first commit
This commit is contained in:
70
extension/opencart/catalog/controller/captcha/basic.php
Normal file
70
extension/opencart/catalog/controller/captcha/basic.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Captcha;
|
||||
/**
|
||||
* Class Basic
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Basic extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('extension/opencart/captcha/basic');
|
||||
|
||||
$data['route'] = (string)$this->request->get['route'];
|
||||
|
||||
$this->session->data['captcha'] = substr(oc_token(100), rand(0, 94), 6);
|
||||
|
||||
return $this->load->view('extension/opencart/captcha/basic', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function validate(): string {
|
||||
$this->load->language('extension/opencart/captcha/basic');
|
||||
|
||||
if (!isset($this->session->data['captcha']) || !isset($this->request->post['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
|
||||
return $this->language->get('error_captcha');
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function captcha(): void {
|
||||
$image = imagecreatetruecolor(150, 35);
|
||||
|
||||
$width = imagesx($image);
|
||||
$height = imagesy($image);
|
||||
|
||||
$black = imagecolorallocate($image, 0, 0, 0);
|
||||
$white = imagecolorallocate($image, 255, 255, 255);
|
||||
$red = imagecolorallocatealpha($image, 255, 0, 0, 75);
|
||||
$green = imagecolorallocatealpha($image, 0, 255, 0, 75);
|
||||
$blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
|
||||
|
||||
imagefilledrectangle($image, 0, 0, $width, $height, $white);
|
||||
imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
|
||||
imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
|
||||
imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
|
||||
imagefilledrectangle($image, 0, 0, $width, 0, $black);
|
||||
imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
|
||||
imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
|
||||
imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
|
||||
|
||||
imagestring($image, 10, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black);
|
||||
|
||||
header('Content-type: image/jpeg');
|
||||
header('Cache-Control: no-cache');
|
||||
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
|
||||
|
||||
imagejpeg($image);
|
||||
|
||||
imagedestroy($image);
|
||||
exit();
|
||||
}
|
||||
}
|
67
extension/opencart/catalog/controller/currency/ecb.php
Normal file
67
extension/opencart/catalog/controller/currency/ecb.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Currency;
|
||||
/**
|
||||
* Class ECB
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class ECB extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $default
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function currency(string $default = ''): void {
|
||||
if ($this->config->get('currency_ecb_status')) {
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($response) {
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->loadXml($response);
|
||||
|
||||
$cube = $dom->getElementsByTagName('Cube')->item(0);
|
||||
|
||||
$currencies = [];
|
||||
|
||||
$currencies['EUR'] = 1.0000;
|
||||
|
||||
foreach ($cube->getElementsByTagName('Cube') as $currency) {
|
||||
if ($currency->getAttribute('currency')) {
|
||||
$currencies[$currency->getAttribute('currency')] = $currency->getAttribute('rate');
|
||||
}
|
||||
}
|
||||
|
||||
if ($currencies) {
|
||||
$this->load->model('localisation/currency');
|
||||
|
||||
$results = $this->model_localisation_currency->getCurrencies();
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (isset($currencies[$result['code']])) {
|
||||
$from = $currencies['EUR'];
|
||||
|
||||
$to = $currencies[$result['code']];
|
||||
|
||||
$this->model_localisation_currency->editValueByCode($result['code'], 1 / ($currencies[$default] * ($from / $to)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->model_localisation_currency->editValueByCode($default, '1.00000');
|
||||
|
||||
$this->cache->delete('currency');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
61
extension/opencart/catalog/controller/currency/fixer.php
Normal file
61
extension/opencart/catalog/controller/currency/fixer.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Currency;
|
||||
/**
|
||||
* Class Fixer
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Fixer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $default
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function currency(string $default = ''): void {
|
||||
if ($this->config->get('currency_fixer_status')) {
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, 'http://data.fixer.io/api/latest?access_key=' . $this->config->get('currency_fixer_api'));
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
$response_info = json_decode($response, true);
|
||||
|
||||
if (is_array($response_info) && isset($response_info['rates'])) {
|
||||
// Compile all the rates into an array
|
||||
$currencies = [];
|
||||
|
||||
$currencies['EUR'] = 1.0000;
|
||||
|
||||
foreach ($response_info['rates'] as $key => $value) {
|
||||
$currencies[$key] = $value;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/currency');
|
||||
|
||||
$results = $this->model_localisation_currency->getCurrencies();
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (isset($currencies[$result['code']])) {
|
||||
$from = $currencies['EUR'];
|
||||
|
||||
$to = $currencies[$result['code']];
|
||||
|
||||
$this->model_localisation_currency->editValueByCode($result['code'], 1 / ($currencies[$default] * ($from / $to)));
|
||||
}
|
||||
}
|
||||
|
||||
$this->model_localisation_currency->editValueByCode($default, 1);
|
||||
|
||||
$this->cache->delete('currency');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
extension/opencart/catalog/controller/module/account.php
Normal file
35
extension/opencart/catalog/controller/module/account.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Account extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('extension/opencart/module/account');
|
||||
|
||||
$data['logged'] = $this->customer->isLogged();
|
||||
$data['register'] = $this->url->link('account/register', 'language=' . $this->config->get('config_language'));
|
||||
$data['login'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'));
|
||||
$data['logout'] = $this->url->link('account/logout', 'language=' . $this->config->get('config_language'));
|
||||
$data['forgotten'] = $this->url->link('account/forgotten', 'language=' . $this->config->get('config_language'));
|
||||
$data['account'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['edit'] = $this->url->link('account/edit', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['password'] = $this->url->link('account/password', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['address'] = $this->url->link('account/address', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['wishlist'] = $this->url->link('account/wishlist', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['order'] = $this->url->link('account/order', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['download'] = $this->url->link('account/download', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['reward'] = $this->url->link('account/reward', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['return'] = $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['transaction'] = $this->url->link('account/transaction', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['newsletter'] = $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
$data['subscription'] = $this->url->link('account/subscription', 'language=' . $this->config->get('config_language') . (isset($this->session->data['customer_token']) ? '&customer_token=' . $this->session->data['customer_token'] : ''));
|
||||
|
||||
return $this->load->view('extension/opencart/module/account', $data);
|
||||
}
|
||||
}
|
50
extension/opencart/catalog/controller/module/banner.php
Normal file
50
extension/opencart/catalog/controller/module/banner.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Banner
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Banner extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $setting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $setting): string {
|
||||
static $module = 0;
|
||||
|
||||
$this->load->model('design/banner');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['banners'] = [];
|
||||
|
||||
$results = $this->model_design_banner->getBanner($setting['banner_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['banners'][] = [
|
||||
'title' => $result['title'],
|
||||
'link' => $result['link'],
|
||||
'image' => $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $setting['width'], $setting['height'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['banners']) {
|
||||
$data['module'] = $module++;
|
||||
|
||||
$data['effect'] = $setting['effect'];
|
||||
$data['controls'] = $setting['controls'];
|
||||
$data['indicators'] = $setting['indicators'];
|
||||
$data['items'] = $setting['items'];
|
||||
$data['interval'] = $setting['interval'];
|
||||
$data['width'] = $setting['width'];
|
||||
$data['height'] = $setting['height'];
|
||||
|
||||
return $this->load->view('extension/opencart/module/banner', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
73
extension/opencart/catalog/controller/module/bestseller.php
Normal file
73
extension/opencart/catalog/controller/module/bestseller.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class BestSeller
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class BestSeller extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $setting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $setting): string {
|
||||
$this->load->language('extension/opencart/module/bestseller');
|
||||
|
||||
$data['axis'] = $setting['axis'];
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$this->load->model('extension/opencart/module/bestseller');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$results = $this->model_extension_opencart_module_bestseller->getBestSellers($setting['limit']);
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['image']) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$price = false;
|
||||
}
|
||||
|
||||
if ((float)$result['special']) {
|
||||
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
||||
'rating' => $result['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'])
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/module/bestseller', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
76
extension/opencart/catalog/controller/module/category.php
Normal file
76
extension/opencart/catalog/controller/module/category.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Category
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Category extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('extension/opencart/module/category');
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$parts = explode('_', (string)$this->request->get['path']);
|
||||
} else {
|
||||
$parts = [];
|
||||
}
|
||||
|
||||
if (isset($parts[0])) {
|
||||
$data['category_id'] = $parts[0];
|
||||
} else {
|
||||
$data['category_id'] = 0;
|
||||
}
|
||||
|
||||
if (isset($parts[1])) {
|
||||
$data['child_id'] = $parts[1];
|
||||
} else {
|
||||
$data['child_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$data['categories'] = [];
|
||||
|
||||
$categories = $this->model_catalog_category->getCategories(0);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$children_data = [];
|
||||
|
||||
if ($category['category_id'] == $data['category_id']) {
|
||||
$children = $this->model_catalog_category->getCategories($category['category_id']);
|
||||
|
||||
foreach ($children as $child) {
|
||||
$filter_data = [
|
||||
'filter_category_id' => $child['category_id'],
|
||||
'filter_sub_category' => true
|
||||
];
|
||||
|
||||
$children_data[] = [
|
||||
'category_id' => $child['category_id'],
|
||||
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category['category_id'] . '_' . $child['category_id'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$filter_data = [
|
||||
'filter_category_id' => $category['category_id'],
|
||||
'filter_sub_category' => true
|
||||
];
|
||||
|
||||
$data['categories'][] = [
|
||||
'category_id' => $category['category_id'],
|
||||
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
|
||||
'children' => $children_data,
|
||||
'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category['category_id'])
|
||||
];
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/module/category', $data);
|
||||
}
|
||||
}
|
83
extension/opencart/catalog/controller/module/featured.php
Normal file
83
extension/opencart/catalog/controller/module/featured.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Featured
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Featured extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $setting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $setting): string {
|
||||
$this->load->language('extension/opencart/module/featured');
|
||||
|
||||
$data['axis'] = $setting['axis'];
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (!empty($setting['product'])) {
|
||||
$products = [];
|
||||
|
||||
foreach ($setting['product'] as $product_id) {
|
||||
$product_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if ($product_info) {
|
||||
$products[] = $product_info;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($products as $product) {
|
||||
if ($product['image']) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($product['image'], ENT_QUOTES, 'UTF-8'), $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$price = false;
|
||||
}
|
||||
|
||||
if ((float)$product['special']) {
|
||||
$special = $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$product['special'] ? $product['special'] : $product['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $product['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $product['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $product['minimum'] > 0 ? $product['minimum'] : 1,
|
||||
'rating' => (int)$product['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $product['product_id'])
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['products']) {
|
||||
return $this->load->view('extension/opencart/module/featured', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
85
extension/opencart/catalog/controller/module/filter.php
Normal file
85
extension/opencart/catalog/controller/module/filter.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Filter
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Filter extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if (isset($this->request->get['path'])) {
|
||||
$parts = explode('_', (string)$this->request->get['path']);
|
||||
} else {
|
||||
$parts = [];
|
||||
}
|
||||
|
||||
$category_id = end($parts);
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$category_info = $this->model_catalog_category->getCategory($category_id);
|
||||
|
||||
if ($category_info) {
|
||||
$this->load->language('extension/opencart/module/filter');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['limit'])) {
|
||||
$url .= '&limit=' . $this->request->get['limit'];
|
||||
}
|
||||
|
||||
$data['action'] = str_replace('&', '&', $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . $url));
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$data['filter_category'] = explode(',', $this->request->get['filter']);
|
||||
} else {
|
||||
$data['filter_category'] = [];
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$data['filter_groups'] = [];
|
||||
|
||||
$filter_groups = $this->model_catalog_category->getFilters($category_id);
|
||||
|
||||
if ($filter_groups) {
|
||||
foreach ($filter_groups as $filter_group) {
|
||||
$children_data = [];
|
||||
|
||||
foreach ($filter_group['filter'] as $filter) {
|
||||
$filter_data = [
|
||||
'filter_category_id' => $category_id,
|
||||
'filter_filter' => $filter['filter_id']
|
||||
];
|
||||
|
||||
$children_data[] = [
|
||||
'filter_id' => $filter['filter_id'],
|
||||
'name' => $filter['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : '')
|
||||
];
|
||||
}
|
||||
|
||||
$data['filter_groups'][] = [
|
||||
'filter_group_id' => $filter_group['filter_group_id'],
|
||||
'name' => $filter_group['name'],
|
||||
'filter' => $children_data
|
||||
];
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/module/filter', $data);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
25
extension/opencart/catalog/controller/module/html.php
Normal file
25
extension/opencart/catalog/controller/module/html.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class HTML
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class HTML extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $setting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $setting): string {
|
||||
if (isset($setting['module_description'][$this->config->get('config_language_id')])) {
|
||||
$data['heading_title'] = html_entity_decode($setting['module_description'][$this->config->get('config_language_id')]['title'], ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$data['html'] = html_entity_decode($setting['module_description'][$this->config->get('config_language_id')]['description'], ENT_QUOTES, 'UTF-8');
|
||||
|
||||
return $this->load->view('extension/opencart/module/html', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
31
extension/opencart/catalog/controller/module/information.php
Normal file
31
extension/opencart/catalog/controller/module/information.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Information
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Information extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('extension/opencart/module/information');
|
||||
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
$data['informations'] = [];
|
||||
|
||||
foreach ($this->model_catalog_information->getInformations() as $result) {
|
||||
$data['informations'][] = [
|
||||
'title' => $result['title'],
|
||||
'href' => $this->url->link('information/information', 'language=' . $this->config->get('config_language') . '&information_id=' . $result['information_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$data['contact'] = $this->url->link('information/contact', 'language=' . $this->config->get('config_language'));
|
||||
$data['sitemap'] = $this->url->link('information/sitemap', 'language=' . $this->config->get('config_language'));
|
||||
|
||||
return $this->load->view('extension/opencart/module/information', $data);
|
||||
}
|
||||
}
|
73
extension/opencart/catalog/controller/module/latest.php
Normal file
73
extension/opencart/catalog/controller/module/latest.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Latest
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Latest extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $setting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $setting): string {
|
||||
$this->load->language('extension/opencart/module/latest');
|
||||
|
||||
$data['axis'] = $setting['axis'];
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$this->load->model('extension/opencart/module/latest');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$results = $this->model_extension_opencart_module_latest->getLatest($setting['limit']);
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['image']) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$price = false;
|
||||
}
|
||||
|
||||
if ((float)$result['special']) {
|
||||
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
||||
'rating' => $result['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'])
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/module/latest', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
80
extension/opencart/catalog/controller/module/special.php
Normal file
80
extension/opencart/catalog/controller/module/special.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Special
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Special extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $setting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $setting): string {
|
||||
$this->load->language('extension/opencart/module/special');
|
||||
|
||||
$data['axis'] = $setting['axis'];
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => 'pd.name',
|
||||
'order' => 'ASC',
|
||||
'start' => 0,
|
||||
'limit' => $setting['limit']
|
||||
];
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$results = $this->model_catalog_product->getSpecials($filter_data);
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['image']) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
|
||||
}
|
||||
|
||||
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
|
||||
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$price = false;
|
||||
}
|
||||
|
||||
if ((float)$result['special']) {
|
||||
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$special = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
$product_data = [
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => oc_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('config_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
|
||||
'rating' => $result['rating'],
|
||||
'href' => $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'])
|
||||
];
|
||||
|
||||
$data['products'][] = $this->load->controller('product/thumb', $product_data);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/module/special', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
49
extension/opencart/catalog/controller/module/store.php
Normal file
49
extension/opencart/catalog/controller/module/store.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
|
||||
/**
|
||||
* Class Store
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Store extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$status = true;
|
||||
|
||||
if ($this->config->get('module_store_admin')) {
|
||||
$this->user = new \Opencart\System\Library\Cart\User($this->registry);
|
||||
|
||||
$status = $this->user->isLogged();
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$this->load->language('extension/opencart/module/store');
|
||||
|
||||
$data['store_id'] = $this->config->get('config_store_id');
|
||||
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default'),
|
||||
'url' => HTTP_SERVER . 'index.php?route=common/home&session_id=' . $this->session->getId()
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$results = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['stores'][] = [
|
||||
'store_id' => $result['store_id'],
|
||||
'name' => $result['name'],
|
||||
'url' => $result['url'] . 'index.php?route=common/home&session_id=' . $this->session->getId()
|
||||
];
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/module/store', $data);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Payment;
|
||||
/**
|
||||
* Class BankTransfer
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class BankTransfer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('extension/opencart/payment/bank_transfer');
|
||||
|
||||
$data['bank'] = nl2br($this->config->get('payment_bank_transfer_bank_' . $this->config->get('config_language_id')));
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('extension/opencart/payment/bank_transfer', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(): void {
|
||||
$this->load->language('extension/opencart/payment/bank_transfer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!isset($this->session->data['order_id'])) {
|
||||
$json['error'] = $this->language->get('error_order');
|
||||
}
|
||||
|
||||
if (!isset($this->session->data['payment_method']) || $this->session->data['payment_method']['code'] != 'bank_transfer.bank_transfer') {
|
||||
$json['error'] = $this->language->get('error_payment_method');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$comment = $this->language->get('text_instruction') . "\n\n";
|
||||
$comment .= $this->config->get('payment_bank_transfer_bank_' . $this->config->get('config_language_id')) . "\n\n";
|
||||
$comment .= $this->language->get('text_payment');
|
||||
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$this->model_checkout_order->addHistory($this->session->data['order_id'], $this->config->get('payment_bank_transfer_order_status_id'), $comment, true);
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/success', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
56
extension/opencart/catalog/controller/payment/cheque.php
Normal file
56
extension/opencart/catalog/controller/payment/cheque.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Payment;
|
||||
/**
|
||||
* Class Cheque
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Cheque extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('extension/opencart/payment/cheque');
|
||||
|
||||
$data['payable'] = $this->config->get('payment_cheque_payable');
|
||||
$data['address'] = nl2br($this->config->get('config_address'));
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('extension/opencart/payment/cheque', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(): void {
|
||||
$this->load->language('extension/opencart/payment/cheque');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!isset($this->session->data['order_id'])) {
|
||||
$json['error'] = $this->language->get('error_order');
|
||||
}
|
||||
|
||||
if (!isset($this->session->data['payment_method']) || $this->session->data['payment_method']['code'] != 'cheque.cheque') {
|
||||
$json['error'] = $this->language->get('error_payment_method');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$comment = $this->language->get('text_payable') . "\n";
|
||||
$comment .= $this->config->get('payment_cheque_payable') . "\n\n";
|
||||
$comment .= $this->language->get('text_address') . "\n";
|
||||
$comment .= $this->config->get('config_address') . "\n\n";
|
||||
$comment .= $this->language->get('text_payment') . "\n";
|
||||
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$this->model_checkout_order->addHistory($this->session->data['order_id'], $this->config->get('payment_cheque_order_status_id'), $comment, true);
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/success', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
47
extension/opencart/catalog/controller/payment/cod.php
Normal file
47
extension/opencart/catalog/controller/payment/cod.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Payment;
|
||||
/**
|
||||
* Class Cod
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Cod extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('extension/opencart/payment/cod');
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('extension/opencart/payment/cod', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(): void {
|
||||
$this->load->language('extension/opencart/payment/cod');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!isset($this->session->data['order_id'])) {
|
||||
$json['error'] = $this->language->get('error_order');
|
||||
}
|
||||
|
||||
if (!isset($this->session->data['payment_method']) || $this->session->data['payment_method']['code'] != 'cod.cod') {
|
||||
$json['error'] = $this->language->get('error_payment_method');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$this->model_checkout_order->addHistory($this->session->data['order_id'], $this->config->get('payment_cod_order_status_id'));
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/success', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Payment;
|
||||
/**
|
||||
* Class FreeCheckout
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class FreeCheckout extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('extension/opencart/payment/free_checkout');
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('extension/opencart/payment/free_checkout', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(): void {
|
||||
$this->load->language('extension/opencart/payment/free_checkout');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!isset($this->session->data['order_id'])) {
|
||||
$json['error'] = $this->language->get('error_order');
|
||||
}
|
||||
|
||||
if (!isset($this->session->data['payment_method']) || $this->session->data['payment_method']['code'] != 'free_checkout.free_checkout') {
|
||||
$json['error'] = $this->language->get('error_payment_method');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$this->model_checkout_order->addHistory($this->session->data['order_id'], $this->config->get('payment_free_checkout_order_status_id'));
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/success', 'language=' . $this->config->get('config_language'), true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
79
extension/opencart/catalog/controller/total/coupon.php
Normal file
79
extension/opencart/catalog/controller/total/coupon.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Coupon
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Coupon extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if ($this->config->get('total_coupon_status')) {
|
||||
$this->load->language('extension/opencart/total/coupon');
|
||||
|
||||
$data['save'] = $this->url->link('extension/opencart/total/coupon.save', 'language=' . $this->config->get('config_language'), true);
|
||||
$data['list'] = $this->url->link('checkout/cart.list', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
if (isset($this->session->data['coupon'])) {
|
||||
$data['coupon'] = $this->session->data['coupon'];
|
||||
} else {
|
||||
$data['coupon'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/total/coupon', $data);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('extension/opencart/total/coupon');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['coupon'])) {
|
||||
$coupon = $this->request->post['coupon'];
|
||||
} else {
|
||||
$coupon = '';
|
||||
}
|
||||
|
||||
if (!$this->config->get('total_coupon_status')) {
|
||||
$json['error'] = $this->language->get('error_status');
|
||||
}
|
||||
|
||||
if ($coupon) {
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
$coupon_info = $this->model_marketing_coupon->getCoupon($coupon);
|
||||
|
||||
if (!$coupon_info) {
|
||||
$json['error'] = $this->language->get('error_coupon');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ($coupon) {
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$this->session->data['coupon'] = $coupon;
|
||||
} else {
|
||||
$json['success'] = $this->language->get('text_remove');
|
||||
|
||||
unset($this->session->data['coupon']);
|
||||
}
|
||||
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
103
extension/opencart/catalog/controller/total/reward.php
Normal file
103
extension/opencart/catalog/controller/total/reward.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Reward
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Reward extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if ($this->config->get('total_reward_status')) {
|
||||
$available = $this->customer->getRewardPoints();
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($available && $points_total) {
|
||||
$this->load->language('extension/opencart/total/reward');
|
||||
|
||||
$data['heading_title'] = sprintf($this->language->get('heading_title'), $available);
|
||||
|
||||
$data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total);
|
||||
|
||||
$data['save'] = $this->url->link('extension/opencart/total/reward.save', 'language=' . $this->config->get('config_language'), true);
|
||||
$data['list'] = $this->url->link('checkout/cart.list', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
if (isset($this->session->data['reward'])) {
|
||||
$data['reward'] = $this->session->data['reward'];
|
||||
} else {
|
||||
$data['reward'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/total/reward', $data);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('extension/opencart/total/reward');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['reward'])) {
|
||||
$reward = abs((int)$this->request->post['reward']);
|
||||
} else {
|
||||
$reward = 0;
|
||||
}
|
||||
|
||||
$available = $this->customer->getRewardPoints();
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->config->get('total_reward_status')) {
|
||||
$json['error'] = $this->language->get('error_reward');
|
||||
}
|
||||
|
||||
if ($reward > $available) {
|
||||
$json['error'] = sprintf($this->language->get('error_points'), $reward);
|
||||
}
|
||||
|
||||
if ($reward > $points_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_maximum'), $points_total);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ($reward) {
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$this->session->data['reward'] = $reward;
|
||||
} else {
|
||||
$json['success'] = $this->language->get('text_remove');
|
||||
|
||||
unset($this->session->data['reward']);
|
||||
}
|
||||
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
172
extension/opencart/catalog/controller/total/shipping.php
Normal file
172
extension/opencart/catalog/controller/total/shipping.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Shipping
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Shipping extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if ($this->config->get('total_shipping_status') && $this->config->get('total_shipping_estimator') && $this->cart->hasShipping()) {
|
||||
$this->load->language('extension/opencart/total/shipping');
|
||||
|
||||
if (isset($this->session->data['shipping_address'])) {
|
||||
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
|
||||
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
|
||||
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
|
||||
} else {
|
||||
$data['postcode'] = '';
|
||||
$data['country_id'] = (int)$this->config->get('config_country_id');
|
||||
$data['zone_id'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['shipping_method'])) {
|
||||
$data['code'] = $this->session->data['shipping_method']['code'];
|
||||
} else {
|
||||
$data['code'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
$data['language'] = $this->config->get('config_language');
|
||||
|
||||
return $this->load->view('extension/opencart/total/shipping', $data);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function quote(): void {
|
||||
$this->load->language('extension/opencart/total/shipping');
|
||||
|
||||
$json = [];
|
||||
|
||||
$keys = [
|
||||
'postcode',
|
||||
'country_id',
|
||||
'zone_id'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->cart->hasProducts()) {
|
||||
$json['error']['warning'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
if (!$this->cart->hasShipping()) {
|
||||
$json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_info = $this->model_localisation_country->getCountry((int)$this->request->post['country_id']);
|
||||
|
||||
if ($country_info && $country_info['postcode_required'] && (oc_strlen($this->request->post['postcode']) < 2 || oc_strlen($this->request->post['postcode']) > 10)) {
|
||||
$json['error']['postcode'] = $this->language->get('error_postcode');
|
||||
}
|
||||
|
||||
if ($this->request->post['country_id'] == '') {
|
||||
$json['error']['country'] = $this->language->get('error_country');
|
||||
}
|
||||
|
||||
if ($this->request->post['zone_id'] == '') {
|
||||
$json['error']['zone'] = $this->language->get('error_zone');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ($country_info) {
|
||||
$country = $country_info['name'];
|
||||
$iso_code_2 = $country_info['iso_code_2'];
|
||||
$iso_code_3 = $country_info['iso_code_3'];
|
||||
$address_format = $country_info['address_format'];
|
||||
} else {
|
||||
$country = '';
|
||||
$iso_code_2 = '';
|
||||
$iso_code_3 = '';
|
||||
$address_format = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone_info = $this->model_localisation_zone->getZone($this->request->post['zone_id']);
|
||||
|
||||
if ($zone_info) {
|
||||
$zone = $zone_info['name'];
|
||||
$zone_code = $zone_info['code'];
|
||||
} else {
|
||||
$zone = '';
|
||||
$zone_code = '';
|
||||
}
|
||||
|
||||
$this->session->data['shipping_address'] = [
|
||||
'postcode' => $this->request->post['postcode'],
|
||||
'zone_id' => $this->request->post['zone_id'],
|
||||
'zone' => $zone,
|
||||
'zone_code' => $zone_code,
|
||||
'country_id' => $this->request->post['country_id'],
|
||||
'country' => $country,
|
||||
'iso_code_2' => $iso_code_2,
|
||||
'iso_code_3' => $iso_code_3
|
||||
];
|
||||
|
||||
$this->tax->setShippingAddress($this->request->post['country_id'], $this->request->post['zone_id']);
|
||||
|
||||
// Shipping Methods
|
||||
$this->load->model('checkout/shipping_method');
|
||||
|
||||
$shipping_methods = $this->model_checkout_shipping_method->getMethods($this->session->data['shipping_address']);
|
||||
|
||||
if ($shipping_methods) {
|
||||
$json['shipping_methods'] = $this->session->data['shipping_methods'] = $shipping_methods;
|
||||
} else {
|
||||
$json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact', 'language=' . $this->config->get('config_language')));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('extension/opencart/total/shipping');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!empty($this->request->post['shipping_method'])) {
|
||||
$shipping = explode('.', $this->request->post['shipping_method']);
|
||||
|
||||
if (!isset($shipping[0]) || !isset($shipping[1]) || !isset($this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {
|
||||
$json['error'] = $this->language->get('error_shipping');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_shipping');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
79
extension/opencart/catalog/controller/total/voucher.php
Normal file
79
extension/opencart/catalog/controller/total/voucher.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Extension\Opencart\Total;
|
||||
/**
|
||||
* Class Voucher
|
||||
*
|
||||
* @package
|
||||
*/
|
||||
class Voucher extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if ($this->config->get('total_voucher_status')) {
|
||||
$this->load->language('extension/opencart/total/voucher');
|
||||
|
||||
$data['save'] = $this->url->link('extension/opencart/total/voucher.save', 'language=' . $this->config->get('config_language'), true);
|
||||
$data['list'] = $this->url->link('checkout/cart.list', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
if (isset($this->session->data['voucher'])) {
|
||||
$data['voucher'] = $this->session->data['voucher'];
|
||||
} else {
|
||||
$data['voucher'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/opencart/total/voucher', $data);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('extension/opencart/total/voucher');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['voucher'])) {
|
||||
$voucher = (string)$this->request->post['voucher'];
|
||||
} else {
|
||||
$voucher = '';
|
||||
}
|
||||
|
||||
if (!$this->config->get('total_voucher_status')) {
|
||||
$json['error'] = $this->language->get('error_status');
|
||||
}
|
||||
|
||||
if ($voucher) {
|
||||
$this->load->model('checkout/voucher');
|
||||
|
||||
$voucher_info = $this->model_checkout_voucher->getVoucher($voucher);
|
||||
|
||||
if (!$voucher_info) {
|
||||
$json['error'] = $this->language->get('error_voucher');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ($voucher) {
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$this->session->data['voucher'] = $voucher;
|
||||
} else {
|
||||
$json['success'] = $this->language->get('text_remove');
|
||||
|
||||
unset($this->session->data['voucher']);
|
||||
}
|
||||
|
||||
unset($this->session->data['shipping_method']);
|
||||
unset($this->session->data['shipping_methods']);
|
||||
unset($this->session->data['payment_method']);
|
||||
unset($this->session->data['payment_methods']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user