first commit
This commit is contained in:
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
|
||||
use \googleshopping\traits\StoreLoader;
|
||||
use \googleshopping\traits\LibraryLoader;
|
||||
|
||||
class ControllerExtensionAdvertiseGoogle extends Controller {
|
||||
use StoreLoader;
|
||||
use LibraryLoader;
|
||||
|
||||
private $store_id = 0;
|
||||
|
||||
public function __construct($registry) {
|
||||
parent::__construct($registry);
|
||||
|
||||
if (getenv("ADVERTISE_GOOGLE_STORE_ID")) {
|
||||
$this->store_id = (int)getenv("ADVERTISE_GOOGLE_STORE_ID");
|
||||
} else {
|
||||
$this->store_id = (int)$this->config->get('config_store_id');
|
||||
}
|
||||
|
||||
$this->loadStore($this->store_id);
|
||||
}
|
||||
|
||||
public function google_global_site_tag(&$route, &$data, &$output) {
|
||||
// In case the extension is disabled, do nothing
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is no tracker, do nothing
|
||||
if (!$this->setting->has('advertise_google_conversion_tracker')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tracker = $this->setting->get('advertise_google_conversion_tracker');
|
||||
|
||||
// Insert the tags before the closing <head> tag
|
||||
$output = str_replace('</head>', $tracker['google_global_site_tag'] . '</head>', $output);
|
||||
}
|
||||
|
||||
public function before_checkout_success(&$route, &$data) {
|
||||
// In case the extension is disabled, do nothing
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is no tracker, do nothing
|
||||
if (!$this->setting->has('advertise_google_conversion_tracker')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// In case there is no order, do nothing
|
||||
if (!isset($this->session->data['order_id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->registry->has('googleshopping')) {
|
||||
$this->loadLibrary($this->store_id);
|
||||
}
|
||||
|
||||
$this->load->model('checkout/order');
|
||||
$this->load->model('extension/advertise/google');
|
||||
|
||||
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
|
||||
|
||||
$tracker = $this->setting->get('advertise_google_conversion_tracker');
|
||||
$currency = $order_info['currency_code'];
|
||||
|
||||
$total = $this->googleshopping->convertAndFormat($order_info['total'], $currency);
|
||||
|
||||
$search = array(
|
||||
'{VALUE}',
|
||||
'{CURRENCY}'
|
||||
);
|
||||
|
||||
$replace = array(
|
||||
$total,
|
||||
$currency
|
||||
);
|
||||
|
||||
$snippet = str_replace($search, $replace, $tracker['google_event_snippet']);
|
||||
|
||||
// Store the snippet to display it in the order success view
|
||||
$tax = 0;
|
||||
$shipping = 0;
|
||||
$coupon = $this->model_extension_advertise_google->getCoupon($order_info['order_id']);
|
||||
|
||||
foreach ($this->model_checkout_order->getOrderTotals($order_info['order_id']) as $order_total) {
|
||||
if ($order_total['code'] == 'shipping') {
|
||||
$shipping += $this->googleshopping->convertAndFormat($order_total['value'], $currency);
|
||||
}
|
||||
|
||||
if ($order_total['code'] == 'tax') {
|
||||
$tax += $this->googleshopping->convertAndFormat($order_total['value'], $currency);
|
||||
}
|
||||
}
|
||||
|
||||
$order_products = $this->model_checkout_order->getOrderProducts($order_info['order_id']);
|
||||
|
||||
foreach ($order_products as &$order_product) {
|
||||
$order_product['option'] = $this->model_checkout_order->getOrderOptions($order_info['order_id'], $order_product['order_product_id']);
|
||||
}
|
||||
|
||||
$purchase_data = array(
|
||||
'transaction_id' => $order_info['order_id'],
|
||||
'value' => $total,
|
||||
'currency' => $currency,
|
||||
'tax' => $tax,
|
||||
'shipping' => $shipping,
|
||||
'items' => $this->model_extension_advertise_google->getRemarketingItems($order_products, $order_info['store_id']),
|
||||
'ecomm_prodid' => $this->model_extension_advertise_google->getRemarketingProductIds($order_products, $order_info['store_id'])
|
||||
);
|
||||
|
||||
if ($coupon !== null) {
|
||||
$purchase_data['coupon'] = $coupon;
|
||||
}
|
||||
|
||||
$this->googleshopping->setEventSnippet($snippet);
|
||||
$this->googleshopping->setPurchaseData($purchase_data);
|
||||
}
|
||||
|
||||
public function google_dynamic_remarketing_purchase(&$route, &$data, &$output) {
|
||||
// In case the extension is disabled, do nothing
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the library has not been loaded, or if there is no snippet, do nothing
|
||||
if (!$this->registry->has('googleshopping') || $this->googleshopping->getEventSnippet() === null || $this->googleshopping->getPurchaseData() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
|
||||
|
||||
$purchase_data = $this->googleshopping->getPurchaseData();
|
||||
|
||||
$data['transaction_id'] = $purchase_data['transaction_id'];
|
||||
$data['value'] = $purchase_data['value'];
|
||||
$data['currency'] = $purchase_data['currency'];
|
||||
$data['tax'] = $purchase_data['tax'];
|
||||
$data['shipping'] = $purchase_data['shipping'];
|
||||
$data['items'] = json_encode($purchase_data['items']);
|
||||
$data['ecomm_prodid'] = json_encode($purchase_data['ecomm_prodid']);
|
||||
$data['ecomm_totalvalue'] = $purchase_data['value'];
|
||||
|
||||
$purchase_snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_purchase', $data);
|
||||
|
||||
// Insert the snippet after the output
|
||||
$output = str_replace('</body>', $this->googleshopping->getEventSnippet() . $purchase_snippet . '</body>', $output);
|
||||
}
|
||||
|
||||
public function google_dynamic_remarketing_home(&$route, &$data, &$output) {
|
||||
// In case the extension is disabled, do nothing
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are not on the home page, do nothing
|
||||
if (isset($this->request->get['route']) && $this->request->get['route'] != $this->config->get('action_default')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->registry->has('googleshopping')) {
|
||||
$this->loadLibrary($this->store_id);
|
||||
}
|
||||
|
||||
if (null === $this->googleshopping->getEventSnippetSendTo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
|
||||
|
||||
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_home', $data);
|
||||
|
||||
// Insert the snippet after the output
|
||||
$output = str_replace('</body>', $snippet . '</body>', $output);
|
||||
}
|
||||
|
||||
public function google_dynamic_remarketing_searchresults(&$route, &$data, &$output) {
|
||||
// In case the extension is disabled, do nothing
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are not on the search page, do nothing
|
||||
if (!isset($this->request->get['route']) || $this->request->get['route'] != 'product/search' || !isset($this->request->get['search'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->registry->has('googleshopping')) {
|
||||
$this->loadLibrary($this->store_id);
|
||||
}
|
||||
|
||||
if (null === $this->googleshopping->getEventSnippetSendTo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
|
||||
$data['search_term'] = $this->request->get['search'];
|
||||
|
||||
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_searchresults', $data);
|
||||
|
||||
// Insert the snippet after the output
|
||||
$output = str_replace('</body>', $snippet . '</body>', $output);
|
||||
}
|
||||
|
||||
public function google_dynamic_remarketing_category(&$route, &$data, &$output) {
|
||||
// In case the extension is disabled, do nothing
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are not on the search page, do nothing
|
||||
if (!isset($this->request->get['route']) || $this->request->get['route'] != 'product/category') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->registry->has('googleshopping')) {
|
||||
$this->loadLibrary($this->store_id);
|
||||
}
|
||||
|
||||
if (null === $this->googleshopping->getEventSnippetSendTo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$parts = explode('_', $this->request->get['path']);
|
||||
$category_id = (int)end($parts);
|
||||
} else if (isset($this->request->get['category_id'])) {
|
||||
$category_id = (int)$this->request->get['category_id'];
|
||||
} else {
|
||||
$category_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('extension/advertise/google');
|
||||
|
||||
$data = array();
|
||||
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
|
||||
$data['description'] = str_replace('"', '\\"', $this->model_extension_advertise_google->getHumanReadableOpenCartCategory($category_id));
|
||||
|
||||
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_category', $data);
|
||||
|
||||
// Insert the snippet after the output
|
||||
$output = str_replace('</body>', $snippet . '</body>', $output);
|
||||
}
|
||||
|
||||
public function google_dynamic_remarketing_product(&$route, &$data, &$output) {
|
||||
// In case the extension is disabled, do nothing
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we do not know the viewed product, do nothing
|
||||
if (!isset($this->request->get['product_id']) || !isset($this->request->get['route']) || $this->request->get['route'] != 'product/product') {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$product_info = $this->model_catalog_product->getProduct((int)$this->request->get['product_id']);
|
||||
|
||||
// If product does not exist, do nothing
|
||||
if (!$product_info) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->registry->has('googleshopping')) {
|
||||
$this->loadLibrary($this->store_id);
|
||||
}
|
||||
|
||||
if (null === $this->googleshopping->getEventSnippetSendTo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->model('extension/advertise/google');
|
||||
|
||||
$category_name = $this->model_extension_advertise_google->getHumanReadableCategory($product_info['product_id'], $this->store_id);
|
||||
|
||||
$option_map = $this->model_extension_advertise_google->getSizeAndColorOptionMap($product_info['product_id'], $this->store_id);
|
||||
|
||||
$data = array();
|
||||
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
|
||||
$data['option_map'] = json_encode($option_map);
|
||||
$data['brand'] = $product_info['manufacturer'];
|
||||
$data['name'] = $product_info['name'];
|
||||
$data['category'] = str_replace('"', '\\"', $category_name);
|
||||
|
||||
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_product', $data);
|
||||
|
||||
// Insert the snippet after the output
|
||||
$output = str_replace('</body>', $snippet . '</body>', $output);
|
||||
}
|
||||
|
||||
public function google_dynamic_remarketing_cart(&$route, &$data, &$output) {
|
||||
// In case the extension is disabled, do nothing
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are not on the cart page, do nothing
|
||||
if (!isset($this->request->get['route']) || $this->request->get['route'] != 'checkout/cart') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->registry->has('googleshopping')) {
|
||||
$this->loadLibrary($this->store_id);
|
||||
}
|
||||
|
||||
if (null === $this->googleshopping->getEventSnippetSendTo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('extension/advertise/google');
|
||||
|
||||
$data = array();
|
||||
$data['send_to'] = $this->googleshopping->getEventSnippetSendTo();
|
||||
$data['ecomm_totalvalue'] = $this->cart->getTotal();
|
||||
$data['ecomm_prodid'] = json_encode($this->model_extension_advertise_google->getRemarketingProductIds($this->cart->getProducts(), $this->store_id));
|
||||
$data['items'] = json_encode($this->model_extension_advertise_google->getRemarketingItems($this->cart->getProducts(), $this->store_id));
|
||||
|
||||
$snippet = $this->load->view('extension/advertise/google_dynamic_remarketing_cart', $data);
|
||||
|
||||
// Insert the snippet after the output
|
||||
$output = str_replace('</body>', $snippet . '</body>', $output);
|
||||
}
|
||||
|
||||
public function cron($cron_id = null, $code = null, $cycle = null, $date_added = null, $date_modified = null) {
|
||||
$this->loadLibrary($this->store_id);
|
||||
|
||||
if (!$this->validateCRON()) {
|
||||
// In case this is not a CRON task
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->language('extension/advertise/google');
|
||||
|
||||
// Reset taxes to use the store address and zone
|
||||
$this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
|
||||
$this->tax->setPaymentAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
|
||||
$this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
|
||||
|
||||
$this->googleshopping->cron();
|
||||
}
|
||||
|
||||
protected function validateCRON() {
|
||||
if (!$this->setting->get('advertise_google_status')) {
|
||||
// In case the extension is disabled, do nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->setting->get('advertise_google_gmc_account_selected')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->setting->get('advertise_google_gmc_shipping_taxes_configured')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (count($this->googleshopping->getTargets($this->store_id)) === 0) {
|
||||
return false;
|
||||
}
|
||||
} catch (\RuntimeException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['cron_token']) && $this->request->get['cron_token'] == $this->config->get('advertise_google_cron_token')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (defined('ADVERTISE_GOOGLE_ROUTE')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class ControllerExtensionAnalyticsGoogle extends Controller {
|
||||
public function index() {
|
||||
return html_entity_decode($this->config->get('analytics_google_code'), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
class ControllerExtensionAnalyticsYandexMetrika extends Controller {
|
||||
public function index() {
|
||||
|
||||
$admin = false;
|
||||
|
||||
$user = false;
|
||||
|
||||
if ($this->config->get('analytics_yandex_metrika_no_admin')) {
|
||||
$this->user = new Cart\User($this->registry);
|
||||
|
||||
$admin = $this->user->isLogged();
|
||||
}
|
||||
|
||||
if ($this->config->get('analytics_yandex_metrika_no_users')) {
|
||||
$user = $this->customer->isLogged();
|
||||
}
|
||||
|
||||
if (!$admin and !$user) {
|
||||
return html_entity_decode($this->config->get('analytics_yandex_metrika_code'), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
class ControllerExtensionCaptchaBasic extends Controller {
|
||||
public function index($error = array()) {
|
||||
$this->load->language('extension/captcha/basic');
|
||||
|
||||
if (isset($error['captcha'])) {
|
||||
$data['error_captcha'] = $error['captcha'];
|
||||
} else {
|
||||
$data['error_captcha'] = '';
|
||||
}
|
||||
|
||||
$data['route'] = $this->request->get['route'];
|
||||
|
||||
return $this->load->view('extension/captcha/basic', $data);
|
||||
}
|
||||
|
||||
public function validate() {
|
||||
$this->load->language('extension/captcha/basic');
|
||||
|
||||
if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
|
||||
return $this->language->get('error_captcha');
|
||||
}
|
||||
}
|
||||
|
||||
public function captcha() {
|
||||
$this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6);
|
||||
|
||||
$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');
|
||||
|
||||
imagejpeg($image);
|
||||
|
||||
imagedestroy($image);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
class ControllerExtensionCaptchaGoogle extends Controller {
|
||||
public function index($error = array()) {
|
||||
$this->load->language('extension/captcha/google');
|
||||
|
||||
if (isset($error['captcha'])) {
|
||||
$data['error_captcha'] = $error['captcha'];
|
||||
} else {
|
||||
$data['error_captcha'] = '';
|
||||
}
|
||||
|
||||
$data['site_key'] = $this->config->get('captcha_google_key');
|
||||
|
||||
$data['route'] = $this->request->get['route'];
|
||||
|
||||
return $this->load->view('extension/captcha/google', $data);
|
||||
}
|
||||
|
||||
public function validate() {
|
||||
if (empty($this->session->data['gcapcha'])) {
|
||||
$this->load->language('extension/captcha/google');
|
||||
|
||||
if (!isset($this->request->post['g-recaptcha-response'])) {
|
||||
return $this->language->get('error_captcha');
|
||||
}
|
||||
|
||||
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('captcha_google_secret')) . '&response=' . $this->request->post['g-recaptcha-response'] . '&remoteip=' . $this->request->server['REMOTE_ADDR']);
|
||||
|
||||
$recaptcha = json_decode($recaptcha, true);
|
||||
|
||||
if ($recaptcha['success']) {
|
||||
$this->session->data['gcapcha'] = true;
|
||||
} else {
|
||||
return $this->language->get('error_captcha');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
class ControllerExtensionFeedGoogleBase extends Controller {
|
||||
public function index() {
|
||||
if ($this->config->get('feed_google_base_status')) {
|
||||
$output = '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
$output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
|
||||
$output .= ' <channel>';
|
||||
$output .= ' <title>' . $this->config->get('config_name') . '</title>';
|
||||
$output .= ' <description>' . $this->config->get('config_meta_description') . '</description>';
|
||||
$output .= ' <link>' . $this->config->get('config_url') . '</link>';
|
||||
|
||||
$this->load->model('extension/feed/google_base');
|
||||
$this->load->model('catalog/category');
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$product_data = array();
|
||||
|
||||
$google_base_categories = $this->model_extension_feed_google_base->getCategories();
|
||||
|
||||
foreach ($google_base_categories as $google_base_category) {
|
||||
$filter_data = array(
|
||||
'filter_category_id' => $google_base_category['category_id'],
|
||||
'filter_filter' => false
|
||||
);
|
||||
|
||||
$products = $this->model_catalog_product->getProducts($filter_data);
|
||||
|
||||
foreach ($products as $product) {
|
||||
if (!in_array($product['product_id'], $product_data) && $product['description']) {
|
||||
|
||||
$product_data[] = $product['product_id'];
|
||||
|
||||
$output .= '<item>';
|
||||
$output .= '<title><![CDATA[' . $product['name'] . ']]></title>';
|
||||
$output .= '<link>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</link>';
|
||||
$output .= '<description><![CDATA[' . strip_tags(html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8')) . ']]></description>';
|
||||
$output .= '<g:brand><![CDATA[' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . ']]></g:brand>';
|
||||
$output .= '<g:condition>new</g:condition>';
|
||||
$output .= '<g:id>' . $product['product_id'] . '</g:id>';
|
||||
|
||||
if ($product['image']) {
|
||||
$output .= ' <g:image_link>' . $this->model_tool_image->resize($product['image'], 500, 500) . '</g:image_link>';
|
||||
} else {
|
||||
$output .= ' <g:image_link></g:image_link>';
|
||||
}
|
||||
|
||||
$output .= ' <g:model_number>' . $product['model'] . '</g:model_number>';
|
||||
|
||||
if ($product['mpn']) {
|
||||
$output .= ' <g:mpn><![CDATA[' . $product['mpn'] . ']]></g:mpn>' ;
|
||||
} else {
|
||||
$output .= ' <g:identifier_exists>false</g:identifier_exists>';
|
||||
}
|
||||
|
||||
if ($product['upc']) {
|
||||
$output .= ' <g:upc>' . $product['upc'] . '</g:upc>';
|
||||
}
|
||||
|
||||
if ($product['ean']) {
|
||||
$output .= ' <g:ean>' . $product['ean'] . '</g:ean>';
|
||||
}
|
||||
|
||||
$currencies = array(
|
||||
'USD',
|
||||
'EUR',
|
||||
'GBP'
|
||||
);
|
||||
|
||||
if (in_array($this->session->data['currency'], $currencies)) {
|
||||
$currency_code = $this->session->data['currency'];
|
||||
$currency_value = $this->currency->getValue($this->session->data['currency']);
|
||||
} else {
|
||||
$currency_code = 'USD';
|
||||
$currency_value = $this->currency->getValue('USD');
|
||||
}
|
||||
|
||||
if ((float)$product['special']) {
|
||||
$output .= ' <g:price>' . $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</g:price>';
|
||||
} else {
|
||||
$output .= ' <g:price>' . $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency_code, $currency_value, false) . '</g:price>';
|
||||
}
|
||||
|
||||
$output .= ' <g:google_product_category>' . $google_base_category['google_base_category_id'] . '</g:google_product_category>';
|
||||
|
||||
$categories = $this->model_catalog_product->getCategories($product['product_id']);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$path = $this->getPath($category['category_id']);
|
||||
|
||||
if ($path) {
|
||||
$string = '';
|
||||
|
||||
foreach (explode('_', $path) as $path_id) {
|
||||
$category_info = $this->model_catalog_category->getCategory($path_id);
|
||||
|
||||
if ($category_info) {
|
||||
if (!$string) {
|
||||
$string = $category_info['name'];
|
||||
} else {
|
||||
$string .= ' > ' . $category_info['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '<g:product_type><![CDATA[' . $string . ']]></g:product_type>';
|
||||
}
|
||||
}
|
||||
|
||||
$output .= ' <g:quantity>' . $product['quantity'] . '</g:quantity>';
|
||||
$output .= ' <g:weight>' . $this->weight->format($product['weight'], $product['weight_class_id']) . '</g:weight>';
|
||||
$output .= ' <g:availability><![CDATA[' . ($product['quantity'] ? 'in stock' : 'out of stock') . ']]></g:availability>';
|
||||
$output .= '</item>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= ' </channel>';
|
||||
$output .= '</rss>';
|
||||
|
||||
$this->response->addHeader('Content-Type: application/rss+xml');
|
||||
$this->response->setOutput($output);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getPath($parent_id, $current_path = '') {
|
||||
$category_info = $this->model_catalog_category->getCategory($parent_id);
|
||||
|
||||
if ($category_info) {
|
||||
if (!$current_path) {
|
||||
$new_path = $category_info['category_id'];
|
||||
} else {
|
||||
$new_path = $category_info['category_id'] . '_' . $current_path;
|
||||
}
|
||||
|
||||
$path = $this->getPath($category_info['parent_id'], $new_path);
|
||||
|
||||
if ($path) {
|
||||
return $path;
|
||||
} else {
|
||||
return $new_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
class ControllerExtensionFeedGoogleSitemap extends Controller {
|
||||
public function index() {
|
||||
if ($this->config->get('feed_google_sitemap_status')) {
|
||||
$output = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$products = $this->model_catalog_product->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
if ($product['image']) {
|
||||
$output .= '<url>';
|
||||
$output .= ' <loc>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</loc>';
|
||||
$output .= ' <changefreq>weekly</changefreq>';
|
||||
$output .= ' <lastmod>' . date('Y-m-d\TH:i:sP', strtotime($product['date_modified'])) . '</lastmod>';
|
||||
$output .= ' <priority>1.0</priority>';
|
||||
$output .= ' <image:image>';
|
||||
$output .= ' <image:loc>' . $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>';
|
||||
$output .= ' <image:caption>' . $product['name'] . '</image:caption>';
|
||||
$output .= ' <image:title>' . $product['name'] . '</image:title>';
|
||||
$output .= ' </image:image>';
|
||||
$output .= '</url>';
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$output .= $this->getCategories(0);
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
$manufacturers = $this->model_catalog_manufacturer->getManufacturers();
|
||||
|
||||
foreach ($manufacturers as $manufacturer) {
|
||||
$output .= '<url>';
|
||||
$output .= ' <loc>' . $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $manufacturer['manufacturer_id']) . '</loc>';
|
||||
$output .= ' <changefreq>weekly</changefreq>';
|
||||
$output .= ' <priority>0.7</priority>';
|
||||
$output .= '</url>';
|
||||
|
||||
$products = $this->model_catalog_product->getProducts(array('filter_manufacturer_id' => $manufacturer['manufacturer_id']));
|
||||
|
||||
foreach ($products as $product) {
|
||||
$output .= '<url>';
|
||||
$output .= ' <loc>' . $this->url->link('product/product', 'manufacturer_id=' . $manufacturer['manufacturer_id'] . '&product_id=' . $product['product_id']) . '</loc>';
|
||||
$output .= ' <changefreq>weekly</changefreq>';
|
||||
$output .= ' <priority>1.0</priority>';
|
||||
$output .= '</url>';
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
$informations = $this->model_catalog_information->getInformations();
|
||||
|
||||
foreach ($informations as $information) {
|
||||
$output .= '<url>';
|
||||
$output .= ' <loc>' . $this->url->link('information/information', 'information_id=' . $information['information_id']) . '</loc>';
|
||||
$output .= ' <changefreq>weekly</changefreq>';
|
||||
$output .= ' <priority>0.5</priority>';
|
||||
$output .= '</url>';
|
||||
}
|
||||
|
||||
$output .= '</urlset>';
|
||||
|
||||
$this->response->addHeader('Content-Type: application/xml');
|
||||
$this->response->setOutput($output);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCategories($parent_id, $current_path = '') {
|
||||
$output = '';
|
||||
|
||||
$results = $this->model_catalog_category->getCategories($parent_id);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (!$current_path) {
|
||||
$new_path = $result['category_id'];
|
||||
} else {
|
||||
$new_path = $current_path . '_' . $result['category_id'];
|
||||
}
|
||||
|
||||
$output .= '<url>';
|
||||
$output .= ' <loc>' . $this->url->link('product/category', 'path=' . $new_path) . '</loc>';
|
||||
$output .= ' <changefreq>weekly</changefreq>';
|
||||
$output .= ' <priority>0.7</priority>';
|
||||
$output .= '</url>';
|
||||
|
||||
$products = $this->model_catalog_product->getProducts(array('filter_category_id' => $result['category_id']));
|
||||
|
||||
foreach ($products as $product) {
|
||||
$output .= '<url>';
|
||||
$output .= ' <loc>' . $this->url->link('product/product', 'path=' . $new_path . '&product_id=' . $product['product_id']) . '</loc>';
|
||||
$output .= ' <changefreq>weekly</changefreq>';
|
||||
$output .= ' <priority>1.0</priority>';
|
||||
$output .= '</url>';
|
||||
}
|
||||
|
||||
$output .= $this->getCategories($result['category_id'], $new_path);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
class ControllerExtensionFeedGoogleSitemapFast extends Controller {
|
||||
protected $categories = array();
|
||||
|
||||
public function index() {
|
||||
if($this->config->get('feed_google_sitemap_fast_status')) {
|
||||
$time_start = microtime(true);
|
||||
|
||||
$output = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
||||
|
||||
$this->load->model('tool/sitemap');
|
||||
|
||||
$products = $this->model_tool_sitemap->getProducts();
|
||||
|
||||
foreach($products as $product) {
|
||||
$output .= '<url>';
|
||||
$output .= '<loc>' . str_replace('&', '&', str_replace('&', '&', $this->url->link('product/product', 'product_id=' . $product['product_id']))) . '</loc>';
|
||||
$output .= '<lastmod>' . $product['date'] . '</lastmod>';
|
||||
$output .= '<changefreq>weekly</changefreq>';
|
||||
$output .= '<priority>1.0</priority>';
|
||||
$output .= '</url>';
|
||||
}
|
||||
|
||||
$this->categories = $this->model_tool_sitemap->getAllCategories();
|
||||
|
||||
$output .= $this->getAllCategories(0);
|
||||
|
||||
$manufacturers = $this->model_tool_sitemap->getManufacturers();
|
||||
|
||||
foreach($manufacturers as $manufacturer) {
|
||||
$output .= '<url>';
|
||||
$output .= '<loc>' . str_replace('&', '&', str_replace('&', '&', $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $manufacturer['manufacturer_id']))) . '</loc>';
|
||||
$output .= '<changefreq>weekly</changefreq>';
|
||||
$output .= '<priority>0.7</priority>';
|
||||
$output .= '</url>';
|
||||
}
|
||||
|
||||
|
||||
$informations = $this->model_tool_sitemap->getInformations();
|
||||
|
||||
foreach($informations as $information) {
|
||||
$output .= '<url>';
|
||||
$output .= '<loc>' . str_replace('&', '&', str_replace('&', '&', $this->url->link('information/information', 'information_id=' . $information['information_id']))) . '</loc>';
|
||||
$output .= '<changefreq>weekly</changefreq>';
|
||||
$output .= '<priority>0.5</priority>';
|
||||
$output .= '</url>';
|
||||
}
|
||||
|
||||
$output .= '</urlset>';
|
||||
|
||||
$this->log->write(sprintf("Fast Sitemap Execution Time: %05.5f", (microtime(true) - $time_start)));
|
||||
|
||||
$this->response->addHeader('Content-Type: application/xml');
|
||||
$this->response->setOutput($output);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getAllCategories($parent_id = 0, $current_path = '') {
|
||||
$output = '';
|
||||
|
||||
if(array_key_exists($parent_id, $this->categories)) {
|
||||
$results = $this->categories[$parent_id];
|
||||
|
||||
foreach($results as $result) {
|
||||
if(!$current_path) {
|
||||
$new_path = $result['category_id'];
|
||||
} else {
|
||||
$new_path = $current_path . '_' . $result['category_id'];
|
||||
}
|
||||
|
||||
$output .= '<url>';
|
||||
$output .= '<loc>' . str_replace('&', '&', str_replace('&', '&', $this->url->link('product/category', 'path=' . $new_path))) . '</loc>';
|
||||
$output .= '<lastmod>' . $result['date'] . '</lastmod>';
|
||||
$output .= '<changefreq>weekly</changefreq>';
|
||||
$output .= '<priority>0.7</priority>';
|
||||
$output .= '</url>';
|
||||
|
||||
if(!$current_path) {
|
||||
$new_path = $result['category_id'];
|
||||
} else {
|
||||
$new_path = $current_path . '_' . $result['category_id'];
|
||||
}
|
||||
|
||||
$children = '';
|
||||
|
||||
if(array_key_exists($result['category_id'], $this->categories)) {
|
||||
$children = $this->getAllCategories($result['category_id'], $new_path);
|
||||
}
|
||||
|
||||
$output .= $children;
|
||||
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Unisender subscriber for OpenCart (ocStore) 2.3.x
|
||||
*
|
||||
* Main class subscribe/unsubscribe Unisender maillists
|
||||
*
|
||||
* @author Alexander Toporkov <toporchillo@gmail.com>
|
||||
* @copyright (C) 2013- Alexander Toporkov
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* Version of this module: http://opencartforum.ru/files/file/1258-unisender-eksport-kontakov/
|
||||
*/
|
||||
class ControllerExtensionFeedUnisender extends Controller {
|
||||
|
||||
public function update() {
|
||||
$newsletter = $this->customer->getNewsletter();
|
||||
$data = array('email'=>$this->customer->getEmail());
|
||||
|
||||
$key = $this->config->get('feed_unisender_key');
|
||||
if (!$this->config->get('feed_unisender_status') || !$key) return;
|
||||
|
||||
$field_names = array(0=>'email', 1=>'email_status');
|
||||
$dat = array(0=>array(0=>$data['email'], 1=>($newsletter ? 'active' : 'inactive')));
|
||||
|
||||
if ($newsletter) {
|
||||
$subscribtions = $this->config->get('feed_unisender_subscribtion');
|
||||
$field_names[2] = 'email_list_ids';
|
||||
$dat[0][2] = implode(',', $subscribtions);
|
||||
}
|
||||
return $this->send($field_names, $dat);
|
||||
}
|
||||
|
||||
public function subscribe_customer() {
|
||||
$customer_id = $this->session->data['customer_id'];
|
||||
$this->load->model('account/customer');
|
||||
$data = $this->model_account_customer->getCustomer($customer_id);
|
||||
$this->subscribe($data);
|
||||
}
|
||||
|
||||
public function subscribe_guest() {
|
||||
$order_id = $this->session->data['order_id'];
|
||||
$this->load->model('checkout/order');
|
||||
$data = $this->model_checkout_order->getOrder($order_id);
|
||||
if ($data['customer_id'] > 0) return;
|
||||
$this->subscribe($data);
|
||||
}
|
||||
|
||||
public function subscribe($data) {
|
||||
$key = $this->config->get('feed_unisender_key');
|
||||
if (!$this->config->get('feed_unisender_status') || !$key) return;
|
||||
|
||||
$subscribtions = $this->config->get('feed_unisender_subscribtion');
|
||||
|
||||
$field_names = array(0=>'email');
|
||||
$dat = array(0=>array(0=>$data['email']));
|
||||
$double_optin = $this->config->get('feed_unisender_ignore') ? 1 : 0;
|
||||
|
||||
if (((isset($data['newsletter']) && $data['newsletter']) || $this->config->get('feed_unisender_ignore')) && is_array($subscribtions) && count($subscribtions) > 0) {
|
||||
$field_names[1] = 'email_request_ip';
|
||||
$dat[0][1] = $this->request->server['REMOTE_ADDR'];
|
||||
|
||||
$field_names[2] = 'email_confirm_ip';
|
||||
$dat[0][2] = $this->request->server['REMOTE_ADDR'];
|
||||
|
||||
$field_names[3] = 'email_add_time';
|
||||
$dat[0][3] = gmdate('Y-m-d h:i:s', time()-20);
|
||||
|
||||
$field_names[4] = 'email_confirm_time';
|
||||
$dat[0][4] = gmdate('Y-m-d h:i:s', time()-10);
|
||||
|
||||
$field_names[5] = 'email_list_ids';
|
||||
$dat[0][5] = implode(',', $subscribtions);
|
||||
}
|
||||
if (isset($data['telephone']) && $data['telephone']) {
|
||||
$field_names[6] = 'phone';
|
||||
$dat[0][6] = $data['telephone'];
|
||||
}
|
||||
$field_names[7] = 'Name';
|
||||
$dat[0][7] = trim($data['firstname'].' '.$data['lastname']);
|
||||
|
||||
$res = $this->send($field_names, $dat, $double_optin);
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function send($field_names, $dat, $double_optin=0) {
|
||||
$key = $this->config->get('feed_unisender_key');
|
||||
$exp = array(
|
||||
'api_key' => $key,
|
||||
'double_optin' => $double_optin
|
||||
);
|
||||
|
||||
foreach($field_names as $n=>$v) {
|
||||
$exp['field_names['.$n.']'] = $v;
|
||||
}
|
||||
foreach($dat[0] as $n=>$v) {
|
||||
$exp['data[0]['.$n.']'] = $v;
|
||||
}
|
||||
|
||||
$ch = curl_init ('https://api.unisender.com/ru/api/importContacts?format=json');
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1) ;
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $exp);
|
||||
$res = curl_exec ($ch) ;
|
||||
curl_close ($ch);
|
||||
return json_decode($res);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,542 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
/**
|
||||
* Класс YML экспорта
|
||||
* YML (Yandex Market Language) - стандарт, разработанный "Яндексом"
|
||||
* для принятия и публикации информации в базе данных Яндекс.Маркет
|
||||
* YML основан на стандарте XML (Extensible Markup Language)
|
||||
* описание формата YML http://partner.market.yandex.ru/legal/tt/
|
||||
*/
|
||||
class ControllerExtensionFeedYandexMarket extends Controller {
|
||||
private $shop = array();
|
||||
private $currencies = array();
|
||||
private $categories = array();
|
||||
private $offers = array();
|
||||
private $from_charset = 'utf-8'; // UTF-8, windows-1251
|
||||
private $eol = "\n";
|
||||
|
||||
public function index() {
|
||||
if ($this->config->get('feed_yandex_market_status')) {
|
||||
// Защитный ключ
|
||||
$secret_key = $this->config->get('feed_yandex_market_secret_key');
|
||||
|
||||
if ($secret_key) {
|
||||
if (isset($this->request->get['secret_key'])) {
|
||||
if ($this->request->get['secret_key'] != $secret_key) exit();
|
||||
} else {
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Выборка категорий и производителей
|
||||
$allowed_categories = $this->config->get('feed_yandex_market_categories');
|
||||
$allowed_manufacturers = $this->config->get('feed_yandex_market_manufacturers');
|
||||
|
||||
//if (!$allowed_categories && !$allowed_manufacturers) exit();
|
||||
|
||||
$this->load->model('extension/feed/yandex_market');
|
||||
$this->load->model('localisation/currency');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
// Магазин
|
||||
$this->setShop('name', $this->config->get('feed_yandex_market_shopname'));
|
||||
$this->setShop('company', $this->config->get('feed_yandex_market_company'));
|
||||
$this->setShop('url', HTTP_SERVER);
|
||||
$this->setShop('phone', $this->config->get('config_telephone'));
|
||||
$this->setShop('platform', 'OCSTORE.COM');
|
||||
$this->setShop('version', VERSION);
|
||||
|
||||
// Валюты
|
||||
// TODO: Добавить возможность настраивать проценты в админке.
|
||||
$offers_currency = $this->config->get('feed_yandex_market_currency');
|
||||
if (!$this->currency->has($offers_currency)) exit();
|
||||
|
||||
$decimal_place = $this->currency->getDecimalPlace($offers_currency);
|
||||
|
||||
$shop_currency = $this->config->get('config_currency');
|
||||
|
||||
$this->setCurrency($offers_currency, 1);
|
||||
|
||||
$currencies = $this->model_localisation_currency->getCurrencies();
|
||||
|
||||
$supported_currencies = array('RUR', 'RUB', 'USD', 'BYN', 'BYR', 'KZT', 'EUR', 'UAH');
|
||||
|
||||
$currencies = array_intersect_key($currencies, array_flip($supported_currencies));
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
if ($currency['code'] != $offers_currency && $currency['status'] == 1) {
|
||||
$this->setCurrency($currency['code'], number_format(1/$this->currency->convert($currency['value'], $offers_currency, $shop_currency), 4, '.', ''));
|
||||
}
|
||||
}
|
||||
|
||||
// Категории <categories></categories>
|
||||
$categories = $this->model_extension_feed_yandex_market->getCategory();
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$this->setCategory($category['name'], $category['category_id'], $category['parent_id']);
|
||||
}
|
||||
|
||||
// Параметры товарного предложения <offer></offer>
|
||||
$bus_id = $this->config->get('feed_yandex_market_id'); // Идентификатор товара - "id"
|
||||
$bus_type = $this->config->get('feed_yandex_market_type'); // Тип предложений - "type"
|
||||
$bus_name = $this->config->get('feed_yandex_market_name'); // Название товара - "name"
|
||||
$bus_model = $this->config->get('feed_yandex_market_model'); // Код товара - "model"
|
||||
$bus_vendorCode = $this->config->get('feed_yandex_market_vendorCode'); // Артикул товара - "SKU"
|
||||
$bus_image = $this->config->get('feed_yandex_market_image'); // Статус товара без изображений
|
||||
$bus_image_width = $this->config->get('feed_yandex_market_image_width'); // Ширина изображения товара
|
||||
$bus_image_height = $this->config->get('feed_yandex_market_image_height'); // Высота изображения товара
|
||||
$bus_image_quantity = $this->config->get('feed_yandex_market_image_quantity'); // Количество изображений товара
|
||||
$bus_main_category = $this->config->get('feed_yandex_market_main_category'); // Статус товара без главной категории
|
||||
$in_stock_id = $this->config->get('feed_yandex_market_in_stock'); // id статуса товара "В наличии"
|
||||
$out_of_stock_id = $this->config->get('feed_yandex_market_out_of_stock'); // id статуса товара "Нет на складе"
|
||||
$bus_quantity_status = $this->config->get('feed_yandex_market_quantity_status'); // Статус товара "количество равное 0"
|
||||
$vendor_required = false; // true - только товары у которых задан производитель, необходимо для 'vendor.model'
|
||||
|
||||
$products = $this->model_extension_feed_yandex_market->getProduct($allowed_categories, $allowed_manufacturers, $out_of_stock_id, $vendor_required, $bus_image, $bus_image_quantity, $bus_main_category, $bus_quantity_status);
|
||||
|
||||
foreach ($products as $product) {
|
||||
$data = array();
|
||||
|
||||
// Атрибуты товарного предложения
|
||||
if (!empty($product[$bus_id])) {
|
||||
$data['id'] = $product[$bus_id];
|
||||
} else {
|
||||
$data['id'] = $product['product_id'];
|
||||
}
|
||||
// $data['type'] = $bus_type;
|
||||
// $data['type'] = 'vendor.model';
|
||||
$data['available'] = ($product['quantity'] > 0 || $product['stock_status_id'] == $in_stock_id);
|
||||
// $data['bid'] = 10;
|
||||
// $data['cbid'] = 15;
|
||||
|
||||
// Параметры товарного предложения
|
||||
$data['url'] = $this->url->link('product/product', 'path=' . $this->getPath($product['category_id']) . '&product_id=' . $product['product_id']);
|
||||
$data['price'] = number_format($this->currency->convert($this->tax->calculate($product['price'], $product['tax_class_id']), $shop_currency, $offers_currency), $decimal_place, '.', '');
|
||||
$data['currencyId'] = $offers_currency;
|
||||
$data['categoryId'] = $product['category_id'];
|
||||
$data['delivery'] = 'true';
|
||||
// $data['local_delivery_cost'] = 100;
|
||||
if (!empty($product[$bus_name])) {
|
||||
$data['name'] = $product[$bus_name];
|
||||
} else {
|
||||
$data['name'] = $product['name'];
|
||||
}
|
||||
if (!empty($product['manufacturer'])) {
|
||||
$data['vendor'] = $product['manufacturer'];
|
||||
} else {
|
||||
$data['vendor'] = '';
|
||||
}
|
||||
if (!empty($product[$bus_vendorCode])) {
|
||||
$data['vendorCode'] = $product[$bus_vendorCode];
|
||||
} else {
|
||||
$data['vendorCode'] = '';
|
||||
}
|
||||
if (!empty($product[$bus_model])) {
|
||||
$data['model'] = $product[$bus_model];
|
||||
} else {
|
||||
$data['model'] = '';
|
||||
}
|
||||
if (!empty($product['description'])) {
|
||||
$data['description'] = $product['description'];
|
||||
} else {
|
||||
$data['description'] = '';
|
||||
}
|
||||
// $data['manufacturer_warranty'] = 'true';
|
||||
// $data['barcode'] = $product['sku'];
|
||||
|
||||
if (!empty($product['image'])) {
|
||||
$data['picture'] = $this->model_tool_image->resize($product['image'], $bus_image_width, $bus_image_height);
|
||||
}
|
||||
|
||||
if (isset($product['images'])) {
|
||||
foreach (explode(',', $product['images']) as $image) {
|
||||
$data['picture'] .= ',' . $this->model_tool_image->resize($image, $bus_image_width, $bus_image_height);
|
||||
}
|
||||
}
|
||||
/*
|
||||
// пример структуры массива для вывода параметров
|
||||
$data['param'] = array(
|
||||
array(
|
||||
'name'=>'Wi-Fi',
|
||||
'value'=>'есть'
|
||||
), array(
|
||||
'name'=>'Размер экрана',
|
||||
'unit'=>'дюйм',
|
||||
'value'=>'20'
|
||||
), array(
|
||||
'name'=>'Вес',
|
||||
'unit'=>'кг',
|
||||
'value'=>'4.6'
|
||||
)
|
||||
);
|
||||
*/
|
||||
$this->setOffer($data);
|
||||
}
|
||||
|
||||
$this->categories = array_filter($this->categories, array($this, "filterCategory"));
|
||||
|
||||
if (!$this->categories) exit();
|
||||
|
||||
$this->response->addHeader('Content-Type: application/xml');
|
||||
$this->response->setOutput($this->getYml());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Методы формирования YML
|
||||
*/
|
||||
|
||||
/**
|
||||
* Формирование массива для элемента shop описывающего магазин
|
||||
*
|
||||
* @param string $name - Название элемента
|
||||
* @param string $value - Значение элемента
|
||||
*/
|
||||
private function setShop($name, $value) {
|
||||
$allowed = array('name', 'company', 'url', 'phone', 'platform', 'version', 'agency', 'email');
|
||||
if (in_array($name, $allowed)) {
|
||||
$this->shop[$name] = $this->prepareField($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Валюты
|
||||
*
|
||||
* @param string $id - код валюты (RUR, RUB, USD, BYN, BYR, KZT, EUR, UAH)
|
||||
* @param float|string $rate - курс этой валюты к валюте, взятой за единицу.
|
||||
* Параметр rate может иметь так же следующие значения:
|
||||
* CBRF - курс по Центральному банку РФ.
|
||||
* NBU - курс по Национальному банку Украины.
|
||||
* NBK - курс по Национальному банку Казахстана.
|
||||
* СВ - курс по банку той страны, к которой относится интернет-магазин
|
||||
* по Своему региону, указанному в Партнерском интерфейсе Яндекс.Маркета.
|
||||
* @param float $plus - используется только в случае rate = CBRF, NBU, NBK или СВ
|
||||
* и означает на сколько увеличить курс в процентах от курса выбранного банка
|
||||
* @return bool
|
||||
*/
|
||||
private function setCurrency($id, $rate = 'CBRF', $plus = 0) {
|
||||
$allow_id = array('RUR', 'RUB', 'USD', 'BYN', 'BYR', 'KZT', 'EUR', 'UAH');
|
||||
if (!in_array($id, $allow_id)) {
|
||||
return false;
|
||||
}
|
||||
$allow_rate = array('CBRF', 'NBU', 'NBK', 'CB');
|
||||
if (in_array($rate, $allow_rate)) {
|
||||
$plus = str_replace(',', '.', $plus);
|
||||
if (is_numeric($plus) && $plus > 0) {
|
||||
$this->currencies[] = array(
|
||||
'id'=>$this->prepareField(strtoupper($id)),
|
||||
'rate'=>$rate,
|
||||
'plus'=>(float)$plus
|
||||
);
|
||||
} else {
|
||||
$this->currencies[] = array(
|
||||
'id'=>$this->prepareField(strtoupper($id)),
|
||||
'rate'=>$rate
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$rate = str_replace(',', '.', $rate);
|
||||
if (!(is_numeric($rate) && $rate > 0)) {
|
||||
return false;
|
||||
}
|
||||
$this->currencies[] = array(
|
||||
'id'=>$this->prepareField(strtoupper($id)),
|
||||
'rate'=>(float)$rate
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Категории товаров
|
||||
*
|
||||
* @param string $name - название рубрики
|
||||
* @param int $id - id рубрики
|
||||
* @param int $parent_id - id родительской рубрики
|
||||
* @return bool
|
||||
*/
|
||||
private function setCategory($name, $id, $parent_id = 0) {
|
||||
$id = (int)$id;
|
||||
if ($id < 1 || trim($name) == '') {
|
||||
return false;
|
||||
}
|
||||
if ((int)$parent_id > 0) {
|
||||
$this->categories[$id] = array(
|
||||
'id'=>$id,
|
||||
'parentId'=>(int)$parent_id,
|
||||
'name'=>$this->prepareField($name)
|
||||
);
|
||||
} else {
|
||||
$this->categories[$id] = array(
|
||||
'id'=>$id,
|
||||
'name'=>$this->prepareField($name)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Товарные предложения
|
||||
*
|
||||
* @param array $data - массив параметров товарного предложения
|
||||
*/
|
||||
private function setOffer($data) {
|
||||
$offer = array();
|
||||
|
||||
$attributes = array('id', 'type', 'available', 'bid', 'cbid', 'param');
|
||||
$attributes = array_intersect_key($data, array_flip($attributes));
|
||||
|
||||
foreach ($attributes as $key => $value) {
|
||||
switch ($key)
|
||||
{
|
||||
case 'id':
|
||||
case 'bid':
|
||||
case 'cbid':
|
||||
$value = (int)$value;
|
||||
if ($value > 0) {
|
||||
$offer[$key] = $value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'type':
|
||||
if (in_array($value, array('vendor.model', 'book', 'audiobook', 'artist.title', 'tour', 'ticket', 'event-ticket'))) {
|
||||
$offer['type'] = $value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'available':
|
||||
$offer['available'] = ($value ? 'true' : 'false');
|
||||
break;
|
||||
|
||||
case 'param':
|
||||
if (is_array($value)) {
|
||||
$offer['param'] = $value;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$type = isset($offer['type']) ? $offer['type'] : '';
|
||||
|
||||
$allowed_tags = array('url'=>0, 'buyurl'=>0, 'price'=>1, 'wprice'=>0, 'currencyId'=>1, 'xCategory'=>0, 'categoryId'=>1, 'picture'=>0, 'store'=>0, 'pickup'=>0, 'delivery'=>0, 'deliveryIncluded'=>0, 'local_delivery_cost'=>0, 'orderingTime'=>0);
|
||||
|
||||
switch ($type) {
|
||||
case 'vendor.model':
|
||||
$allowed_tags = array_merge($allowed_tags, array('typePrefix'=>0, 'vendor'=>1, 'vendorCode'=>0, 'model'=>1, 'provider'=>0, 'tarifplan'=>0));
|
||||
break;
|
||||
|
||||
case 'book':
|
||||
$allowed_tags = array_merge($allowed_tags, array('author'=>0, 'name'=>1, 'publisher'=>0, 'series'=>0, 'year'=>0, 'ISBN'=>0, 'volume'=>0, 'part'=>0, 'language'=>0, 'binding'=>0, 'page_extent'=>0, 'table_of_contents'=>0));
|
||||
break;
|
||||
|
||||
case 'audiobook':
|
||||
$allowed_tags = array_merge($allowed_tags, array('author'=>0, 'name'=>1, 'publisher'=>0, 'series'=>0, 'year'=>0, 'ISBN'=>0, 'volume'=>0, 'part'=>0, 'language'=>0, 'table_of_contents'=>0, 'performed_by'=>0, 'performance_type'=>0, 'storage'=>0, 'format'=>0, 'recording_length'=>0));
|
||||
break;
|
||||
|
||||
case 'artist.title':
|
||||
$allowed_tags = array_merge($allowed_tags, array('artist'=>0, 'title'=>1, 'year'=>0, 'media'=>0, 'starring'=>0, 'director'=>0, 'originalName'=>0, 'country'=>0));
|
||||
break;
|
||||
|
||||
case 'tour':
|
||||
$allowed_tags = array_merge($allowed_tags, array('worldRegion'=>0, 'country'=>0, 'region'=>0, 'days'=>1, 'dataTour'=>0, 'name'=>1, 'hotel_stars'=>0, 'room'=>0, 'meal'=>0, 'included'=>1, 'transport'=>1, 'price_min'=>0, 'price_max'=>0, 'options'=>0));
|
||||
break;
|
||||
|
||||
case 'event-ticket':
|
||||
$allowed_tags = array_merge($allowed_tags, array('name'=>1, 'place'=>1, 'hall'=>0, 'hall_part'=>0, 'date'=>1, 'is_premiere'=>0, 'is_kids'=>0));
|
||||
break;
|
||||
|
||||
default:
|
||||
$allowed_tags = array_merge($allowed_tags, array('name'=>1, 'vendor'=>0, 'vendorCode'=>0, 'model'=>1));
|
||||
break;
|
||||
}
|
||||
|
||||
$allowed_tags = array_merge($allowed_tags, array('aliases'=>0, 'additional'=>0, 'description'=>0, 'sales_notes'=>0, 'promo'=>0, 'manufacturer_warranty'=>0, 'country_of_origin'=>0, 'downloadable'=>0, 'adult'=>0, 'barcode'=>0));
|
||||
|
||||
$required_tags = array_filter($allowed_tags);
|
||||
|
||||
if (sizeof(array_intersect_key($data, $required_tags)) != sizeof($required_tags)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array_intersect_key($data, $allowed_tags);
|
||||
// if (isset($data['tarifplan']) && !isset($data['provider'])) {
|
||||
// unset($data['tarifplan']);
|
||||
// }
|
||||
|
||||
$allowed_tags = array_intersect_key($allowed_tags, $data);
|
||||
|
||||
// Стандарт XML учитывает порядок следования элементов,
|
||||
// поэтому важно соблюдать его в соответствии с порядком описанным в DTD
|
||||
$offer['data'] = array();
|
||||
foreach ($allowed_tags as $key => $value) {
|
||||
$offer['data'][$key] = $this->prepareField($data[$key], $key);
|
||||
}
|
||||
|
||||
$this->offers[] = $offer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Формирование YML файла
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getYml() {
|
||||
$yml = '<?xml version="1.0" encoding="' . $this->from_charset . '"?>' . $this->eol;
|
||||
$yml .= '<!DOCTYPE yml_catalog SYSTEM "shops.dtd">' . $this->eol;
|
||||
$yml .= '<yml_catalog date="' . date('Y-m-d H:i') . '">' . $this->eol;
|
||||
$yml .= '<shop>' . $this->eol;
|
||||
|
||||
// информация о магазине
|
||||
$yml .= $this->array2Tag($this->shop);
|
||||
|
||||
// валюты
|
||||
$yml .= '<currencies>' . $this->eol;
|
||||
foreach ($this->currencies as $currency) {
|
||||
$yml .= $this->getElement($currency, 'currency');
|
||||
}
|
||||
$yml .= '</currencies>' . $this->eol;
|
||||
|
||||
// категории
|
||||
$yml .= '<categories>' . $this->eol;
|
||||
foreach ($this->categories as $category) {
|
||||
$category_name = $category['name'];
|
||||
unset($category['name'], $category['export']);
|
||||
$yml .= $this->getElement($category, 'category', $category_name);
|
||||
}
|
||||
$yml .= '</categories>' . $this->eol;
|
||||
|
||||
// товарные предложения
|
||||
$yml .= '<offers>' . $this->eol;
|
||||
foreach ($this->offers as $offer) {
|
||||
$tags = $this->array2Tag($offer['data']);
|
||||
unset($offer['data']);
|
||||
if (isset($offer['param'])) {
|
||||
$tags .= $this->array2Param($offer['param']);
|
||||
unset($offer['param']);
|
||||
}
|
||||
$yml .= $this->getElement($offer, 'offer', $tags);
|
||||
}
|
||||
$yml .= '</offers>' . $this->eol;
|
||||
|
||||
$yml .= '</shop>';
|
||||
$yml .= '</yml_catalog>';
|
||||
|
||||
return $yml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Фрмирование элемента
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param string $element_name
|
||||
* @param string $element_value
|
||||
* @return string
|
||||
*/
|
||||
private function getElement($attributes, $element_name, $element_value = '') {
|
||||
$retval = '<' . $element_name . ' ';
|
||||
foreach ($attributes as $key => $value) {
|
||||
$retval .= $key . '="' . $value . '" ';
|
||||
}
|
||||
$retval .= $element_value ? '>' . $this->eol . $element_value . '</' . $element_name . '>' : '/>';
|
||||
$retval .= $this->eol;
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Преобразование массива в теги
|
||||
*
|
||||
* @param array $tags
|
||||
* @return string
|
||||
*/
|
||||
private function array2Tag($tags) {
|
||||
$retval = '';
|
||||
foreach ($tags as $key => $value) {
|
||||
if ($key == 'picture') {
|
||||
foreach (explode(',', $value) as $val) {
|
||||
$retval .= '<' . $key . '>' . $val . '</' . $key . '>' . $this->eol;
|
||||
}
|
||||
} else {
|
||||
$retval .= '<' . $key . '>' . $value . '</' . $key . '>' . $this->eol;
|
||||
}
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Преобразование массива в теги параметров
|
||||
*
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
private function array2Param($params) {
|
||||
$retval = '';
|
||||
foreach ($params as $param) {
|
||||
$retval .= '<param name="' . $this->prepareField($param['name']);
|
||||
if (isset($param['unit'])) {
|
||||
$retval .= '" unit="' . $this->prepareField($param['unit']);
|
||||
}
|
||||
$retval .= '">' . $this->prepareField($param['value']) . '</param>' . $this->eol;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Подготовка текстового поля в соответствии с требованиями Яндекса
|
||||
* Запрещаем любые html-тэги, стандарт XML не допускает использования в текстовых данных
|
||||
* непечатаемых символов с ASCII-кодами в диапазоне значений от 0 до 31 (за исключением
|
||||
* символов с кодами 9, 10, 13 - табуляция, перевод строки, возврат каретки). Также этот
|
||||
* стандарт требует обязательной замены некоторых символов на их символьные примитивы.
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
private function prepareField($field, $key = false) {
|
||||
if ($field) {
|
||||
$field = htmlspecialchars_decode($field);
|
||||
$field = strip_tags($field);
|
||||
$from = array('"', '&', '>', '<', '\'');
|
||||
$to = array('"', '&', '>', '<', ''');
|
||||
$field = str_replace($from, $to, $field);
|
||||
if ($key == 'description') {
|
||||
$field = "<![CDATA[" . mb_substr($field, 0, 3000) . "]]>";
|
||||
}
|
||||
if ($this->from_charset == 'windows-1251') {
|
||||
$field = iconv($this->from_charset, 'windows-1251//TRANSLIT//IGNORE', $field);
|
||||
}
|
||||
$field = preg_replace('#[\x00-\x08\x0B-\x0C\x0E-\x1F]+#is', ' ', $field);
|
||||
}
|
||||
|
||||
return trim($field);
|
||||
}
|
||||
|
||||
protected function getPath($category_id, $current_path = '') {
|
||||
if (isset($this->categories[$category_id])) {
|
||||
$this->categories[$category_id]['export'] = 1;
|
||||
|
||||
if (!$current_path) {
|
||||
$new_path = $this->categories[$category_id]['id'];
|
||||
} else {
|
||||
$new_path = $this->categories[$category_id]['id'] . '_' . $current_path;
|
||||
}
|
||||
|
||||
if (isset($this->categories[$category_id]['parentId'])) {
|
||||
return $this->getPath($this->categories[$category_id]['parentId'], $new_path);
|
||||
} else {
|
||||
return $new_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function filterCategory($category) {
|
||||
return isset($category['export']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/**
|
||||
* Класс YML экспорта
|
||||
* YML (Yandex Market Language) - стандарт, разработанный "Яндексом"
|
||||
* для принятия и публикации информации в базе данных Яндекс.Маркет
|
||||
* YML основан на стандарте XML (Extensible Markup Language)
|
||||
* описание формата YML http://partner.market.yandex.ru/legal/tt/
|
||||
*/
|
||||
class ControllerExtensionFeedYandexTurbo extends Controller {
|
||||
private $currencies = array();
|
||||
private $categories = array();
|
||||
private $eol = "";
|
||||
|
||||
public function index() {
|
||||
if ($this->config->get('feed_yandex_turbo_status')) {
|
||||
|
||||
$this->load->model('extension/feed/yandex_turbo');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$this->eol = "\n";
|
||||
$output = '<?xml version="1.0" encoding="UTF-8"?>' . $this->eol;
|
||||
$output .= '<!DOCTYPE yml_catalog SYSTEM "shops.dtd">' . $this->eol;
|
||||
$output .= '<yml_catalog date="' . date('Y-m-d H:i') . '">' . $this->eol;
|
||||
$output .= '<shop>' . $this->eol;
|
||||
$output .= '<name>' . $this->config->get('config_name') . '</name>' . $this->eol ;
|
||||
$output .= '<company>' . $this->config->get('config_owner') . '</company>' . $this->eol ;
|
||||
$output .= '<url>' . HTTPS_SERVER . '</url>' . $this->eol ;
|
||||
$output .= '<phone>' . $this->config->get('config_telephone') . '</phone>' . $this->eol ;
|
||||
$output .= '<platform>Opencart</platform>' . $this->eol ;
|
||||
$output .= '<version>' . VERSION . '</version>' . $this->eol ;
|
||||
|
||||
$offers_currency = $this->config->get('feed_yandex_turbo_currency');
|
||||
|
||||
$this->load->model('localisation/currency');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (!$this->currency->has($offers_currency)) exit();
|
||||
$decimal_place = $this->currency->getDecimalPlace($offers_currency);
|
||||
$shop_currency = $this->config->get('config_currency');
|
||||
$this->setCurrency($offers_currency, 1);
|
||||
$currencies = $this->model_localisation_currency->getCurrencies();
|
||||
$supported_currencies = array('RUR', 'RUB', 'USD', 'BYR', 'KZT', 'EUR', 'UAH');
|
||||
$currencies = array_intersect_key($currencies, array_flip($supported_currencies));
|
||||
foreach ($currencies as $currency) {
|
||||
if ($currency['code'] != $offers_currency && $currency['status'] == 1) {
|
||||
$this->setCurrency($currency['code'], number_format(1/$this->currency->convert($currency['value'], $offers_currency, $shop_currency), 4, '.', ''));
|
||||
}
|
||||
}
|
||||
$output .= '<currencies>' . $this->eol;
|
||||
foreach ($this->currencies as $currency) {
|
||||
$output .= $this->getElement($currency, 'currency');
|
||||
}
|
||||
$output .= '</currencies>' . $this->eol;
|
||||
$decimal = (int)$this->currency->getDecimalPlace($offers_currency);
|
||||
|
||||
$categories = $this->model_extension_feed_yandex_turbo->getCategories();
|
||||
foreach ($categories as $category) {
|
||||
$this->setCategory($category['name'], $category['category_id'], $category['parent_id']);
|
||||
}
|
||||
|
||||
$output .= '<categories>' . $this->eol;
|
||||
|
||||
foreach ($this->categories as $category) {
|
||||
|
||||
$category_name = $category['name'];
|
||||
unset($category['name'], $category['export']);
|
||||
$output .= $this->getElement($category, 'category', $category_name);
|
||||
|
||||
|
||||
}
|
||||
|
||||
$output .= '</categories>' . $this->eol;
|
||||
$output .= '<offers>' . $this->eol;
|
||||
|
||||
|
||||
|
||||
$products = $this->model_extension_feed_yandex_turbo->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
$output .= '<offer id="' . $product['product_id'] . '" available="' . ($product['quantity'] > 0 ? 'true' : 'false') . '">' . $this->eol;
|
||||
$output .= '<url>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</url>' . $this->eol;
|
||||
$output .= '<price>' . number_format($this->currency->convert($this->tax->calculate($product['price'], $product['tax_class_id']), $shop_currency, $offers_currency), $decimal, '.', '') . '</price>';
|
||||
$output .= '<currencyId>' . $offers_currency . '</currencyId>' . $this->eol;
|
||||
$output .= '<categoryId>' . $product['category_id'] . '</categoryId>' . $this->eol;
|
||||
$output .= '<picture>' . $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')) . '</picture>' . $this->eol;
|
||||
$output .= '<name><![CDATA[' . $this->prepareField($product['name']) . ']]></name>' . $this->eol;
|
||||
$output .= '<description><![CDATA[' . $this->prepareField($product['description']) . ']]></description>' . $this->eol;
|
||||
$output .= '</offer>' . $this->eol;
|
||||
}
|
||||
|
||||
$output .= '</offers>' . $this->eol;
|
||||
$output .= '</shop>'. $this->eol;
|
||||
$output .= '</yml_catalog>';
|
||||
|
||||
$this->response->addHeader('Content-Type: application/xml');
|
||||
$this->response->setOutput($output);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function setCurrency($id, $rate = 'CBRF', $plus = 0) {
|
||||
$allow_id = array('RUR', 'RUB', 'USD', 'BYR', 'KZT', 'EUR', 'UAH');
|
||||
if (!in_array($id, $allow_id)) {
|
||||
return false;
|
||||
}
|
||||
$allow_rate = array('CBRF', 'NBU', 'NBK', 'CB');
|
||||
if (in_array($rate, $allow_rate)) {
|
||||
$plus = str_replace(',', '.', $plus);
|
||||
if (is_numeric($plus) && $plus > 0) {
|
||||
$this->currencies[] = array(
|
||||
'id'=>$this->prepareField(strtoupper($id)),
|
||||
'rate'=>$rate,
|
||||
'plus'=>(float)$plus
|
||||
);
|
||||
} else {
|
||||
$this->currencies[] = array(
|
||||
'id'=>$this->prepareField(strtoupper($id)),
|
||||
'rate'=>$rate
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$rate = str_replace(',', '.', $rate);
|
||||
if (!(is_numeric($rate) && $rate > 0)) {
|
||||
return false;
|
||||
}
|
||||
$this->currencies[] = array(
|
||||
'id'=>$this->prepareField(strtoupper($id)),
|
||||
'rate'=>(float)$rate
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function setCategory($name, $id, $parent_id = 0) {
|
||||
$id = (int)$id;
|
||||
if ($id < 1 || trim($name) == '') {
|
||||
return false;
|
||||
}
|
||||
if ((int)$parent_id > 0) {
|
||||
$this->categories[$id] = array(
|
||||
'id'=>$id,
|
||||
'parentId'=>(int)$parent_id,
|
||||
'name'=>$this->prepareField($name)
|
||||
);
|
||||
} else {
|
||||
$this->categories[$id] = array(
|
||||
'id'=>$id,
|
||||
'name'=>$this->prepareField($name)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getElement($attributes, $element_name, $element_value = '') {
|
||||
$retval = '<' . $element_name . ' ';
|
||||
foreach ($attributes as $key => $value) {
|
||||
$retval .= $key . '="' . $value . '" ';
|
||||
}
|
||||
$retval .= $element_value ? '>' . $this->eol . $element_value . '</' . $element_name . '>' : '/>';
|
||||
$retval .= $this->eol;
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
private function prepareField($field) {
|
||||
|
||||
$field = htmlspecialchars_decode($field);
|
||||
$field = strip_tags($field);
|
||||
|
||||
$from = array('"', '&', '>', '<', '°', '\'');
|
||||
$to = array('"', '&', '>', '<', '°', ''');
|
||||
$field = str_replace($from, $to, $field);
|
||||
|
||||
$field = preg_replace('#[\x00-\x08\x0B-\x0C\x0E-\x1F]+#is', ' ', $field);
|
||||
|
||||
return trim($field);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleAccount extends Controller {
|
||||
public function index() {
|
||||
$this->load->language('extension/module/account');
|
||||
|
||||
$data['logged'] = $this->customer->isLogged();
|
||||
$data['register'] = $this->url->link('account/register', '', true);
|
||||
$data['login'] = $this->url->link('account/login', '', true);
|
||||
$data['logout'] = $this->url->link('account/logout', '', true);
|
||||
$data['forgotten'] = $this->url->link('account/forgotten', '', true);
|
||||
$data['account'] = $this->url->link('account/account', '', true);
|
||||
$data['edit'] = $this->url->link('account/edit', '', true);
|
||||
$data['password'] = $this->url->link('account/password', '', true);
|
||||
$data['address'] = $this->url->link('account/address', '', true);
|
||||
$data['wishlist'] = $this->url->link('account/wishlist');
|
||||
$data['order'] = $this->url->link('account/order', '', true);
|
||||
$data['download'] = $this->url->link('account/download', '', true);
|
||||
$data['reward'] = $this->url->link('account/reward', '', true);
|
||||
$data['return'] = $this->url->link('account/return', '', true);
|
||||
$data['transaction'] = $this->url->link('account/transaction', '', true);
|
||||
$data['newsletter'] = $this->url->link('account/newsletter', '', true);
|
||||
$data['recurring'] = $this->url->link('account/recurring', '', true);
|
||||
|
||||
return $this->load->view('extension/module/account', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleBanner extends Controller {
|
||||
public function index($setting) {
|
||||
static $module = 0;
|
||||
|
||||
$this->load->model('design/banner');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$this->document->addStyle('store/view/javascript/jquery/swiper/css/swiper.min.css');
|
||||
$this->document->addStyle('store/view/javascript/jquery/swiper/css/opencart.css');
|
||||
$this->document->addScript('store/view/javascript/jquery/swiper/js/swiper.jquery.js');
|
||||
|
||||
$data['banners'] = array();
|
||||
|
||||
$results = $this->model_design_banner->getBanner($setting['banner_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . $result['image'])) {
|
||||
$data['banners'][] = array(
|
||||
'title' => $result['title'],
|
||||
'link' => $result['link'],
|
||||
'description' => $result['description'],
|
||||
'button_text' => $result['button_text'],
|
||||
'image' => $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']),
|
||||
'image_mobile' => $result['image_mobile'] && is_file(DIR_IMAGE . $result['image_mobile']) ? $this->model_tool_image->resize($result['image_mobile'], $setting['width'], $setting['height']) : ''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$data['module'] = $module++;
|
||||
|
||||
return $this->load->view('extension/module/banner', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleBestSeller extends Controller {
|
||||
public function index($setting) {
|
||||
$this->load->language('extension/module/bestseller');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['products'] = array();
|
||||
$data['module_name'] = $setting['name'];
|
||||
|
||||
$results = $this->model_catalog_product->getBestSellerProducts($setting['limit']);
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['image']) {
|
||||
$image = $this->model_tool_image->resize($result['image'], $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 (!is_null($result['special']) && (float)$result['special'] >= 0) {
|
||||
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$tax_price = (float)$result['special'];
|
||||
} else {
|
||||
$special = false;
|
||||
$tax_price = (float)$result['price'];
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format($tax_price, $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$rating = $result['rating'];
|
||||
} else {
|
||||
$rating = false;
|
||||
}
|
||||
|
||||
$results = $this->model_catalog_product->getProductImages($product_id);
|
||||
if($results){
|
||||
$additional_image = $this->model_tool_image->resize($results[0]['image'], $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$additional_image = false;
|
||||
}
|
||||
$data['products'][] = array(
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'additional_thumb' => $additional_image,
|
||||
'price_n' => $product_info['price'],
|
||||
'price_2' => $this->currency->format($this->tax->calculate($product_info['price_2'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'price_2_n' => $product_info['price_2'],
|
||||
'price_3' => $this->currency->format($this->tax->calculate($product_info['price_3'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'price_3_n' => $product_info['price_3'],
|
||||
'min_price' => $this->currency->format($this->tax->calculate(min([$product_info['price'],$product_info['price_2']]), $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'name' => $result['name'],
|
||||
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'rating' => $rating,
|
||||
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
|
||||
);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/bestseller', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerExtensionModuleBlogCategory extends Controller {
|
||||
public function index() {
|
||||
$this->load->language('extension/module/blog_category');
|
||||
|
||||
$data['heading_title'] = $this->language->get('heading_title');
|
||||
|
||||
if (isset($this->request->get['blog_category_id'])) {
|
||||
$parts = explode('_', (string)$this->request->get['blog_category_id']);
|
||||
} else {
|
||||
$parts = array();
|
||||
}
|
||||
|
||||
if (isset($parts[0])) {
|
||||
$data['blog_category_id'] = $parts[0];
|
||||
} else {
|
||||
$data['blog_category_id'] = 0;
|
||||
}
|
||||
|
||||
if (isset($parts[1])) {
|
||||
$data['child_id'] = $parts[1];
|
||||
} else {
|
||||
$data['child_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('blog/category');
|
||||
|
||||
$this->load->model('blog/article');
|
||||
|
||||
$data['categories'] = array();
|
||||
|
||||
$categories = $this->model_blog_category->getCategories(0);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$children_data = array();
|
||||
|
||||
if ($category['blog_category_id'] == $data['blog_category_id']) {
|
||||
$children = $this->model_blog_category->getCategories($category['blog_category_id']);
|
||||
|
||||
foreach($children as $child) {
|
||||
$filter_data = array('filter_blog_category_id' => $child['blog_category_id'], 'filter_sub_category' => true);
|
||||
|
||||
$children_data[] = array(
|
||||
'blog_category_id' => $child['blog_category_id'],
|
||||
'name' => $child['name'] . ($this->config->get('configblog_article_count') ? ' (' . $this->model_blog_article->getTotalArticles($filter_data) . ')' : ''),
|
||||
'href' => $this->url->link('blog/category', 'blog_category_id=' . $category['blog_category_id'] . '_' . $child['blog_category_id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$filter_data = array(
|
||||
'filter_blog_category_id' => $category['blog_category_id'],
|
||||
);
|
||||
|
||||
$data['categories'][] = array(
|
||||
'blog_category_id' => $category['blog_category_id'],
|
||||
'name' => $category['name'] . ($this->config->get('configblog_article_count') ? ' (' . $this->model_blog_article->getTotalArticles($filter_data) . ')' : ''),
|
||||
'children' => $children_data,
|
||||
'href' => $this->url->link('blog/category', 'blog_category_id=' . $category['blog_category_id'])
|
||||
);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/blog_category', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerExtensionModuleBlogFeatured extends Controller {
|
||||
public function index($setting) {
|
||||
$this->load->language('extension/module/blog_featured');
|
||||
|
||||
$this->load->model('blog/article');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['articles'] = array();
|
||||
|
||||
if (!$setting['limit']) {
|
||||
$setting['limit'] = 4;
|
||||
}
|
||||
|
||||
if (!empty($setting['article'])) {
|
||||
$articles = array_slice($setting['article'], 0, (int)$setting['limit']);
|
||||
|
||||
foreach ($articles as $article_id) {
|
||||
$article_info = $this->model_blog_article->getArticle($article_id);
|
||||
|
||||
if ($article_info) {
|
||||
if ($article_info['image']) {
|
||||
$image = $this->model_tool_image->resize($article_info['image'], $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
|
||||
}
|
||||
|
||||
if ($this->config->get('configblog_review_status')) {
|
||||
$rating = $article_info['rating'];
|
||||
} else {
|
||||
$rating = false;
|
||||
}
|
||||
|
||||
$data['articles'][] = array(
|
||||
'article_id' => $article_info['article_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $article_info['name'],
|
||||
'description' => utf8_substr(strip_tags(html_entity_decode($article_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('configblog_article_description_length')) . '..',
|
||||
'rating' => $rating,
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($article_info['date_added'])),
|
||||
'viewed' => $article_info['viewed'],
|
||||
'href' => $this->url->link('blog/article', 'article_id=' . $article_info['article_id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['articles']) {
|
||||
return $this->load->view('extension/module/blog_featured', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerExtensionModuleBlogLatest extends Controller {
|
||||
public function index($setting) {
|
||||
$this->load->language('extension/module/blog_latest');
|
||||
|
||||
$this->load->model('blog/article');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['articles'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => 'p.date_added',
|
||||
'order' => 'DESC',
|
||||
'start' => 0,
|
||||
'limit' => $setting['limit']
|
||||
);
|
||||
|
||||
$results = $this->model_blog_article->getArticles($filter_data);
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['image']) {
|
||||
$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
|
||||
}
|
||||
|
||||
if ($this->config->get('configblog_review_status')) {
|
||||
$rating = $result['rating'];
|
||||
} else {
|
||||
$rating = false;
|
||||
}
|
||||
|
||||
$data['articles'][] = array(
|
||||
'article_id' => $result['article_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('configblog_article_description_length')) . '..',
|
||||
'rating' => $rating,
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'viewed' => $result['viewed'],
|
||||
'href' => $this->url->link('blog/article', 'article_id=' . $result['article_id'])
|
||||
);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/blog_latest', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleCallback extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->language->load('extension/module/callback');
|
||||
$json = array();
|
||||
|
||||
// $this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
|
||||
// $data['heading_title'] = $this->language->get('heading_title');
|
||||
|
||||
if ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($this->request->post['action'])) {
|
||||
if ($this->validate()) {
|
||||
$data = array();
|
||||
if (isset($this->request->post['name'])) {
|
||||
$data['name'] = $this->request->post['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
if (isset($this->request->post['phone'])) {
|
||||
$data['phone'] = $this->request->post['phone'];
|
||||
} else {
|
||||
$data['phone'] = '';
|
||||
}
|
||||
if (isset($this->request->post['comment'])) {
|
||||
$data['comment'] = $this->request->post['comment'];
|
||||
} else {
|
||||
$data['comment'] = '';
|
||||
}
|
||||
$this->load->model('extension/module/callback');
|
||||
$results = $this->model_extension_module_callback->addCallback($data);
|
||||
|
||||
if ($this->config->get('theme_lightshop_callback_email_alert')) {
|
||||
$this->sendMail($data);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('ok');
|
||||
}else{
|
||||
$json['warning'] = $this->error;
|
||||
}
|
||||
|
||||
return $this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
// Captcha
|
||||
if ($this->config->get('theme_lightshop_config_captcha_cb')) {
|
||||
$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('theme_lightshop_config_captcha_cb'));
|
||||
|
||||
} else {
|
||||
$data['captcha'] = '';
|
||||
}
|
||||
|
||||
$data['sendthis'] = $this->language->get('sendthis');
|
||||
$data['namew'] = $this->language->get('namew');
|
||||
$data['phonew'] = $this->language->get('phonew');
|
||||
$data['sendw'] = $this->language->get('sendw');
|
||||
$data['cancel'] = $this->language->get('cancel');
|
||||
$data['comment'] = $this->language->get('comment');
|
||||
|
||||
if ($this->config->get('theme_lightshop_callback_pdata')) {
|
||||
$this->load->language('extension/theme/lightshop');
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
$information_info = $this->model_catalog_information->getInformation($this->config->get('theme_lightshop_callback_pdata'));
|
||||
|
||||
if ($information_info) {
|
||||
$data['text_lightshop_pdata'] = sprintf($this->language->get('text_lightshop_pdata'), $this->language->get('sendw'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('theme_lightshop_callback_pdata'), true), $information_info['title'], $information_info['title']);
|
||||
} else {
|
||||
$data['text_lightshop_pdata'] = '';
|
||||
}
|
||||
} else {
|
||||
$data['text_lightshop_pdata'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/callback', $data);
|
||||
// $this->response->setOutput($this->load->view('extension/module/callback', $data));
|
||||
|
||||
}
|
||||
|
||||
private function validate() {
|
||||
$this->language->load('extension/module/callback');
|
||||
if ((strlen(utf8_decode($this->request->post['name'])) < 1) || (strlen(utf8_decode($this->request->post['name'])) > 32)) {
|
||||
$this->error['name'] = $this->language->get('mister');
|
||||
}
|
||||
if ((strlen(utf8_decode($this->request->post['phone'])) < 3) || (strlen(utf8_decode($this->request->post['phone'])) > 32)) {
|
||||
$this->error['phone'] = $this->language->get('wrongnumber');
|
||||
}
|
||||
|
||||
// Captcha
|
||||
if ($this->config->get('captcha_' . $this->config->get('theme_lightshop_config_captcha_cb') . '_status')) {
|
||||
$captcha = $this->load->controller('extension/captcha/' . $this->config->get('theme_lightshop_config_captcha_cb') . '/validate');
|
||||
|
||||
if ($captcha) {
|
||||
$this->error['captcha'] = $captcha;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->error) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private function sendMail($data) {
|
||||
$subject = $this->language->get('subject');
|
||||
$text = $this->language->get('text_1');
|
||||
$text .= $this->language->get('subject') . ":\n";
|
||||
$text .= $this->language->get('name') . $data['name'] . "\n";
|
||||
$text .= $this->language->get('phone') . $data['phone'] . "\n";
|
||||
$text .= $this->language->get('comment') . $data['comment'] . "\n";
|
||||
|
||||
$mail = new Mail();
|
||||
$mail->protocol = $this->config->get('config_mail_protocol');
|
||||
$mail->parameter = $this->config->get('config_mail_parameter');
|
||||
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
|
||||
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
|
||||
$mail->smtp_password = $this->config->get('config_mail_smtp_password');
|
||||
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
|
||||
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
|
||||
$mail->setTo($this->config->get('config_email'));
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($this->config->get('config_name'));
|
||||
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
|
||||
$mail->send();
|
||||
|
||||
// Send to additional alert emails
|
||||
$emails = explode(',', $this->config->get('config_alert_email'));
|
||||
|
||||
foreach ($emails as $email) {
|
||||
if ($email && preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $email)) {
|
||||
$mail->setTo($email);
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleCarousel extends Controller {
|
||||
public function index($setting) {
|
||||
static $module = 0;
|
||||
|
||||
$this->load->model('design/banner');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$this->document->addStyle('store/view/javascript/jquery/swiper/css/swiper.min.css');
|
||||
$this->document->addStyle('store/view/javascript/jquery/swiper/css/opencart.css');
|
||||
$this->document->addScript('store/view/javascript/jquery/swiper/js/swiper.jquery.js');
|
||||
|
||||
$data['banners'] = array();
|
||||
|
||||
$results = $this->model_design_banner->getBanner($setting['banner_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . $result['image'])) {
|
||||
$data['banners'][] = array(
|
||||
'title' => $result['title'],
|
||||
'link' => $result['link'],
|
||||
'image' => $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$data['module'] = $module++;
|
||||
|
||||
return $this->load->view('extension/module/carousel', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleCategory extends Controller {
|
||||
public function index() {
|
||||
$this->load->language('extension/module/category');
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$parts = explode('_', (string)$this->request->get['path']);
|
||||
} else {
|
||||
$parts = array();
|
||||
}
|
||||
|
||||
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'] = array();
|
||||
|
||||
$categories = $this->model_catalog_category->getCategories(0);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$children_data = array();
|
||||
|
||||
if ($category['category_id'] == $data['category_id']) {
|
||||
$children = $this->model_catalog_category->getCategories($category['category_id']);
|
||||
|
||||
foreach($children as $child) {
|
||||
$filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);
|
||||
|
||||
$children_data[] = array(
|
||||
'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', 'path=' . $category['category_id'] . '_' . $child['category_id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$filter_data = array(
|
||||
'filter_category_id' => $category['category_id'],
|
||||
'filter_sub_category' => true
|
||||
);
|
||||
|
||||
$data['categories'][] = array(
|
||||
'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', 'path=' . $category['category_id'])
|
||||
);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/category', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleFeatured extends Controller {
|
||||
public function index($setting) {
|
||||
$this->load->language('extension/module/featured');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['products'] = array();
|
||||
$data['module_name'] = $setting['name'];
|
||||
|
||||
if (!$setting['limit']) {
|
||||
$setting['limit'] = 4;
|
||||
}
|
||||
|
||||
if (!empty($setting['product'])) {
|
||||
$products = array_slice($setting['product'], 0, (int)$setting['limit']);
|
||||
|
||||
foreach ($products as $product_id) {
|
||||
$product_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if ($product_info) {
|
||||
if ($product_info['image']) {
|
||||
$image = $this->model_tool_image->resize($product_info['image'], $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_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
} else {
|
||||
$price = false;
|
||||
}
|
||||
|
||||
if (!is_null($product_info['special']) && (float)$product_info['special'] >= 0) {
|
||||
$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$tax_price = (float)$product_info['special'];
|
||||
} else {
|
||||
$special = false;
|
||||
$tax_price = (float)$product_info['price'];
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format($tax_price, $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$rating = $product_info['rating'];
|
||||
} else {
|
||||
$rating = false;
|
||||
}
|
||||
|
||||
$results = $this->model_catalog_product->getProductImages($product_id);
|
||||
if($results){
|
||||
$additional_image = $this->model_tool_image->resize($results[0]['image'], $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$additional_image = false;
|
||||
}
|
||||
$data['products'][] = array(
|
||||
'product_id' => $product_info['product_id'],
|
||||
'thumb' => $image,
|
||||
'additional_thumb' => $additional_image,
|
||||
'price_n' => $product_info['price'],
|
||||
'price_2' => $this->currency->format($this->tax->calculate($product_info['price_2'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'price_2_n' => $product_info['price_2'],
|
||||
'price_3' => $this->currency->format($this->tax->calculate($product_info['price_3'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'price_3_n' => $product_info['price_3'],
|
||||
'min_price' => $this->currency->format($this->tax->calculate(min([$product_info['price'],$product_info['price_2']]), $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'name' => $product_info['name'],
|
||||
'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'rating' => $rating,
|
||||
'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['products']) {
|
||||
return $this->load->view('extension/module/featured', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerExtensionModuleFeaturedArticle extends Controller {
|
||||
public function index($setting) {
|
||||
|
||||
if (isset($this->request->get['product_id']) || isset($this->request->get['manufacturer_id']) || isset($this->request->get['path'])) {
|
||||
$this->load->language('extension/module/featured_article');
|
||||
|
||||
$this->load->model('blog/article');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['articles'] = array();
|
||||
|
||||
$results = array();
|
||||
|
||||
if (isset($this->request->get['product_id'])) {
|
||||
|
||||
$filter_data = array(
|
||||
'product_id' => $this->request->get['product_id'],
|
||||
'limit' => $setting['limit']
|
||||
);
|
||||
|
||||
$results = $this->model_blog_article->getArticleRelatedByProduct($filter_data);
|
||||
|
||||
} elseif (isset($this->request->get['manufacturer_id'])) {
|
||||
|
||||
$filter_data = array(
|
||||
'manufacturer_id' => $this->request->get['manufacturer_id'],
|
||||
'limit' => $setting['limit']
|
||||
);
|
||||
|
||||
$results = $this->model_blog_article->getArticleRelatedByManufacturer($filter_data);
|
||||
|
||||
} else {
|
||||
|
||||
$parts = explode('_', (string)$this->request->get['path']);
|
||||
|
||||
if(!empty($parts) && is_array($parts)) {
|
||||
|
||||
$filter_data = array(
|
||||
'category_id' => array_pop($parts),
|
||||
'limit' => $setting['limit']
|
||||
);
|
||||
|
||||
$results = $this->model_blog_article->getArticleRelatedByCategory($filter_data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['image']) {
|
||||
$image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
|
||||
}
|
||||
|
||||
$data['configblog_review_status'] = $this->config->get('configblog_review_status');
|
||||
|
||||
if ($this->config->get('configblog_review_status')) {
|
||||
$rating = $result['rating'];
|
||||
} else {
|
||||
$rating = false;
|
||||
}
|
||||
|
||||
$data['articles'][] = array(
|
||||
'article_id' => $result['article_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('configblog_article_description_length')) . '..',
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'viewed' => $result['viewed'],
|
||||
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
|
||||
'rating' => $rating,
|
||||
'href' => $this->url->link('blog/article', 'article_id=' . $result['article_id']),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/featured_article', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerExtensionModuleFeaturedProduct extends Controller {
|
||||
public function index($setting) {
|
||||
|
||||
|
||||
if (!$setting['limit']) {
|
||||
$setting['limit'] = 4;
|
||||
}
|
||||
|
||||
$results = array();
|
||||
|
||||
$this->load->model('catalog/cms');
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
|
||||
$filter_data = array(
|
||||
'manufacturer_id' => $this->request->get['manufacturer_id'],
|
||||
'limit' => $setting['limit']
|
||||
);
|
||||
|
||||
$results = $this->model_catalog_cms->getProductRelatedByManufacturer($filter_data);
|
||||
|
||||
} else {
|
||||
|
||||
$parts = explode('_', (string)$this->request->get['path']);
|
||||
|
||||
if(!empty($parts) && is_array($parts)) {
|
||||
|
||||
$filter_data = array(
|
||||
'category_id' => array_pop($parts),
|
||||
'limit' => $setting['limit']
|
||||
);
|
||||
|
||||
$results = $this->model_catalog_cms->getProductRelatedByCategory($filter_data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->language('extension/module/featured_product');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['products'] = array();
|
||||
|
||||
if (!empty($results)) {
|
||||
|
||||
foreach ($results as $product) {
|
||||
|
||||
if ($product) {
|
||||
if ($product['image']) {
|
||||
$image = $this->model_tool_image->resize($product['image'], $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;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$rating = $product['rating'];
|
||||
} else {
|
||||
$rating = false;
|
||||
}
|
||||
|
||||
|
||||
$data['products'][] = array(
|
||||
'product_id' => $product['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $product['name'],
|
||||
'description' => utf8_substr(strip_tags(html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'rating' => $rating,
|
||||
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/featured_product', $data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleFilter extends Controller {
|
||||
public function index() {
|
||||
if (isset($this->request->get['path'])) {
|
||||
$parts = explode('_', (string)$this->request->get['path']);
|
||||
} else {
|
||||
$parts = array();
|
||||
}
|
||||
|
||||
$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/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', 'path=' . $this->request->get['path'] . $url));
|
||||
|
||||
if (isset($this->request->get['filter'])) {
|
||||
$data['filter_category'] = explode(',', $this->request->get['filter']);
|
||||
} else {
|
||||
$data['filter_category'] = array();
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$data['filter_groups'] = array();
|
||||
|
||||
$filter_groups = $this->model_catalog_category->getCategoryFilters($category_id);
|
||||
|
||||
if ($filter_groups) {
|
||||
foreach ($filter_groups as $filter_group) {
|
||||
$childen_data = array();
|
||||
|
||||
foreach ($filter_group['filter'] as $filter) {
|
||||
$filter_data = array(
|
||||
'filter_category_id' => $category_id,
|
||||
'filter_filter' => $filter['filter_id']
|
||||
);
|
||||
|
||||
$childen_data[] = array(
|
||||
'filter_id' => $filter['filter_id'],
|
||||
'name' => $filter['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : '')
|
||||
);
|
||||
}
|
||||
|
||||
$data['filter_groups'][] = array(
|
||||
'filter_group_id' => $filter_group['filter_group_id'],
|
||||
'name' => $filter_group['name'],
|
||||
'filter' => $childen_data
|
||||
);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/filter', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleHTML extends Controller {
|
||||
public function index($setting) {
|
||||
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/module/html', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleInformation extends Controller {
|
||||
public function index() {
|
||||
$this->load->language('extension/module/information');
|
||||
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
$data['informations'] = array();
|
||||
|
||||
foreach ($this->model_catalog_information->getInformations() as $result) {
|
||||
$data['informations'][] = array(
|
||||
'title' => $result['title'],
|
||||
'href' => $this->url->link('information/information', 'information_id=' . $result['information_id'])
|
||||
);
|
||||
}
|
||||
|
||||
$data['contact'] = $this->url->link('information/contact');
|
||||
$data['sitemap'] = $this->url->link('information/sitemap');
|
||||
|
||||
return $this->load->view('extension/module/information', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleLatest extends Controller {
|
||||
public function index($setting) {
|
||||
$this->load->language('extension/module/latest');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['products'] = array();
|
||||
$data['module_name'] = $setting['name'];
|
||||
|
||||
$results = $this->model_catalog_product->getLatestProducts($setting['limit']);
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['image']) {
|
||||
$image = $this->model_tool_image->resize($result['image'], $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 (!is_null($result['special']) && (float)$result['special'] >= 0) {
|
||||
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$tax_price = (float)$result['special'];
|
||||
} else {
|
||||
$special = false;
|
||||
$tax_price = (float)$result['price'];
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format($tax_price, $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$rating = $result['rating'];
|
||||
} else {
|
||||
$rating = false;
|
||||
}
|
||||
|
||||
$results = $this->model_catalog_product->getProductImages($product_id);
|
||||
if($results){
|
||||
$additional_image = $this->model_tool_image->resize($results[0]['image'], $setting['width'], $setting['height']);
|
||||
} else {
|
||||
$additional_image = false;
|
||||
}
|
||||
$data['products'][] = array(
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'additional_thumb' => $additional_image,
|
||||
'price_n' => $product_info['price'],
|
||||
'price_2' => $this->currency->format($this->tax->calculate($product_info['price_2'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'price_2_n' => $product_info['price_2'],
|
||||
'price_3' => $this->currency->format($this->tax->calculate($product_info['price_3'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'price_3_n' => $product_info['price_3'],
|
||||
'min_price' => $this->currency->format($this->tax->calculate(min([$product_info['price'],$product_info['price_2']]), $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
|
||||
'name' => $result['name'],
|
||||
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'rating' => $rating,
|
||||
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
|
||||
);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/latest', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleSlideshow extends Controller {
|
||||
public function index($setting) {
|
||||
static $module = 0;
|
||||
|
||||
$this->load->model('design/banner');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$this->document->addStyle('store/view/javascript/jquery/swiper/css/swiper.min.css');
|
||||
$this->document->addStyle('store/view/javascript/jquery/swiper/css/opencart.css');
|
||||
$this->document->addScript('store/view/javascript/jquery/swiper/js/swiper.jquery.js');
|
||||
|
||||
$data['banners'] = array();
|
||||
|
||||
$results = $this->model_design_banner->getBanner($setting['banner_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . $result['image'])) {
|
||||
$data['banners'][] = array(
|
||||
'title' => $result['title'],
|
||||
'link' => $result['link'],
|
||||
'image' => $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$data['module'] = $module++;
|
||||
|
||||
return $this->load->view('extension/module/slideshow', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleSpecial extends Controller {
|
||||
public function index($setting) {
|
||||
$this->load->language('extension/module/special');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['products'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => 'pd.name',
|
||||
'order' => 'ASC',
|
||||
'start' => 0,
|
||||
'limit' => $setting['limit']
|
||||
);
|
||||
|
||||
$results = $this->model_catalog_product->getProductSpecials($filter_data);
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
if ($result['image']) {
|
||||
$image = $this->model_tool_image->resize($result['image'], $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 (!is_null($result['special']) && (float)$result['special'] >= 0) {
|
||||
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
|
||||
$tax_price = (float)$result['special'];
|
||||
} else {
|
||||
$special = false;
|
||||
$tax_price = (float)$result['price'];
|
||||
}
|
||||
|
||||
if ($this->config->get('config_tax')) {
|
||||
$tax = $this->currency->format($tax_price, $this->session->data['currency']);
|
||||
} else {
|
||||
$tax = false;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_review_status')) {
|
||||
$rating = $result['rating'];
|
||||
} else {
|
||||
$rating = false;
|
||||
}
|
||||
|
||||
$data['products'][] = array(
|
||||
'product_id' => $result['product_id'],
|
||||
'thumb' => $image,
|
||||
'name' => $result['name'],
|
||||
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
|
||||
'price' => $price,
|
||||
'special' => $special,
|
||||
'tax' => $tax,
|
||||
'rating' => $rating,
|
||||
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
|
||||
);
|
||||
}
|
||||
|
||||
return $this->load->view('extension/module/special', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleStore extends Controller {
|
||||
public function index() {
|
||||
$status = true;
|
||||
|
||||
if ($this->config->get('module_store_admin')) {
|
||||
$this->user = new Cart\User($this->registry);
|
||||
|
||||
$status = $this->user->isLogged();
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$this->load->language('extension/module/store');
|
||||
|
||||
$data['store_id'] = $this->config->get('config_store_id');
|
||||
|
||||
$data['stores'] = array();
|
||||
|
||||
$data['stores'][] = array(
|
||||
'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'][] = array(
|
||||
'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/module/store', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleSubcategory extends Controller {
|
||||
public function index($setting) {
|
||||
static $module = 0;
|
||||
$lang_id = $this->config->get('config_language_id');
|
||||
$this->load->model('tool/image');
|
||||
|
||||
|
||||
$data['random'] = token(32);
|
||||
$data['module_name'] = $setting['name'];
|
||||
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$data['categories'] = [];
|
||||
|
||||
foreach($setting['category_ids'] as $category_id){
|
||||
$category_info = $this->model_catalog_category->getCategory($category_id);
|
||||
if($category_info){
|
||||
|
||||
$category_info['href'] = $this->url->link('product/category', 'path=' . $category_info['category_id']);
|
||||
|
||||
$category_info['thumb'] = $this->model_tool_image->resize($category_info['image'] ? $category_info['image'] : 'placeholder.png', $setting['sizes']['desktop']['width'], $setting['sizes']['desktop']['height']);
|
||||
|
||||
|
||||
$data['categories'][] = $category_info;
|
||||
}
|
||||
}
|
||||
|
||||
$data['sizes'] = $setting['sizes']['desktop'];
|
||||
|
||||
$data['module'] = $module++;
|
||||
if($data['categories']){
|
||||
|
||||
$this->document->addStyle('store/view/theme/dominik/assets/css/swiper-bundle.min.css');
|
||||
$this->document->addScript('store/view/theme/dominik/assets/js/swiper-bundle.js');
|
||||
|
||||
return $this->load->view('extension/module/subcategory', $data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
class ControllerExtensionModuleWDBanners extends Controller {
|
||||
public function index($setting) {
|
||||
static $module = 0;
|
||||
|
||||
$this->load->model('tool/image');
|
||||
$this->load->model('design/banner');
|
||||
|
||||
if (isset($setting['include'])) {
|
||||
|
||||
$includes = explode("\r\n", $setting['include']);
|
||||
|
||||
foreach ($includes as $include) {
|
||||
$include = trim($include, "/");
|
||||
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $include)) {
|
||||
$path_parts = pathinfo($_SERVER['DOCUMENT_ROOT'] . '/' . $include);
|
||||
switch ($path_parts['extension']) {
|
||||
case "css":
|
||||
$this->document->addStyle($include);
|
||||
break;
|
||||
case "js":
|
||||
$this->document->addScript($include);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['random'] = token(32);
|
||||
$data['title'] = isset($setting['hide']) ? $setting['name'] : false;
|
||||
|
||||
$data['sizes'] = $setting['sizes'];
|
||||
|
||||
$data['favicon'] = $this->model_tool_image->resize($this->config->get("config_icon"), 114, 114, true);
|
||||
|
||||
$data['banners'] = array();
|
||||
|
||||
if (!empty($setting['banner_id'])) {
|
||||
$results = $this->model_design_banner->getBanner($setting['banner_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (is_file(DIR_IMAGE . $result['image'])) {
|
||||
$data['banners'][] = array(
|
||||
'image' => $this->model_tool_image->resize($result['image'], $setting['sizes']['desktop']['width'], $setting['sizes']['desktop']['height']),
|
||||
'image_mob' => $result['image_mobile'] && is_file(DIR_IMAGE . $result['image_mobile']) ? $this->model_tool_image->resize($result['image_mobile'], $setting['sizes']['mob']['width'], $setting['sizes']['mob']['height']) : '',
|
||||
'image_orig' => HTTPS_SERVER . 'image/' . $result['image'],
|
||||
'title' => html_entity_decode($result['title'], ENT_QUOTES, 'UTF-8'),
|
||||
'text' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
|
||||
'link' => $result['link'],
|
||||
'button' => $result['button_text'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['module'] = $module++;
|
||||
|
||||
return $this->load->view('extension/module/' . ((isset($setting['twig']) && $setting['twig'] != "") ? trim($setting['twig']) : "wd_banners"), $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
class ControllerExtensionPaymentCod extends Controller {
|
||||
public function index() {
|
||||
return $this->load->view('extension/payment/cod');
|
||||
}
|
||||
|
||||
public function confirm() {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->session->data['payment_method']['code']) && $this->session->data['payment_method']['code'] == 'cod') {
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_cod_order_status_id'));
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
class ControllerExtensionTotalCoupon extends Controller {
|
||||
public function index() {
|
||||
if ($this->config->get('total_coupon_status')) {
|
||||
$this->load->language('extension/total/coupon');
|
||||
|
||||
if (isset($this->session->data['coupon'])) {
|
||||
$data['coupon'] = $this->session->data['coupon'];
|
||||
} else {
|
||||
$data['coupon'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/total/coupon', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function coupon() {
|
||||
$this->load->language('extension/total/coupon');
|
||||
|
||||
$json = array();
|
||||
|
||||
$this->load->model('extension/total/coupon');
|
||||
|
||||
if (isset($this->request->post['coupon'])) {
|
||||
$coupon = $this->request->post['coupon'];
|
||||
} else {
|
||||
$coupon = '';
|
||||
}
|
||||
|
||||
$coupon_info = $this->model_extension_total_coupon->getCoupon($coupon);
|
||||
|
||||
if (empty($this->request->post['coupon'])) {
|
||||
$json['error'] = $this->language->get('error_empty');
|
||||
|
||||
unset($this->session->data['coupon']);
|
||||
} elseif ($coupon_info) {
|
||||
$this->session->data['coupon'] = $this->request->post['coupon'];
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/cart');
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_coupon');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
class ControllerExtensionTotalReward extends Controller {
|
||||
public function index() {
|
||||
$points = $this->customer->getRewardPoints();
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($points && $points_total && $this->config->get('total_reward_status')) {
|
||||
$this->load->language('extension/total/reward');
|
||||
|
||||
$data['heading_title'] = sprintf($this->language->get('heading_title'), $points);
|
||||
|
||||
$data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total);
|
||||
|
||||
if (isset($this->session->data['reward'])) {
|
||||
$data['reward'] = $this->session->data['reward'];
|
||||
} else {
|
||||
$data['reward'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/total/reward', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function reward() {
|
||||
$this->load->language('extension/total/reward');
|
||||
|
||||
$json = array();
|
||||
|
||||
$points = $this->customer->getRewardPoints();
|
||||
|
||||
$points_total = 0;
|
||||
|
||||
foreach ($this->cart->getProducts() as $product) {
|
||||
if ($product['points']) {
|
||||
$points_total += $product['points'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->request->post['reward']) || !is_numeric($this->request->post['reward']) || ($this->request->post['reward'] <= 0)) {
|
||||
$json['error'] = $this->language->get('error_reward');
|
||||
}
|
||||
|
||||
if ($this->request->post['reward'] > $points) {
|
||||
$json['error'] = sprintf($this->language->get('error_points'), $this->request->post['reward']);
|
||||
}
|
||||
|
||||
if ($this->request->post['reward'] > $points_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_maximum'), $points_total);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['reward'] = abs($this->request->post['reward']);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
if (isset($this->request->post['redirect'])) {
|
||||
$json['redirect'] = $this->url->link($this->request->post['redirect']);
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('checkout/cart');
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
class ControllerExtensionTotalShipping extends Controller {
|
||||
public function index() {
|
||||
if ($this->config->get('total_shipping_status') && $this->config->get('total_shipping_estimator') && $this->cart->hasShipping()) {
|
||||
$this->load->language('extension/total/shipping');
|
||||
|
||||
if (isset($this->session->data['shipping_address']['country_id'])) {
|
||||
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
|
||||
} else {
|
||||
$data['country_id'] = $this->config->get('config_country_id');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
if (isset($this->session->data['shipping_address']['zone_id'])) {
|
||||
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
|
||||
} else {
|
||||
$data['zone_id'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['shipping_address']['postcode'])) {
|
||||
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
|
||||
} else {
|
||||
$data['postcode'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['shipping_method'])) {
|
||||
$data['shipping_method'] = $this->session->data['shipping_method']['code'];
|
||||
} else {
|
||||
$data['shipping_method'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/total/shipping', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function quote() {
|
||||
$this->load->language('extension/total/shipping');
|
||||
|
||||
$json = array();
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
if ($this->request->post['country_id'] == '') {
|
||||
$json['error']['country'] = $this->language->get('error_country');
|
||||
}
|
||||
|
||||
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '' || !is_numeric($this->request->post['zone_id'])) {
|
||||
$json['error']['zone'] = $this->language->get('error_zone');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
|
||||
|
||||
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
|
||||
$json['error']['postcode'] = $this->language->get('error_postcode');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->tax->setShippingAddress($this->request->post['country_id'], $this->request->post['zone_id']);
|
||||
|
||||
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'] = array(
|
||||
'firstname' => '',
|
||||
'lastname' => '',
|
||||
'company' => '',
|
||||
'address_1' => '',
|
||||
'address_2' => '',
|
||||
'postcode' => $this->request->post['postcode'],
|
||||
'city' => '',
|
||||
'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,
|
||||
'address_format' => $address_format
|
||||
);
|
||||
|
||||
$quote_data = array();
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getExtensions('shipping');
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($this->config->get('shipping_' . $result['code'] . '_status')) {
|
||||
if (!is_file(DIR_APPLICATION . 'model/extension/shipping/' . $result['code'] . '.php')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->load->model('extension/shipping/' . $result['code']);
|
||||
|
||||
$quote = $this->{'model_extension_shipping_' . $result['code']}->getQuote($this->session->data['shipping_address']);
|
||||
|
||||
if ($quote) {
|
||||
$quote_data[$result['code']] = array(
|
||||
'title' => $quote['title'],
|
||||
'quote' => $quote['quote'],
|
||||
'sort_order' => $quote['sort_order'],
|
||||
'error' => $quote['error']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($quote_data as $key => $value) {
|
||||
$sort_order[$key] = $value['sort_order'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $quote_data);
|
||||
|
||||
$this->session->data['shipping_methods'] = $quote_data;
|
||||
|
||||
if ($this->session->data['shipping_methods']) {
|
||||
$json['shipping_method'] = $this->session->data['shipping_methods'];
|
||||
} else {
|
||||
$json['error']['warning'] = sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function shipping() {
|
||||
$this->load->language('extension/total/shipping');
|
||||
|
||||
$json = array();
|
||||
|
||||
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['warning'] = $this->language->get('error_shipping');
|
||||
}
|
||||
} else {
|
||||
$json['warning'] = $this->language->get('error_shipping');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$shipping = explode('.', $this->request->post['shipping_method']);
|
||||
|
||||
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/cart');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function country() {
|
||||
$json = array();
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
|
||||
|
||||
if ($country_info) {
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$json = array(
|
||||
'country_id' => $country_info['country_id'],
|
||||
'name' => $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'],
|
||||
'postcode_required' => $country_info['postcode_required'],
|
||||
'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
|
||||
'status' => $country_info['status']
|
||||
);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
class ControllerExtensionTotalVoucher extends Controller {
|
||||
public function index() {
|
||||
if ($this->config->get('total_voucher_status')) {
|
||||
$this->load->language('extension/total/voucher');
|
||||
|
||||
if (isset($this->session->data['voucher'])) {
|
||||
$data['voucher'] = $this->session->data['voucher'];
|
||||
} else {
|
||||
$data['voucher'] = '';
|
||||
}
|
||||
|
||||
return $this->load->view('extension/total/voucher', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function voucher() {
|
||||
$this->load->language('extension/total/voucher');
|
||||
|
||||
$json = array();
|
||||
|
||||
$this->load->model('extension/total/voucher');
|
||||
|
||||
if (isset($this->request->post['voucher'])) {
|
||||
$voucher = $this->request->post['voucher'];
|
||||
} else {
|
||||
$voucher = '';
|
||||
}
|
||||
|
||||
$voucher_info = $this->model_extension_total_voucher->getVoucher($voucher);
|
||||
|
||||
if (empty($this->request->post['voucher'])) {
|
||||
$json['error'] = $this->language->get('error_empty');
|
||||
} elseif ($voucher_info) {
|
||||
$this->session->data['voucher'] = $this->request->post['voucher'];
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['redirect'] = $this->url->link('checkout/cart');
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_voucher');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function send($route, $args, $output) {
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$order_info = $this->model_checkout_order->getOrder($args[0]);
|
||||
|
||||
// If order status in the complete range create any vouchers that where in the order need to be made available.
|
||||
if (in_array($order_info['order_status_id'], $this->config->get('config_complete_status'))) {
|
||||
$voucher_query = $this->db->query("SELECT *, vtd.name AS theme FROM `" . DB_PREFIX . "voucher` v LEFT JOIN " . DB_PREFIX . "voucher_theme vt ON (v.voucher_theme_id = vt.voucher_theme_id) LEFT JOIN " . DB_PREFIX . "voucher_theme_description vtd ON (vt.voucher_theme_id = vtd.voucher_theme_id) WHERE v.order_id = '" . (int)$order_info['order_id'] . "' AND vtd.language_id = '" . (int)$order_info['language_id'] . "'");
|
||||
|
||||
if ($voucher_query->num_rows) {
|
||||
// Send out any gift voucher mails
|
||||
$language = new Language($order_info['language_code']);
|
||||
$language->load($order_info['language_code']);
|
||||
$language->load('mail/voucher');
|
||||
|
||||
foreach ($voucher_query->rows as $voucher) {
|
||||
// HTML Mail
|
||||
$data = array();
|
||||
|
||||
$data['title'] = sprintf($language->get('text_subject'), $voucher['from_name']);
|
||||
|
||||
$data['text_greeting'] = sprintf($language->get('text_greeting'), $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']));
|
||||
$data['text_from'] = sprintf($language->get('text_from'), $voucher['from_name']);
|
||||
$data['text_message'] = $language->get('text_message');
|
||||
$data['text_redeem'] = sprintf($language->get('text_redeem'), $voucher['code']);
|
||||
$data['text_footer'] = $language->get('text_footer');
|
||||
|
||||
if (is_file(DIR_IMAGE . $voucher['image'])) {
|
||||
$data['image'] = $this->config->get('config_url') . 'image/' . $voucher['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$data['store_name'] = $order_info['store_name'];
|
||||
$data['store_url'] = $order_info['store_url'];
|
||||
$data['message'] = nl2br($voucher['message']);
|
||||
|
||||
$mail = new Mail($this->config->get('config_mail_engine'));
|
||||
$mail->parameter = $this->config->get('config_mail_parameter');
|
||||
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
|
||||
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
|
||||
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
|
||||
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
|
||||
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
|
||||
|
||||
$mail->setTo($voucher['to_email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setSubject(html_entity_decode(sprintf($language->get('text_subject'), $voucher['from_name']), ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setHtml($this->load->view('mail/voucher', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user