2405 lines
99 KiB
PHP
2405 lines
99 KiB
PHP
<?php
|
|
/**
|
|
* Copyright ETS Software Technology Co., Ltd
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This file is not open source! Each license that you purchased is only available for 1 website only.
|
|
* If you want to use this file on more websites (or projects), you need to purchase additional licenses.
|
|
* You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
* versions in the future.
|
|
*
|
|
* @author ETS Software Technology Co., Ltd
|
|
* @copyright ETS Software Technology Co., Ltd
|
|
* @license Valid for 1 website (or project) for each purchase of license
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
require_once(dirname(__FILE__) . '/classes/ets_pr_defines.php');
|
|
require_once(dirname(__FILE__) . '/classes/Ets_pr_obj.php');
|
|
require_once(dirname(__FILE__) . '/classes/ets_pr_rule.php');
|
|
require_once(dirname(__FILE__) . '/classes/ets_pr_condition_rule.php');
|
|
require_once(dirname(__FILE__) . '/classes/ets_pr_action_rule.php');
|
|
require_once(dirname(__FILE__) . '/classes/ets_pr_promote_rule.php');
|
|
require_once(dirname(__FILE__) . '/classes/ets_pr_paggination_class.php');
|
|
if (!defined('_PS_ETS_PR_IMG_DIR_')) {
|
|
define('_PS_ETS_PR_IMG_DIR_', _PS_IMG_DIR_.'ets_promotion/');
|
|
}
|
|
if (!defined('_PS_ETS_PR_IMG_')) {
|
|
define('_PS_ETS_PR_IMG_', _PS_IMG_.'ets_promotion/');
|
|
}
|
|
if (!defined('_PS_ETS_PROMOTION_LOG_DIR_')) {
|
|
if (file_exists(_PS_ROOT_DIR_ . '/var/logs')) {
|
|
define('_PS_ETS_PROMOTION_LOG_DIR_', _PS_ROOT_DIR_ . '/var/logs/');
|
|
} else
|
|
define('_PS_ETS_PROMOTION_LOG_DIR_', _PS_ROOT_DIR_ . '/log/');
|
|
}
|
|
class Ets_promotion extends Module
|
|
{
|
|
public $is17 = false;
|
|
public $hooks = array(
|
|
'displayBackOfficeHeader',
|
|
'displayHeader',
|
|
'displayBanner',
|
|
'actionObjectCartRuleDeleteAfter',
|
|
'displayOverrideTemplate',
|
|
'displayCustomDiscountRule',
|
|
'actionValidateOrder',
|
|
'actionEmailSendBefore',
|
|
'displayShoppingCartFooter',
|
|
);
|
|
public $html;
|
|
public static $trans;
|
|
public $_errors = array();
|
|
public function __construct()
|
|
{
|
|
$this->name = 'ets_promotion';
|
|
$this->tab = 'merchandizing';
|
|
$this->version = '1.1.9';
|
|
$this->author = 'PrestaHero';
|
|
$this->need_instance = 0;
|
|
$this->bootstrap = true;
|
|
parent::__construct();
|
|
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
|
|
$this->module_dir = $this->_path;
|
|
$this->displayName = $this->l('Promotion Pro: Auto discounts, free ship, gifts, etc.');
|
|
$this->description = $this->l('Create auto promotion campaign: Buy X get Y, free ship over $500, 20% OFF if buy from 3 items, etc. Grow sales and attract customers using targeted offers with flexible discounts rules.');
|
|
$this->module_key = 'd70c9fddfff88403bea8ecd6436f5fcc';
|
|
if(version_compare(_PS_VERSION_, '1.7', '>='))
|
|
$this->is17 = true;
|
|
$this->translates();
|
|
|
|
}
|
|
public function translates()
|
|
{
|
|
self::$trans = array(
|
|
'Free_text' => $this->l('Free'),
|
|
'Free_shipping_text' => $this->l('Free shipping'),
|
|
);
|
|
}
|
|
public function getTabs()
|
|
{
|
|
return array(
|
|
array(
|
|
'class' => 'AdminPromotionRule',
|
|
'icon' => 'icon-rule',
|
|
'active' => 1,
|
|
'name' => $this->l('Discount rules'),
|
|
'name_lang' =>'Discount rules'
|
|
),
|
|
);
|
|
}
|
|
public function _installTab()
|
|
{
|
|
if ($parentId = Tab::getIdFromClassName('AdminCatalog')) {
|
|
$languages = Language::getLanguages(false);
|
|
$tabs = $this->getTabs();
|
|
foreach($tabs as $tab)
|
|
{
|
|
$tabObj = new Tab();
|
|
$tabObj->id_parent = (int)$parentId;
|
|
$tabObj->class_name = $tab['class'];
|
|
$tabObj->icon = $tab['icon'];
|
|
$tabObj->module = $this->name;
|
|
$tabObj->active=(int)$tab['active'];
|
|
$tabObj->position = 6;
|
|
foreach ($languages as $l) {
|
|
$tabObj->name[$l['id_lang']] = $this->getTextLang($tab['name_lang'],$l) ?: $tab['name'];
|
|
}
|
|
if (!Tab::getIdFromClassName($tabObj->class_name))
|
|
$tabObj->add();
|
|
}
|
|
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'tab` SET `position` = "7" WHERE class_name="AdminPromotionRule"');
|
|
}
|
|
return true;
|
|
}
|
|
public function _unInstallTab()
|
|
{
|
|
$tabs = $this->getTabs();
|
|
foreach($tabs as $tab)
|
|
{
|
|
if ($id = Tab::getIdFromClassName($tab['class'])) {
|
|
$tabobj = new Tab((int)$id);
|
|
$tabobj->delete();
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
public function install()
|
|
{
|
|
return parent::install() && $this->installHooks() && $this->installDefaultConfig() && $this->installDb()&& $this->_installTab();
|
|
}
|
|
public function unInstall()
|
|
{
|
|
return parent::unInstall() && $this->unInstallHooks()&& $this->unInstallDefaultConfig()&& $this->unInstallDb() && $this->_unInstallTab() && $this->rrmdir(_PS_ETS_PR_IMG_DIR_);
|
|
}
|
|
public function installDb()
|
|
{
|
|
return Ets_pr_defines::getInstance()->installDb();
|
|
}
|
|
public function unInstallDb()
|
|
{
|
|
return Ets_pr_defines::getInstance()->unInstallDb();
|
|
}
|
|
public function installHooks()
|
|
{
|
|
foreach($this->hooks as $hook)
|
|
{
|
|
$this->registerHook($hook);
|
|
}
|
|
$position_hooks = Ets_pr_promote_rule::getInstance()->getPositions();
|
|
foreach(array_keys($position_hooks) as $position_hook)
|
|
{
|
|
$this->registerHook($position_hook);
|
|
}
|
|
return true;
|
|
}
|
|
public function unInstallHooks()
|
|
{
|
|
foreach($this->hooks as $hook)
|
|
{
|
|
$this->unRegisterHook($hook);
|
|
}
|
|
$position_hooks = Ets_pr_promote_rule::getInstance()->getPositions();
|
|
foreach(array_keys($position_hooks) as $position_hook)
|
|
{
|
|
$this->unRegisterHook($position_hook);
|
|
}
|
|
return true;
|
|
}
|
|
public function installDefaultConfig(){
|
|
$inputs = Ets_pr_defines::getInstance()->getConfigInputs();
|
|
$languages = Language::getLanguages(false);
|
|
if($inputs)
|
|
{
|
|
foreach($inputs as $input)
|
|
{
|
|
if(isset($input['default']) && $input['default'])
|
|
{
|
|
if(isset($input['lang']) && $input['lang'])
|
|
{
|
|
$values = array();
|
|
foreach($languages as $language)
|
|
{
|
|
$values[$language['id_lang']] = isset($input['default_lang']) && $input['default_lang'] ? $this->getTextLang($input['default_lang'],$language) : $input['default'];
|
|
}
|
|
Configuration::updateGlobalValue($input['name'],$values);
|
|
}
|
|
else
|
|
Configuration::updateGlobalValue($input['name'],$input['default']);
|
|
}
|
|
}
|
|
}
|
|
if(file_exists(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log'))
|
|
@unlink(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log');
|
|
$this->context->cookie->pr_closed_popups ='';
|
|
$this->context->cookie->pr_closed_highlightbars ='';
|
|
$this->context->cookie->write();
|
|
return true;
|
|
}
|
|
public function unInstallDefaultConfig(){
|
|
$inputs = Ets_pr_defines::getInstance()->getConfigInputs();
|
|
if($inputs)
|
|
{
|
|
foreach($inputs as $input)
|
|
{
|
|
Configuration::deleteByName($input['name']);
|
|
}
|
|
}
|
|
if(file_exists(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log'))
|
|
@unlink(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log');
|
|
$this->context->cookie->pr_closed_popups ='';
|
|
$this->context->cookie->pr_closed_highlightbars ='';
|
|
$this->context->cookie->write();
|
|
return true;
|
|
}
|
|
public function rrmdir($dir) {
|
|
$dir = rtrim($dir,'/');
|
|
if ($dir && is_dir($dir)) {
|
|
if($objects = scandir($dir))
|
|
{
|
|
foreach ($objects as $object) {
|
|
if ($object != "." && $object != "..") {
|
|
if (is_dir($dir."/".$object) && !is_link($dir."/".$object))
|
|
$this->rrmdir($dir."/".$object);
|
|
else
|
|
@unlink($dir."/".$object);
|
|
}
|
|
}
|
|
}
|
|
rmdir($dir);
|
|
}
|
|
return true;
|
|
}
|
|
public function getTextLang($text, $lang,$file_name='')
|
|
{
|
|
if(is_array($lang))
|
|
$iso_code = $lang['iso_code'];
|
|
elseif(is_object($lang))
|
|
$iso_code = $lang->iso_code;
|
|
else
|
|
{
|
|
$language = new Language($lang);
|
|
$iso_code = $language->iso_code;
|
|
}
|
|
$modulePath = rtrim(_PS_MODULE_DIR_, '/').'/'.$this->name;
|
|
$fileTransDir = $modulePath.'/translations/'.$iso_code.'.'.'php';
|
|
if(!@file_exists($fileTransDir)){
|
|
return $text;
|
|
}
|
|
$fileContent = Tools::file_get_contents($fileTransDir);
|
|
$text_tras = preg_replace("/\\\*'/", "\'", $text);
|
|
$strMd5 = md5($text_tras);
|
|
$keyMd5 = '<{' . $this->name . '}prestashop>' . ($file_name ? : $this->name) . '_' . $strMd5;
|
|
preg_match('/(\$_MODULE\[\'' . preg_quote($keyMd5) . '\'\]\s*=\s*\')(.*)(\';)/', $fileContent, $matches);
|
|
if($matches && isset($matches[2])){
|
|
return $matches[2];
|
|
}
|
|
return $text;
|
|
}
|
|
protected function getEmailTemplateContent($template_name, $mail_type, $var)
|
|
{
|
|
$email_configuration = Configuration::get('PS_MAIL_TYPE');
|
|
if ($email_configuration != $mail_type && $email_configuration != Mail::TYPE_BOTH) {
|
|
return '';
|
|
}
|
|
|
|
$pathToFindEmail = array(
|
|
_PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name,
|
|
_PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . $template_name,
|
|
_PS_MAIL_DIR_ . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name,
|
|
_PS_MAIL_DIR_ . 'en' . DIRECTORY_SEPARATOR . $template_name,
|
|
_PS_MAIL_DIR_ . '_partials' . DIRECTORY_SEPARATOR . $template_name,
|
|
);
|
|
|
|
foreach ($pathToFindEmail as $path) {
|
|
if (Tools::file_exists_cache($path)) {
|
|
$this->context->smarty->assign('list', $var);
|
|
|
|
return $this->context->smarty->fetch($path);
|
|
}
|
|
}
|
|
|
|
return '';
|
|
}
|
|
public function hookActionEmailSendBefore($params)
|
|
{
|
|
if (isset($this->context->cart->id)) {
|
|
$id_order = Order::getIdByCartId($this->context->cart->id);
|
|
if ($id_order && ($order = new Order($id_order)) && Validate::isLoadedObject($order) && $params['template'] == 'order_conf') {
|
|
$cart_rules_list = Ets_pr_rule::getOrderCartRules($id_order);
|
|
$cart_rules_list_txt = '';
|
|
$cart_rules_list_html = '';
|
|
if (count($cart_rules_list) > 0) {
|
|
$cart_rules_list_txt = $this->getEmailTemplateContent('order_conf_cart_rules.txt', Mail::TYPE_TEXT, $cart_rules_list);
|
|
$cart_rules_list_html = $this->getEmailTemplateContent('order_conf_cart_rules.tpl', Mail::TYPE_HTML, $cart_rules_list);
|
|
}
|
|
$params['templateVars']['{discounts}'] = $cart_rules_list_html;
|
|
$params['templateVars']['{discounts_txt}'] = $cart_rules_list_txt;
|
|
}
|
|
}
|
|
}
|
|
public function hookActionValidateOrder($params)
|
|
{
|
|
if(isset($params['cart']) && Validate::isLoadedObject($params['cart']) && isset($params['order']) && Validate::isLoadedObject($params['order']) && !Cache::isStored('ets_promotion_hookValidateOrder' . $params['order']->id_cart))
|
|
{
|
|
Cache::store('ets_promotion_hookValidateOrder' . $params['order']->id_cart, true);
|
|
Ets_pr_rule::addToOrder($params['order']);
|
|
}
|
|
}
|
|
public function hookActionObjectCartRuleDeleteAfter()
|
|
{
|
|
if(!Configuration::getGlobalValue('PS_CART_RULE_FEATURE_ACTIVE'))
|
|
{
|
|
Configuration::updateGlobalValue(
|
|
'PS_CART_RULE_FEATURE_ACTIVE',
|
|
CartRule::isCurrentlyUsed('cart_rule', true) && Ets_pr_rule::isCurrentlyUsed('ets_pr_rule', true)
|
|
);
|
|
}
|
|
}
|
|
public function addJquery()
|
|
{
|
|
if (version_compare(_PS_VERSION_, '1.7.6.0', '>=') && version_compare(_PS_VERSION_, '1.7.7.0', '<'))
|
|
$this->context->controller->addJS(_PS_JS_DIR_ . 'jquery/jquery-'._PS_JQUERY_VERSION_.'.min.js');
|
|
else
|
|
$this->context->controller->addJquery();
|
|
}
|
|
|
|
public function hookDisplayBackOfficeHeader()
|
|
{
|
|
$controller = Tools::getValue('controller');
|
|
$configure = Tools::getValue('configure');
|
|
if(($controller=='AdminModules' && $configure== $this->name))
|
|
{
|
|
$this->context->controller->addCSS($this->_path.'views/css/admin.css');
|
|
$this->addJquery();
|
|
$this->context->controller->addJS($this->_path.'views/js/admin.js');
|
|
}
|
|
}
|
|
public function displayText($content=null,$tag='',$class=null,$id=null,$href=null,$blank=false,$src = null,$alt = null, $name = null,$value = null,$type = null,$data_id_product = null,$rel = null,$attr_datas=null, $title = null)
|
|
{
|
|
return Ets_pr_defines::displayText($content, $tag, $class, $id, $href, $blank, $src, $alt, $name, $value, $type, $data_id_product, $rel, $attr_datas, $title);
|
|
// $this->smarty->assign(
|
|
// array(
|
|
// 'tag_content' =>$content,
|
|
// 'tag_name' => $tag,
|
|
// 'tag_class'=> $class,
|
|
// 'tag_id' => $id,
|
|
// 'href' => $href,
|
|
// 'blank' => $blank,
|
|
// 'src' => $src,
|
|
// 'attr_name' => $name,
|
|
// 'value' => $value,
|
|
// 'type' => $type,
|
|
// 'data_id_product' => $data_id_product,
|
|
// 'attr_datas' => $attr_datas,
|
|
// 'rel' => $rel,
|
|
// )
|
|
// );
|
|
// return $this->display(__FILE__,'html.tpl');
|
|
}
|
|
public function _header()
|
|
{
|
|
if ($this->context->controller->php_self == 'category') {
|
|
$this->smarty->assign(array(
|
|
'hookDisplayProductListHeaderAfter' => $this->hookDisplayProductListHeaderAfter(),
|
|
'hookDisplayProductListHeaderBefore' => $this->hookDisplayProductListHeaderBefore(),
|
|
));
|
|
}
|
|
if ($this->context->controller->php_self == 'product') {
|
|
$this->smarty->assign(array(
|
|
'hookDisplayProductVariantsBefore' => $this->hookDisplayProductVariantsBefore(),
|
|
'hookDisplayProductVariantsAfter' => $this->hookDisplayProductVariantsAfter(),
|
|
'hookDisplayProductCommentsListHeaderBefore' => $this->hookDisplayProductCommentsListHeaderBefore(),
|
|
));
|
|
}
|
|
if ($this->context->controller->php_self == 'cart') {
|
|
$this->smarty->assign(array(
|
|
'hookDisplayCartGridBodyBefore1' => $this->hookDisplayCartGridBodyBefore1(),
|
|
));
|
|
}
|
|
if ($this->context->controller->php_self == 'order') {
|
|
$this->smarty->assign(array(
|
|
'hookDisplayCartGridBodyBefore1' => $this->hookDisplayCartGridBodyBefore1(),
|
|
'hookDisplayCartGridBodyBefore2' => $this->hookDisplayCartGridBodyBefore2(),
|
|
'hookDisplayCartGridBodyAfter' => $this->hookDisplayCartGridBodyAfter(),
|
|
));
|
|
}
|
|
$this->smarty->assign(array(
|
|
'hookDisplayLeftColumnBefore' => $this->hookDisplayLeftColumnBefore(),
|
|
'hookDisplayRightColumnBefore' => $this->hookDisplayRightColumnBefore(),
|
|
));
|
|
return $this->display(__FILE__, 'render-js.tpl');
|
|
}
|
|
public function hookDisplayHeader()
|
|
{
|
|
$this->context->controller->addCSS($this->_path.'views/css/front.css');
|
|
$this->context->controller->addJS($this->_path.'views/js/front.js');
|
|
$this->context->controller->addJS($this->_path.'views/js/jquery.countdown.min.js');
|
|
$this->context->controller->addJS($this->_path.'views/js/clock.js');
|
|
$controller = Tools::getValue('controller');
|
|
$header = '';
|
|
if($controller=='order' && Ets_pr_rule::checkConditionPaymentExit())
|
|
{
|
|
$this->context->controller->addJS($this->_path.'views/js/order.js');
|
|
if (!$this->isCached('header.tpl', $this->_getCacheId(['header']))) {
|
|
$this->smarty->assign(
|
|
array(
|
|
'ets_pr_link_ajax_change_payment' => $this->context->link->getModuleLink($this->name,'ajax'),
|
|
)
|
|
);
|
|
}
|
|
$header .= $this->display(__FILE__,'header.tpl', $this->_getCacheId(['header']));
|
|
}
|
|
$header .= $this->_header();
|
|
return $header;
|
|
}
|
|
public function hookDisplayShoppingCartFooter()
|
|
{
|
|
return $this->displayListGiftProducts().$this->displayPromoteDiscountRule('displayShoppingCartFooter');
|
|
}
|
|
public function hookDisplayProductAdditionalInfo()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayProductAdditionalInfo');
|
|
}
|
|
public function hookDisplayBanner()
|
|
{
|
|
return $this->displayPromoteDiscountRule(false,'display_highlight_bar').$this->displayPromoteDiscountRule(false,'display_popup');
|
|
}
|
|
public function hookDisplayHome()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayHome');
|
|
}
|
|
public function hookDisplayLeftColumn()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayLeftColumn');
|
|
}
|
|
public function hookDisplayLeftColumnBefore()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayBeforeLeftColumn');
|
|
}
|
|
public function hookDisplayRightColumnBefore()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayBeforeRightColumn');
|
|
}
|
|
public function hookDisplayRightColumn()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayRightColumn');
|
|
}
|
|
public function hookDisplayCartGridBodyBefore2()
|
|
{
|
|
//custom hook
|
|
return $this->displayPromoteDiscountRule('displayCartGridBodyBefore2');
|
|
}
|
|
public function hookDisplayCartGridBodyAfter()
|
|
{
|
|
//custom hook
|
|
return $this->displayPromoteDiscountRule('displayCartGridBodyAfter');
|
|
}
|
|
public function hookDisplayProductListHeaderBefore()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayProductListHeaderBefore');
|
|
}
|
|
public function hookDisplayProductListHeaderAfter()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayProductListHeaderAfter');
|
|
}
|
|
public function hookDisplayFooterCategory()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayFooterCategory');
|
|
}
|
|
public function hookDisplayNav1()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayNav1');
|
|
}
|
|
public function hookDisplayFooterBefore()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayFooterBefore');
|
|
}
|
|
public function hookDisplayFooterAfter()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayFooterAfter');
|
|
}
|
|
public function hookDisplayCartGridBodyBefore1()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayCartGridBodyBefore1');
|
|
}
|
|
public function hookDisplayFooterProduct()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayFooterProduct');
|
|
}
|
|
public function hookDisplayProductVariantsBefore()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayProductVariantsBefore');
|
|
}
|
|
public function hookDisplayProductVariantsAfter()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayProductVariantsAfter');
|
|
}
|
|
public function hookDisplayReassurance()
|
|
{
|
|
$controller = Tools::getValue('controller');
|
|
if($controller=='product')
|
|
return $this->displayPromoteDiscountRule('displayReassurance');
|
|
}
|
|
public function hookDisplayAfterProductThumbs()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayAfterProductThumbs');
|
|
}
|
|
public function hookDisplayProductActions()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayProductActions');
|
|
}
|
|
public function hookDisplayProductCommentsListHeaderBefore()
|
|
{
|
|
return $this->displayPromoteDiscountRule('displayProductCommentsListHeaderBefore');
|
|
}
|
|
public function hookDisplayOverrideTemplate($params)
|
|
{
|
|
if (isset($params['template_file']) && $params['template_file'] == 'checkout/cart' && !Module::isEnabled('ets_extraoptions')) {
|
|
return $this->getTemplatePath('checkout/cart.tpl');
|
|
}
|
|
if (isset($params['template_file']) && $params['template_file'] == 'checkout/checkout') {
|
|
$this->context->smarty->assign(
|
|
array(
|
|
'html_gift_products' => $this->displayListGiftProducts(),
|
|
)
|
|
);
|
|
return $this->getTemplatePath('checkout/checkout.tpl');
|
|
}
|
|
}
|
|
public function hookDisplayCustomDiscountRule($params)
|
|
{
|
|
$cache_id = $this->_getCacheId(Tools::isSubmit('ajax') ? ['cart_voucher', 'ajax'] : ['cart_voucher']);
|
|
if (!$this->isCached('cart_voucher.tpl', $cache_id)) {
|
|
$list_gift = Tools::isSubmit('ajax') ? $this->displayListGiftProducts():'';
|
|
$this->smarty->assign(
|
|
array(
|
|
'cartVouchers' => Ets_pr_rule::getCartVouchers(),
|
|
'added' => isset($params['added']) ? $params['added'] : false,
|
|
'list_gift'=> $list_gift,
|
|
)
|
|
);
|
|
}
|
|
return $this->display(__FILE__,'cart_voucher.tpl', $cache_id);
|
|
}
|
|
public function displayPromoteDiscountRule($position='',$way_to_promote='')
|
|
{
|
|
$promoteDiscountRules = Ets_pr_rule::getPromoteDiscountRulesByPosition($position,$way_to_promote);
|
|
$html = '';
|
|
if($this->context->cookie->pr_closed_highlightbars)
|
|
{
|
|
$pr_closed_highlightbars = explode(',',$this->context->cookie->pr_closed_highlightbars);
|
|
}
|
|
else
|
|
$pr_closed_highlightbars = array();
|
|
if($this->context->cookie->pr_closed_popups)
|
|
{
|
|
$pr_closed_popups = explode(',',$this->context->cookie->pr_closed_popups);
|
|
}
|
|
else
|
|
$pr_closed_popups = array();
|
|
$this->smarty->assign(
|
|
array(
|
|
'pr_closed_highlightbars' => $pr_closed_highlightbars,
|
|
'pr_closed_popups' => $pr_closed_popups,
|
|
)
|
|
);
|
|
if($promoteDiscountRules)
|
|
{
|
|
foreach($promoteDiscountRules as $promoteDiscountRule)
|
|
{
|
|
$this->smarty->assign(
|
|
array(
|
|
'promoteDiscountRule' => $promoteDiscountRule,
|
|
)
|
|
);
|
|
$html .= $this->display(__FILE__,'promote_discount_rule.tpl');
|
|
}
|
|
}
|
|
return $html;
|
|
}
|
|
public function runCronJob()
|
|
{
|
|
$ok = false;
|
|
if(Configuration::get('ETS_PR_AUTO_CLEAR_RULE_EXPIRED'))
|
|
{
|
|
if($rule = Ets_pr_rule::deleteRuleExpired())
|
|
{
|
|
$ok = true;
|
|
if(Configuration::getGlobalValue('ETS_PR_SAVE_CRONJOB_LOG'))
|
|
file_put_contents(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log',Tools::displayDate(date('Y-m-d H:i:s'),Configuration::get('PS_LANG_DEFAULT'),true).': '.sprintf($this->l('Deleted %d expired discount codes'),$rule)."\n",FILE_APPEND);
|
|
}
|
|
}
|
|
if(Configuration::get('ETS_PR_AUTO_CLEAR_DISCOUNT_USED'))
|
|
{
|
|
if($rule = (int)Ets_pr_rule::deleteRuleUsed())
|
|
{
|
|
$ok = true;
|
|
if(Configuration::getGlobalValue('ETS_PR_SAVE_CRONJOB_LOG'))
|
|
file_put_contents(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log',Tools::displayDate(date('Y-m-d H:i:s'),Configuration::get('PS_LANG_DEFAULT'),true).': '.sprintf($this->l('Deleted %d used discount codes'),$rule)."\n",FILE_APPEND);
|
|
}
|
|
}
|
|
if(!$ok && Configuration::getGlobalValue('ETS_PR_SAVE_CRONJOB_LOG'))
|
|
file_put_contents(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log',Tools::displayDate(date('Y-m-d H:i:s'),Configuration::get('PS_LANG_DEFAULT'),true).': '.$this->l('Cronjob run but nothing to do')."\n",FILE_APPEND);
|
|
Configuration::updateGlobalValue('ETS_PR_TIME_LOG_CRONJOB',date('Y-m-d H:i:s'));
|
|
if(Tools::isSubmit('ajax'))
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Cronjob done'),
|
|
'cronjob_log' => file_exists(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log') ? Tools::file_get_contents(dirname(__FILE__).'/cronjob_log.txt'):'',
|
|
)
|
|
)
|
|
);
|
|
}
|
|
public function submitUpdateToken()
|
|
{
|
|
$error = '';
|
|
$ETS_PR_CRONJOB_TOKEN = Tools::getValue('ETS_PR_CRONJOB_TOKEN');
|
|
if(!$ETS_PR_CRONJOB_TOKEN)
|
|
$error =$this->l('Token is required');
|
|
elseif(!Validate::isCleanHtml($ETS_PR_CRONJOB_TOKEN))
|
|
$error =$this->l('Token is not valid');
|
|
if(!$error)
|
|
{
|
|
Configuration::updateGlobalValue('ETS_PR_CRONJOB_TOKEN',$ETS_PR_CRONJOB_TOKEN);
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Updated successfully'),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
else
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'errors' => $error,
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
public function submitClearLog()
|
|
{
|
|
if(file_exists(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log'))
|
|
@unlink(_PS_ETS_PROMOTION_LOG_DIR_.'ets_promotion.log');
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Clear log successfully'),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
public function getContent()
|
|
{
|
|
if(!$this->active)
|
|
return $this->displayWarning($this->l('You must enable "Promotion Pro: Auto discounts, free ship, gifts, etc." module to configure its features'));
|
|
if(Tools::isSubmit('btnSubmitSettingsRule'))
|
|
$this->submitSettingsRule();
|
|
if(Tools::isSubmit('etsprSubmitClearLog'))
|
|
$this->submitClearLog();
|
|
if(Tools::isSubmit('submitCronjob'))
|
|
$this->runCronJob();
|
|
if(Tools::isSubmit('etsprSubmitUpdateToken'))
|
|
{
|
|
$this->submitUpdateToken();
|
|
}
|
|
if(Tools::isSubmit('ETS_PR_SAVE_CRONJOB_LOG'))
|
|
{
|
|
$ETS_PR_SAVE_CRONJOB_LOG = (int)Tools::getValue('ETS_PR_SAVE_CRONJOB_LOG') ? 1 :0;
|
|
Configuration::updateGlobalValue('ETS_PR_SAVE_CRONJOB_LOG',$ETS_PR_SAVE_CRONJOB_LOG);
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Updated successfully'),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
if(Tools::isSubmit('change_enabled') &&($id_ets_pr_rule = (int)Tools::getValue('id_ets_pr_rule')))
|
|
{
|
|
$change_enabled = (int)Tools::getValue('change_enabled');
|
|
$rule = new Ets_pr_rule($id_ets_pr_rule);
|
|
$rule->active = $change_enabled;
|
|
if($rule->update())
|
|
{
|
|
$this->context->cookie->_success = $this->l('Updated successfully');
|
|
Tools::redirect($this->context->link->getAdminLink('AdminModules').'&configure=ets_promotion');
|
|
}
|
|
|
|
}
|
|
if(Tools::isSubmit('del') && ($id_ets_pr_rule=(int)Tools::getValue('id_ets_pr_rule')) && ($rule = new Ets_pr_rule($id_ets_pr_rule)) && Validate::isLoadedObject($rule))
|
|
{
|
|
$rule->delete();
|
|
$this->context->cookie->_success = $this->l('Deleted successfully');
|
|
Tools::redirect($this->context->link->getAdminLink('AdminModules').'&configure=ets_promotion');
|
|
}
|
|
if(Tools::isSubmit('delPromote') && ($id_ets_pr_promote_rule = (int)Tools::getValue('id_ets_pr_promote_rule')))
|
|
{
|
|
$promote = new Ets_pr_promote_rule($id_ets_pr_promote_rule);
|
|
if($promote->delete())
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Deleted successfully'),
|
|
'id_ets_pr_promote_rule' => $promote->id,
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
if(Tools::isSubmit('editpromoterule') && ($id_ets_pr_promote_rule = (int)Tools::getValue('id_ets_pr_promote_rule')))
|
|
{
|
|
$promote = new Ets_pr_promote_rule($id_ets_pr_promote_rule);
|
|
if(Tools::isSubmit('ajax'))
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'form_html' => $promote->renderForm(),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
else
|
|
return $promote->renderForm();
|
|
}
|
|
if(Tools::isSubmit('delCondition') && ($id_ets_pr_condition_rule = (int)Tools::getValue('id_ets_pr_condition_rule')))
|
|
{
|
|
$condition = new Ets_pr_condition_rule($id_ets_pr_condition_rule);
|
|
if($condition->delete())
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Deleted successfully'),
|
|
'id_ets_pr_condition_rule' => $condition->id,
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
if(Tools::isSubmit('editconditionrule') && ($id_ets_pr_condition_rule = (int)Tools::getValue('id_ets_pr_condition_rule')))
|
|
{
|
|
$condition = new Ets_pr_condition_rule($id_ets_pr_condition_rule);
|
|
if(Tools::isSubmit('ajax'))
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'form_html' => $condition->renderForm(),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
else
|
|
return $condition->renderForm();
|
|
}
|
|
if(Tools::isSubmit('search_product'))
|
|
{
|
|
Ets_pr_defines::getInstance()->searchProduct();
|
|
}
|
|
if(Tools::isSubmit('search_customer'))
|
|
{
|
|
Ets_pr_defines::getInstance()->searchCustomer();
|
|
}
|
|
if(Tools::isSubmit('getStates'))
|
|
{
|
|
if(($id_country = (int)Tools::getValue('id_country')))
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'list_state' => $this->displayListStates($id_country)
|
|
)
|
|
)
|
|
);
|
|
}
|
|
else
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'list_state' => ''
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|
|
if(Tools::isSubmit('save_action_rule'))
|
|
{
|
|
$this->saveActionRule();
|
|
}
|
|
if(Tools::isSubmit('save_promote_discount_rule'))
|
|
{
|
|
$this->submitSavePromoteRule();
|
|
}
|
|
if(Tools::isSubmit('save_condition_rule'))
|
|
{
|
|
$this->submitSaveConditionRule();
|
|
}
|
|
if(Tools::isSubmit('save_rule'))
|
|
{
|
|
$this->submitSaveRule();
|
|
}
|
|
if($this->context->cookie->_success)
|
|
{
|
|
$this->html .= $this->displayConfirmation($this->context->cookie->_success);
|
|
$this->context->cookie->_success ='';
|
|
}
|
|
$rule_tab = Tools::getValue('rule_tab','discount_rule');
|
|
if(!in_array($rule_tab,array('discount_rule','discount_report','settings')))
|
|
$rule_tab = 'discount_rule';
|
|
$this->smarty->assign(
|
|
array(
|
|
'link' => $this->context->link,
|
|
'rule_tab'=> $rule_tab,
|
|
'discount_rule' => $rule_tab == 'discount_rule' ? $this->renderRule():'',
|
|
'setting_form' => $rule_tab == 'settings' ? $this->renderSettings():'',
|
|
'discount_rule_report' => $rule_tab == 'discount_report' ? $this->renderRuleReport():'',
|
|
)
|
|
);
|
|
return $this->html.$this->display(__FILE__,'admin.tpl');
|
|
}
|
|
public function saveActionRule()
|
|
{
|
|
if(($id_ets_pr_rule = (int)Tools::getValue('id_ets_pr_rule')) && ($rule = new Ets_pr_rule($id_ets_pr_rule)) && Validate::isLoadedObject($rule) )
|
|
{
|
|
$action = Ets_pr_action_rule::getActionByIdRule($id_ets_pr_rule);
|
|
$save = $action->saveData();
|
|
if(isset($save['errors']) && $save['errors'])
|
|
$this->html .= $this->displayError($save['errors']);
|
|
elseif(isset($save['success']) && $save['success'])
|
|
{
|
|
$this->context->cookie->_success = $this->l('Save successfully');
|
|
if(Tools::isSubmit('btnSubmitActionRuleStay'))
|
|
Tools::redirect($this->context->link->getAdminLink('AdminModules').'&configure=ets_promotion&&editrule=1&id_ets_pr_rule='.$rule->id.'¤t_tab=action'); //discount
|
|
else
|
|
Tools::redirect($this->context->link->getAdminLink('AdminModules').'&configure=ets_promotion&&editrule=1&id_ets_pr_rule='.$rule->id.'¤t_tab=discount'); //discount
|
|
}
|
|
}
|
|
else
|
|
$this->html .= $this->displayError($this->l('Rule is required'));
|
|
}
|
|
public function submitSaveRule()
|
|
{
|
|
$id_ets_pr_rule = (int)Tools::getValue('id_ets_pr_rule');
|
|
if($id_ets_pr_rule)
|
|
$rule = new Ets_pr_rule($id_ets_pr_rule);
|
|
else
|
|
$rule = new Ets_pr_rule($id_ets_pr_rule);
|
|
$save = $rule->saveData();
|
|
if(isset($save['errors']) && $save['errors'])
|
|
$this->html .= $this->displayError($save['errors']);
|
|
elseif(isset($save['success']) && $save['success'])
|
|
{
|
|
$this->context->cookie->_success = $this->l('Save successfully');
|
|
if(Tools::isSubmit('btnSubmitRuleStay'))
|
|
Tools::redirect($this->context->link->getAdminLink('AdminModules').'&configure=ets_promotion&&editrule=1&id_ets_pr_rule='.$rule->id.'¤t_tab=information');
|
|
else
|
|
Tools::redirect($this->context->link->getAdminLink('AdminModules').'&configure=ets_promotion&&editrule=1&id_ets_pr_rule='.$rule->id.'¤t_tab=condition');
|
|
}
|
|
}
|
|
public function submitSavePromoteRule()
|
|
{
|
|
$id_ets_pr_promote_rule = (int)Tools::getValue('id_ets_pr_promote_rule');
|
|
if($id_ets_pr_promote_rule)
|
|
$promote = new Ets_pr_promote_rule($id_ets_pr_promote_rule);
|
|
else
|
|
$promote = new Ets_pr_promote_rule();
|
|
$save = $promote->saveData();
|
|
if(isset($save['errors']) && $save['errors'])
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'errors' => $this->displayError($save['errors']),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
elseif(isset($save['success']) && $save['success'])
|
|
{
|
|
switch($promote->way_to_promote)
|
|
{
|
|
case 'display_notification':
|
|
$way_to_promote = $this->l('Display notification message');
|
|
$detail = $this->l('Notification: ').$promote->notification[$this->context->language->id];
|
|
$position_to_display = Ets_pr_promote_rule::displayPoisition($promote);
|
|
break;
|
|
case 'display_banner':
|
|
$way_to_promote = $this->l('Display banner');
|
|
$detail = Ets_pr_promote_rule::displayDetailBanner($promote);
|
|
$position_to_display = Ets_pr_promote_rule::displayPoisition($promote);
|
|
break;
|
|
case 'display_popup':
|
|
$way_to_promote = $this->l('Display popup');
|
|
$detail = Ets_pr_promote_rule::displayDetailPopup($promote);
|
|
$position_to_display = '--';
|
|
break;
|
|
case 'display_highlight_bar':
|
|
$way_to_promote = $this->l('Display highlight bar');
|
|
$detail = $this->l('Content: ').$promote->content_bar[$this->context->language->id];
|
|
$position_to_display = '--';
|
|
break;
|
|
}
|
|
$this->smarty->assign(
|
|
array(
|
|
'id_ets_pr_promote_rule' => $promote->id,
|
|
'way_to_promote' => $way_to_promote,
|
|
'detail_promote' => $detail,
|
|
'position_to_display' => $position_to_display,
|
|
'link' => $this->context->link,
|
|
)
|
|
);
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Saved promote way successfully'),
|
|
'id_ets_pr_promote_rule' => $promote->id,
|
|
'row_promote' => $this->display(__FILE__,'promote/row.tpl'),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
public function submitSaveConditionRule()
|
|
{
|
|
$id_ets_pr_condition_rule = (int)Tools::getValue('id_ets_pr_condition_rule');
|
|
if($id_ets_pr_condition_rule)
|
|
$condition = new Ets_pr_condition_rule($id_ets_pr_condition_rule);
|
|
else
|
|
$condition = new Ets_pr_condition_rule();
|
|
$save = $condition->saveData();
|
|
if(isset($save['errors']) && $save['errors'])
|
|
{
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'errors' => $this->displayError($save['errors']),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
elseif(isset($save['success']) && $save['success'])
|
|
{
|
|
switch($condition->parent_codition)
|
|
{
|
|
case 'specific_customer':
|
|
$parent_codition = $this->l('Customer - Specific customer');
|
|
$detail_condition = Ets_pr_condition_rule::displayListCustomer($condition);
|
|
break;
|
|
case 'customer_group':
|
|
$parent_codition = $this->l('Customer - Customer group');
|
|
$detail_condition = Ets_pr_condition_rule::displayListGroup($condition);
|
|
break;
|
|
case 'customer_personal':
|
|
$parent_codition = $this->l('Customer - Customer personal information');
|
|
$detail_condition = Ets_pr_condition_rule::displayCustomerPersonal($condition);
|
|
break;
|
|
case 'customer_membership':
|
|
$parent_codition = $this->l('Customer - Customer membership');
|
|
$detail_condition = Ets_pr_condition_rule::displayCustomerMembership($condition);
|
|
break;
|
|
case 'order_from_customer':
|
|
$parent_codition = $this->l('Customer - Orders placed by customer');
|
|
$detail_condition = Ets_pr_condition_rule::displayOrderFromCustomer($condition);
|
|
break;
|
|
case 'cart_amount':
|
|
$parent_codition = $this->l('Shopping cart - Cart amount');
|
|
$detail_condition = Ets_pr_condition_rule::displayCartAmount($condition);
|
|
break;
|
|
case 'product_in_cart':
|
|
$parent_codition = $this->l('Shopping cart - Products in cart');
|
|
$detail_condition = Ets_pr_condition_rule::displayProductInCart($condition);
|
|
break;
|
|
case 'delivery':
|
|
$parent_codition = $this->l('Shopping cart - Delivery');
|
|
$detail_condition = Ets_pr_condition_rule::displayDelivery($condition);
|
|
break;
|
|
case 'payments':
|
|
$parent_codition = $this->l('Shopping cart - Payment methods');
|
|
$detail_condition = Ets_pr_condition_rule::displayPayments($condition);
|
|
break;
|
|
case 'specific_occasion':
|
|
$parent_codition = $this->l('Specific occasion');
|
|
$detail_condition = Ets_pr_condition_rule::displaySpecificOccasions($condition);
|
|
break;
|
|
}
|
|
$this->smarty->assign(
|
|
array(
|
|
'id_ets_pr_condition_rule' => $condition->id,
|
|
'detail_condition' => $detail_condition,
|
|
'parent_codition' => $parent_codition,
|
|
'link' => $this->context->link,
|
|
)
|
|
);
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Save condition successfully'),
|
|
'id_ets_pr_condition_rule' => $condition->id,
|
|
'row_condtion' => $this->display(__FILE__,'condition/row.tpl'),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
public function renderRule()
|
|
{
|
|
if(Tools::isSubmit('addNewRule') || Tools::isSubmit('editrule'))
|
|
return $this->renderFormRule();
|
|
$fields_list = array(
|
|
'id_ets_pr_rule' => array(
|
|
'title' => $this->l('ID'),
|
|
'width' => 40,
|
|
'type' => 'text',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'name' => array(
|
|
'title' => $this->l('Name'),
|
|
'width' => 40,
|
|
'type' => 'text',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'code' => array(
|
|
'title' => $this->l('Code'),
|
|
'width' => 40,
|
|
'type' => 'text',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'type_action' => array(
|
|
'title' => $this->l('Action'),
|
|
'type' => 'select',
|
|
'strip_tag' => false,
|
|
'filter'=> true,
|
|
'sort' => false,
|
|
'filter_list' => array(
|
|
'id_option' => 'active',
|
|
'value' => 'title',
|
|
'list' => array(
|
|
array(
|
|
'active' => 'action_on_shipping',
|
|
'title' => $this->l('Shipping cost discount')
|
|
),
|
|
array(
|
|
'active' => 'order_amount',
|
|
'title' => $this->l('Order amount discount')
|
|
),
|
|
array(
|
|
'active' => 'action_on_product',
|
|
'title' => $this->l('Product discount')
|
|
),
|
|
array(
|
|
'active' => 'discount_on_all_quantities',
|
|
'title' => $this->l('Buy more than X units - Get discount on all units')
|
|
),
|
|
array(
|
|
'active' => 'purchase_discount_on_next_same_product',
|
|
'title' => $this->l('Buy X units - Get discount on next units of the same product')
|
|
),
|
|
array(
|
|
'active' => 'gift_or_with_discount_product',
|
|
'title' => $this->l('Buy product X - Get product Y for free (or discount)')
|
|
),
|
|
array(
|
|
'active' => 'purchase_more_product_quantity',
|
|
'title' => $this->l('Buy more than X units - Get discount on next all units')
|
|
),
|
|
array(
|
|
'active' => 'purchase_more_product_amount',
|
|
'title' => $this->l('Buy more than $X in selected product type - Get discount on all next products')
|
|
),
|
|
)
|
|
)
|
|
),
|
|
'quantity' => array(
|
|
'title' => $this->l('Qty'),
|
|
'width' => 40,
|
|
'type' => 'int',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'from_date' => array(
|
|
'title' => $this->l('From date'),
|
|
'width' => 40,
|
|
'type' => 'date',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'to_date' => array(
|
|
'title' => $this->l('To date'),
|
|
'width' => 40,
|
|
'type' => 'date',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'active' => array(
|
|
'title' => $this->l('Active'),
|
|
'type' => 'active',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
'filter_list' => array(
|
|
'id_option' => 'active',
|
|
'value' => 'title',
|
|
'list' => array(
|
|
0 => array(
|
|
'active' => 0,
|
|
'title' => $this->l('Disabled')
|
|
),
|
|
1 => array(
|
|
'active' => 1,
|
|
'title' => $this->l('Enabled')
|
|
),
|
|
)
|
|
)
|
|
),
|
|
'priority' => array(
|
|
'title' => $this->l('Priority'),
|
|
'type' => 'int',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
)
|
|
);
|
|
$filter = '';
|
|
$show_resset = false;
|
|
if(($id_ets_pr_rule = Tools::getValue('id_ets_pr_rule'))!='' && Validate::isCleanHtml($id_ets_pr_rule))
|
|
{
|
|
$filter .= ' AND r.id_ets_pr_rule='.(int)$id_ets_pr_rule;
|
|
$show_resset = true;
|
|
}
|
|
if(($name=Tools::getValue('name'))!='' && Validate::isCleanHtml($name))
|
|
{
|
|
$filter .= ' AND rl.name LIKE "%'.pSQL($name).'%"';
|
|
$show_resset = true;
|
|
}
|
|
if(($code=Tools::getValue('code'))!='' && Validate::isCleanHtml($code))
|
|
{
|
|
$filter .= ' AND ar.code LIKE "%'.pSQL($code).'%"';
|
|
$show_resset = true;
|
|
}
|
|
if(($quantity_min=Tools::getValue('quantity_min'))!='' && Validate::isCleanHtml($quantity_min))
|
|
{
|
|
$filter .= ' AND r.quantity >= "'.(int)$quantity_min.'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($quantity_max =Tools::getValue('quantity_max'))!='' && Validate::isCleanHtml($quantity_max))
|
|
{
|
|
$filter .= ' AND r.quantity <= "'.(int)$quantity_max.'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($from_date_min=Tools::getValue('from_date_min'))!='' && Validate::isDate($from_date_min))
|
|
{
|
|
$filter .= ' AND r.from_date >= "'.pSQL($from_date_min).'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($from_date_max =Tools::getValue('from_date_max'))!='' && Validate::isDate($from_date_max))
|
|
{
|
|
$filter .= ' AND r.from_date <= "'.pSQL($from_date_max).'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($to_date_min=Tools::getValue('to_date_min'))!='' && Validate::isDate($to_date_min))
|
|
{
|
|
$filter .= ' AND r.to_date >= "'.pSQL($to_date_min).'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($to_date_max =Tools::getValue('to_date_max'))!='' && Validate::isDate($to_date_max))
|
|
{
|
|
$filter .= ' AND r.to_date <= "'.pSQL($to_date_max).'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($active=Tools::getValue('active'))!='' && Validate::isCleanHtml($active))
|
|
{
|
|
$filter .= ' AND r.active = "'.(int)$active.'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($type_action = Tools::getValue('type_action')) && Validate::isCleanHtml($type_action))
|
|
{
|
|
$filter .= ' AND ar.type_action = "'.pSQL($type_action).'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($priority_min = Tools::getValue('priority_min'))!='' && Validate::isCleanHtml($priority_min))
|
|
{
|
|
$filter .= ' AND r.priority >= "'.(int)$priority_min.'"';
|
|
$show_resset = true;
|
|
}
|
|
if(($priority_max = Tools::getValue('priority_max'))!='' && Validate::isCleanHtml($priority_max))
|
|
{
|
|
$filter .= ' AND r.priority <= "'.(int)$priority_max.'"';
|
|
$show_resset = true;
|
|
}
|
|
$sort = "";
|
|
$sort_type=Tools::getValue('sort_type','asc');
|
|
$sort_value = Tools::getValue('sort','id_ets_pr_rule');
|
|
if($sort_value)
|
|
{
|
|
switch ($sort_value) {
|
|
case 'id_ets_pr_rule':
|
|
$sort .=' r.id_ets_pr_rule';
|
|
break;
|
|
case 'name':
|
|
$sort .=' rl.name';
|
|
break;
|
|
case 'code':
|
|
$sort .=' ar.code';
|
|
break;
|
|
case 'from_date':
|
|
$sort .=' r.from_date';
|
|
break;
|
|
case 'to_date':
|
|
$sort .=' r.to_date';
|
|
break;
|
|
case 'quantity':
|
|
$sort .=' r.quantity';
|
|
break;
|
|
case 'active':
|
|
$sort .=' r.active';
|
|
break;
|
|
case 'priority':
|
|
$sort .=' r.priority';
|
|
break;
|
|
}
|
|
if($sort && $sort_type && in_array($sort_type,array('asc','desc')))
|
|
$sort .= ' '.$sort_type;
|
|
}
|
|
//Paggination
|
|
$page = (int)Tools::getValue('page');
|
|
if($page<=0)
|
|
$page = 1;
|
|
$totalRecords = (int)Ets_pr_rule::getRules($filter,$sort,0,0,true);
|
|
$paggination = new Ets_pr_paggination_class();
|
|
$paggination->total = $totalRecords;
|
|
$paggination->url = $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&page=_page_'.$this->getFilterParams($fields_list,'rule');
|
|
$paggination->limit = (int)Tools::getValue('paginator_rule_select_limit',20);
|
|
$paggination->name ='rule';
|
|
$totalPages = ceil($totalRecords / $paggination->limit);
|
|
if($page > $totalPages)
|
|
$page = $totalPages;
|
|
$paggination->page = $page;
|
|
$start = $paggination->limit * ($page - 1);
|
|
if($start < 0)
|
|
$start = 0;
|
|
$rules= Ets_pr_rule::getRules($filter,$sort,$start,$paggination->limit,false);
|
|
if($rules)
|
|
{
|
|
foreach($rules as &$rule)
|
|
{
|
|
if($rule['from_date']=='0000-00-00 00:00:00')
|
|
$rule['from_date'] ='--';
|
|
if($rule['to_date']=='0000-00-00 00:00:00')
|
|
$rule['to_date'] ='--';
|
|
$type_action = $this->displayText($this->l('No action'), 'span', 'rule_no_action', null, null, null, null, null, null, null, null, null, null, null, $this->l('The rule does not work because no action is added'));
|
|
if ($rule['type_action']) {
|
|
switch ($rule['type_action']) {
|
|
case 'action_on_shipping':
|
|
$type_action = $this->l('Shipping cost discount');
|
|
break;
|
|
case 'order_amount';
|
|
$type_action = $this->l('Order amount discount');
|
|
break;
|
|
case 'action_on_product';
|
|
$type_action = $this->l('Product discount');
|
|
break;
|
|
case 'discount_on_all_quantities';
|
|
$type_action = $this->l('Buy more than X units - Get discount on all units');
|
|
break;
|
|
case 'purchase_discount_on_next_same_product';
|
|
$type_action = $this->l('Buy X units - Get discount on next units of the same product');
|
|
break;
|
|
case 'gift_or_with_discount_product';
|
|
$type_action = $this->l('Buy product X - Get product Y for free (or discount)');
|
|
break;
|
|
case 'purchase_more_product_quantity';
|
|
$type_action = $this->l('Buy more than X units - Get discount on next all units');
|
|
break;
|
|
case 'purchase_more_product_amount';
|
|
$type_action = $this->l('Buy more than $X in selected product type - Get discount on all next products');
|
|
break;
|
|
}
|
|
}
|
|
|
|
$rule['type_action'] = $type_action;
|
|
}
|
|
}
|
|
$paggination->text = $this->l('Showing {start} to {end} of {total} ({pages} Pages)');
|
|
$paggination->style_links = $this->l('links');
|
|
$paggination->style_results = $this->l('results');
|
|
$listData = array(
|
|
'name' => 'rule',
|
|
'actions' => array('view','duplicate','view_report','delete'),
|
|
'icon' => 'icon-rule',
|
|
'currentIndex' => $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.($paggination->limit!=20 ? '&paginator_rule_select_limit='.$paggination->limit:''),
|
|
'postIndex' => $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name,
|
|
'identifier' => 'id_ets_pr_rule',
|
|
'show_toolbar' => true,
|
|
'show_action' => true,
|
|
'show_add_new' => true,
|
|
'link_new' => $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&addNewRule=1',
|
|
'add_new_text' => $this->l('Add new discount rule'),
|
|
'title' => $this->l('Discount rules'),
|
|
'fields_list' => $fields_list,
|
|
'field_values' => $rules,
|
|
'paggination' => $paggination->render(),
|
|
'filter_params' => $this->getFilterParams($fields_list,'rule'),
|
|
'show_reset' =>$show_resset,
|
|
'totalRecords' => $totalRecords,
|
|
'sort'=> $sort_value,
|
|
'sort_type' => $sort_type,
|
|
);
|
|
return $this->renderList($listData);
|
|
}
|
|
public function renderRuleReport()
|
|
{
|
|
if(Tools::isSubmit('viewRuleReport'))
|
|
return $this->displayViewRuleReport();
|
|
$fields_list = array(
|
|
'id_ets_pr_rule' => array(
|
|
'title' => $this->l('ID'),
|
|
'width' => 40,
|
|
'type' => 'text',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'name' => array(
|
|
'title' => $this->l('Rule name'),
|
|
'width' => 40,
|
|
'type' => 'text',
|
|
'strip_tag'=> false,
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'code' => array(
|
|
'title' => $this->l('Code'),
|
|
'width' => 40,
|
|
'type' => 'text',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
),
|
|
'active' => array(
|
|
'title' => $this->l('Active'),
|
|
'type' => 'active',
|
|
'sort' => true,
|
|
'filter' => true,
|
|
'filter_list' => array(
|
|
'id_option' => 'active',
|
|
'value' => 'title',
|
|
'list' => array(
|
|
0 => array(
|
|
'active' => 0,
|
|
'title' => $this->l('Disabled')
|
|
),
|
|
1 => array(
|
|
'active' => 1,
|
|
'title' => $this->l('Enabled')
|
|
),
|
|
)
|
|
)
|
|
),
|
|
'total_order' => array(
|
|
'title' => $this->l('Applied'),
|
|
'width' => 40,
|
|
'type' => 'int',
|
|
'sort' => true,
|
|
'filter' => false,
|
|
),
|
|
'new_customer' => array(
|
|
'title' => $this->l('New customer'),
|
|
'width' => 40,
|
|
'type' => 'int',
|
|
'sort' => true,
|
|
'filter' => false,
|
|
),
|
|
'total_amount' => array(
|
|
'title' => $this->l('Total order amount'),
|
|
'width' => 40,
|
|
'type' => 'int',
|
|
'sort' => true,
|
|
'filter' => false,
|
|
),
|
|
);
|
|
$filter = '';
|
|
$show_resset = false;
|
|
if(($id_ets_pr_rule = Tools::getValue('id_ets_pr_rule'))!='' && Validate::isCleanHtml($id_ets_pr_rule))
|
|
{
|
|
$filter .= ' AND r.id_ets_pr_rule='.(int)$id_ets_pr_rule;
|
|
$show_resset = true;
|
|
}
|
|
if(($name=Tools::getValue('name'))!='' && Validate::isCleanHtml($name))
|
|
{
|
|
$filter .= ' AND rl.name LIKE "%'.pSQL($name).'%"';
|
|
$show_resset = true;
|
|
}
|
|
if(($code=Tools::getValue('code'))!='' && Validate::isCleanHtml($code))
|
|
{
|
|
$filter .= ' AND ar.code LIKE "%'.pSQL($code).'%"';
|
|
$show_resset = true;
|
|
}
|
|
if(($active=Tools::getValue('active'))!='' && Validate::isCleanHtml($active))
|
|
{
|
|
$filter .= ' AND r.active = "'.(int)$active.'"';
|
|
$show_resset = true;
|
|
}
|
|
$sort = "";
|
|
$sort_type=Tools::getValue('sort_type','desc');
|
|
$sort_value = Tools::getValue('sort','total_amount');
|
|
if($sort_value)
|
|
{
|
|
switch ($sort_value) {
|
|
case 'id_ets_pr_rule':
|
|
$sort .=' r.id_ets_pr_rule';
|
|
break;
|
|
case 'name':
|
|
$sort .=' rl.name';
|
|
break;
|
|
case 'code':
|
|
$sort .=' ar.code';
|
|
break;
|
|
case 'active':
|
|
$sort .=' r.active';
|
|
break;
|
|
case 'total_order':
|
|
$sort .=' total_order';
|
|
break;
|
|
case 'total_amount':
|
|
$sort .=' total_amount';
|
|
break;
|
|
case 'new_customer':
|
|
$sort .=' new_customer';
|
|
break;
|
|
}
|
|
if($sort && $sort_type && in_array($sort_type,array('asc','desc')))
|
|
$sort .= ' '.$sort_type;
|
|
}
|
|
//Paggination
|
|
$page = (int)Tools::getValue('page');
|
|
if($page<=0)
|
|
$page = 1;
|
|
$totalRecords = (int)Ets_pr_rule::getRuleReports($filter,$sort,0,0,true);
|
|
$paggination = new Ets_pr_paggination_class();
|
|
$paggination->total = $totalRecords;
|
|
$paggination->url = $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&page=_page_&rule_tab=discount_report'.$this->getFilterParams($fields_list,'rule_report');
|
|
$paggination->limit = (int)Tools::getValue('paginator_rule_report_select_limit',20);
|
|
$paggination->name ='rule_report';
|
|
$totalPages = ceil($totalRecords / $paggination->limit);
|
|
if($page > $totalPages)
|
|
$page = $totalPages;
|
|
$paggination->page = $page;
|
|
$start = $paggination->limit * ($page - 1);
|
|
if($start < 0)
|
|
$start = 0;
|
|
$rules= Ets_pr_rule::getRuleReports($filter,$sort,$start,$paggination->limit,false);
|
|
if($rules)
|
|
{
|
|
foreach($rules as &$rule)
|
|
{
|
|
$rule['total_amount'] = Tools::displayPrice($rule['total_amount']);
|
|
$rule['action_edit'] = false;
|
|
$rule['child_view_url'] = $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&rule_tab=discount_report&viewRuleReport='.(int)$rule['id_ets_pr_rule'];
|
|
$rule['name'] = $this->displayText($rule['name'],'a',null,null,$this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&editrule=1&id_ets_pr_rule='.(int)$rule['id_ets_pr_rule']);
|
|
if(!$rule['new_customer'])
|
|
$rule['new_customer']='--';
|
|
if(!$rule['total_order'])
|
|
$rule['total_order']='--';
|
|
}
|
|
}
|
|
$paggination->text = $this->l('Showing {start} to {end} of {total} ({pages} Pages)');
|
|
$paggination->style_links = $this->l('links');
|
|
$paggination->style_results = $this->l('results');
|
|
$listData = array(
|
|
'name' => 'rule_report',
|
|
'actions' => array('view'),
|
|
'icon' => 'icon-rule',
|
|
'currentIndex' => $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&rule_tab=discount_report'.($paggination->limit!=20 ? '&paginator_rule_report_select_limit='.$paggination->limit:''),
|
|
'postIndex' => $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&rule_tab=discount_report',
|
|
'identifier' => 'id_ets_pr_rule',
|
|
'show_toolbar' => true,
|
|
'show_action' => true,
|
|
'show_add_new' => false,
|
|
'title' => $this->l('Statistics'),
|
|
'fields_list' => $fields_list,
|
|
'field_values' => $rules,
|
|
'paggination' => $paggination->render(),
|
|
'filter_params' => $this->getFilterParams($fields_list,'rule'),
|
|
'show_reset' =>$show_resset,
|
|
'totalRecords' => $totalRecords,
|
|
'sort'=> $sort_value,
|
|
'sort_type' => $sort_type,
|
|
);
|
|
return $this->renderList($listData);
|
|
}
|
|
public function displayViewRuleReport()
|
|
{
|
|
$id_rule = (int)Tools::getValue('viewRuleReport');
|
|
if($id_rule)
|
|
{
|
|
$cache_id = $this->_getCacheId(['rule_report', $id_rule]);
|
|
if (!$this->isCached('rule_report.tpl', $cache_id)) {
|
|
$rule = new Ets_pr_rule($id_rule,$this->context->language->id);
|
|
$this->smarty->assign(
|
|
array(
|
|
'rule' => $rule,
|
|
'applied_orders' => $rule->getOrderApplied(),
|
|
'link'=> $this->context->link,
|
|
)
|
|
);
|
|
}
|
|
return $this->display(__FILE__,'rule_report.tpl', $cache_id);
|
|
}
|
|
|
|
}
|
|
public function renderList($listData)
|
|
{
|
|
if(isset($listData['fields_list']) && $listData['fields_list'])
|
|
{
|
|
foreach($listData['fields_list'] as $key => &$val)
|
|
{
|
|
$value_key = (string)Tools::getValue($key);
|
|
$value_key_max = (string)Tools::getValue($key.'_max');
|
|
$value_key_min = (string)Tools::getValue($key.'_min');
|
|
if(isset($val['filter']) && $val['filter'] && ($val['type']=='int' || $val['type']=='date'))
|
|
{
|
|
if(Tools::isSubmit('ets_pr_submit_'.$listData['name']))
|
|
{
|
|
$val['active']['max'] = trim($value_key_max);
|
|
$val['active']['min'] = trim($value_key_min);
|
|
}
|
|
else
|
|
{
|
|
$val['active']['max']='';
|
|
$val['active']['min']='';
|
|
}
|
|
}
|
|
elseif(!Tools::isSubmit('del') && Tools::isSubmit('ets_pr_submit_'.$listData['name']))
|
|
$val['active'] = trim($value_key);
|
|
else
|
|
$val['active']='';
|
|
}
|
|
}
|
|
if(!isset($listData['class']))
|
|
$listData['class']='';
|
|
$this->smarty->assign($listData);
|
|
return $this->display(__FILE__, 'list_helper.tpl');
|
|
}
|
|
public function getFilterParams($field_list,$table='')
|
|
{
|
|
$params = '';
|
|
if($field_list)
|
|
{
|
|
if(Tools::isSubmit('ets_pr_submit_'.$table))
|
|
$params .='&ets_pr_submit_'.$table.='=1';
|
|
foreach($field_list as $key => $val)
|
|
{
|
|
$value_key = (string)Tools::getValue($key);
|
|
$value_key_max = (string)Tools::getValue($key.'_max');
|
|
$value_key_min = (string)Tools::getValue($key.'_min');
|
|
if($value_key!='')
|
|
{
|
|
$params .= '&'.$key.'='.urlencode($value_key);
|
|
}
|
|
if($value_key_max!='')
|
|
{
|
|
$params .= '&'.$key.'_max='.urlencode($value_key_max);
|
|
}
|
|
if($value_key_min!='')
|
|
{
|
|
$params .= '&'.$key.'_min='.urlencode($value_key_min);
|
|
}
|
|
}
|
|
unset($val);
|
|
}
|
|
return $params;
|
|
}
|
|
public function displayPaggination($limit,$name)
|
|
{
|
|
$this->context->smarty->assign(
|
|
array(
|
|
'limit' => $limit,
|
|
'pageName' => $name,
|
|
)
|
|
);
|
|
return $this->display(__FILE__,'limit.tpl');
|
|
}
|
|
public function renderFormRule()
|
|
{
|
|
$html = '';
|
|
if(Tools::isSubmit('addNewRule') || (Tools::isSubmit('editrule') && ($id_ets_pr_rule = (int)Tools::getValue('id_ets_pr_rule'))) )
|
|
{
|
|
$current_tab = Tools::getValue('current_tab','information');
|
|
if($current_tab=='information')
|
|
{
|
|
if(isset($id_ets_pr_rule) && $id_ets_pr_rule)
|
|
$rule = new Ets_pr_rule($id_ets_pr_rule);
|
|
else
|
|
$rule = new Ets_pr_rule();
|
|
$html .= $rule->renderForm();
|
|
}
|
|
elseif($current_tab=='condition')
|
|
$html .= $this->displayCoditionRuleForm();
|
|
elseif($current_tab=='action' && isset($id_ets_pr_rule) && $id_ets_pr_rule)
|
|
{
|
|
$action = Ets_pr_action_rule::getActionByIdRule($id_ets_pr_rule);
|
|
$html .= $action->renderForm();
|
|
}
|
|
elseif($current_tab=='discount')
|
|
$html .= $this->displayPromoteRuleForm();
|
|
|
|
}
|
|
$this->smarty->assign(
|
|
array(
|
|
'pr_link_search_product' => $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&search_product=1',
|
|
'pr_link_search_customer' => $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&search_customer=1',
|
|
'tab_rule' => $this->displayTabRule(),
|
|
'link' => $this->context->link,
|
|
'form_html' => $html,
|
|
'id_ets_pr_rule' => isset($id_ets_pr_rule) && $id_ets_pr_rule,
|
|
'rule' => isset($id_ets_pr_rule) ? new Ets_pr_rule($id_ets_pr_rule,$this->context->language->id):false,
|
|
)
|
|
);
|
|
return $this->display(__FILE__,'form_rule.tpl');
|
|
}
|
|
public function displayPromoteRuleForm()
|
|
{
|
|
$id_ets_pr_rule = (int)Tools::getValue('id_ets_pr_rule');
|
|
if($id_ets_pr_rule)
|
|
{
|
|
$id_ets_pr_promote_rule = (int)Tools::getValue('id_ets_pr_promote_rule');
|
|
if($id_ets_pr_promote_rule)
|
|
$promoteRule = new Ets_pr_promote_rule($id_ets_pr_promote_rule);
|
|
else
|
|
{
|
|
$promoteRule = new Ets_pr_promote_rule();
|
|
$promoteRule->id_ets_pr_rule = $id_ets_pr_rule;
|
|
}
|
|
$this->smarty->assign(
|
|
array(
|
|
'link' => $this->context->link,
|
|
'promotes' => $promoteRule->getListPromoteByRule($promoteRule->id_ets_pr_rule),
|
|
'promote_form' => $promoteRule->renderForm(),
|
|
'id_ets_pr_rule' => $id_ets_pr_rule,
|
|
)
|
|
);
|
|
return $this->display(__FILE__,'promote.tpl');
|
|
}
|
|
}
|
|
public function displayCoditionRuleForm(){
|
|
$id_ets_pr_rule = (int)Tools::getValue('id_ets_pr_rule');
|
|
if($id_ets_pr_rule)
|
|
{
|
|
$id_ets_pr_condition_rule = (int)Tools::getValue('id_ets_pr_condition_rule');
|
|
$cache_id = $this->_getCacheId(['condition', $id_ets_pr_rule, $id_ets_pr_condition_rule]);
|
|
if (!$this->isCached('condition.tpl', $cache_id)) {
|
|
if($id_ets_pr_condition_rule)
|
|
$conditionRule = new Ets_pr_condition_rule($id_ets_pr_condition_rule);
|
|
else
|
|
{
|
|
$conditionRule = new Ets_pr_condition_rule();
|
|
$conditionRule->id_ets_pr_rule = $id_ets_pr_rule;
|
|
}
|
|
$this->smarty->assign(
|
|
array(
|
|
'link' => $this->context->link,
|
|
'conditions' => $conditionRule->getListConditionsByRule($conditionRule->id_ets_pr_rule),
|
|
'condition_form' => $conditionRule->renderForm(),
|
|
'id_ets_pr_rule' => $id_ets_pr_rule,
|
|
)
|
|
);
|
|
}
|
|
return $this->display(__FILE__,'condition.tpl', $cache_id);
|
|
}
|
|
}
|
|
public function displayTabRule()
|
|
{
|
|
$id_ets_pr_rule = (int)Tools::getValue('id_ets_pr_rule');
|
|
$current_tab = Tools::getValue('current_tab','information');
|
|
$cache_id = $this->_getCacheId(['rule_tab', $id_ets_pr_rule, $current_tab]);
|
|
if (!$this->isCached('rule_tab.tpl', $cache_id)) {
|
|
$this->smarty->assign(
|
|
array(
|
|
'link' => $this->context->link,
|
|
'id_ets_pr_rule' => $id_ets_pr_rule,
|
|
'current_tab' => Validate::isCleanHtml($current_tab) ? $current_tab : 'current_tab',
|
|
)
|
|
);
|
|
}
|
|
return $this->display(__FILE__,'rule_tab.tpl', $cache_id);
|
|
}
|
|
public function modulePath()
|
|
{
|
|
return $this->_path;
|
|
}
|
|
public function displayListStates($id_country)
|
|
{
|
|
$html = '';
|
|
if($states = Ets_pr_rule::getInstance()->getListStates($id_country))
|
|
{
|
|
$html .= $this->displayText($this->l('-- Select state --'), 'option', '', null, null, null, null, null, null, '0');
|
|
foreach ($states as $index => $state) {
|
|
//<option value="{$state.id_state|intval}">{$state.name|escape:'html':'UTF-8'}</option>
|
|
$html .= $this->displayText($state['name'], 'option', '', null, null, null, null, null, null, $state['id_state']);
|
|
}
|
|
// $this->smarty->assign(
|
|
// array(
|
|
// 'states' => $states,
|
|
// )
|
|
// );
|
|
// return $this->display(__FILE__,'states.tpl');
|
|
}
|
|
return $html;
|
|
}
|
|
public function displayListCustomers($id_customers)
|
|
{
|
|
if($id_customers)
|
|
{
|
|
$cache_id = $this->_getCacheId(is_array($id_customers) ? array_merge(['customers'], $id_customers) : ['customers', $id_customers]);
|
|
if (!$this->isCached('customers.tpl', $cache_id)) {
|
|
$this->smarty->assign(
|
|
array(
|
|
'customers' => Ets_pr_condition_rule::getCustomersByIds($id_customers),
|
|
)
|
|
);
|
|
}
|
|
return $this->display(__FILE__,'customers.tpl', $cache_id);
|
|
}
|
|
|
|
}
|
|
public function displayListGiftProducts()
|
|
{
|
|
$cache_id = $this->_getCacheId(['gift_products']);
|
|
if (!$this->isCached('gift_products.tpl', $cache_id)) {
|
|
$products = Ets_pr_rule::getGiftProducts();
|
|
$this->smarty->assign(
|
|
array(
|
|
'products' =>$products,
|
|
'link'=> $this->context->link,
|
|
'ETS_PR_TITLE_OF_PRODUCT_GIFT' => Configuration::get('ETS_PR_TITLE_OF_PRODUCT_GIFT',$this->context->language->id),
|
|
)
|
|
);
|
|
}
|
|
return $this->display(__FILE__,'gift_products.tpl', $cache_id);
|
|
}
|
|
public function displayListProducts($productIds)
|
|
{
|
|
if($productIds)
|
|
{
|
|
$products = Ets_pr_defines::getProductsByIds($productIds);
|
|
$this->smarty->assign('products', $products);
|
|
return $this->display(__FILE__, 'product-item.tpl');
|
|
}
|
|
}
|
|
public static function validateArray($array,$validate='isCleanHtml')
|
|
{
|
|
if(!is_array($array))
|
|
{
|
|
if(method_exists('Validate',$validate))
|
|
{
|
|
return Validate::$validate($array);
|
|
}
|
|
else
|
|
return true;
|
|
}
|
|
if(method_exists('Validate',$validate))
|
|
{
|
|
if($array && is_array($array))
|
|
{
|
|
$ok= true;
|
|
foreach($array as $val)
|
|
{
|
|
if(!is_array($val))
|
|
{
|
|
if($val && !Validate::$validate($val))
|
|
{
|
|
$ok= false;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
$ok = self::validateArray($val,$validate);
|
|
}
|
|
return $ok;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
public static function isColor($color)
|
|
{
|
|
return preg_match('/^(#[0-9a-fA-F]{6})$/', $color);
|
|
}
|
|
public static function isLink($link)
|
|
{
|
|
$link_validation = '/(http|https)\:\/\/[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/';
|
|
if($link =='#' || preg_match($link_validation, $link)){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public function haveCartRuleToday()
|
|
{
|
|
return Ets_pr_rule::haveCartRuleToday();
|
|
|
|
}
|
|
public function getCustomerCartRules(&$result,$id_customer,$highlight_only){
|
|
return Ets_pr_rule::getCustomerCartRules($result,$id_customer,$highlight_only);
|
|
}
|
|
public function addCartRule(&$errors,$code)
|
|
{
|
|
if(($id_rule = (int)Ets_pr_rule::ruleExists($code)) && ($rule = new Ets_pr_rule($id_rule)) && Validate::isLoadedObject($rule) )
|
|
{
|
|
$errors = array();
|
|
if(($error = $rule->checkValidity()))
|
|
$errors[] = $error;
|
|
if(!$errors)
|
|
{
|
|
$rule->addToCart();
|
|
}
|
|
}
|
|
}
|
|
public function deleteCartRule($id_rule)
|
|
{
|
|
$rule = new Ets_pr_rule($id_rule);
|
|
$rule->deleteCart();
|
|
CartRule::autoAddToCart($this->context);
|
|
}
|
|
public function getDiscountTotal($use_tax = true)
|
|
{
|
|
return Ets_pr_rule::getDiscountTotal($use_tax);
|
|
}
|
|
public function autoAddToCart($context = null)
|
|
{
|
|
return Ets_pr_rule::autoAddToCart($context);
|
|
}
|
|
public function renderSettings()
|
|
{
|
|
$fields_form = array(
|
|
'form' => array(
|
|
'legend' => array(
|
|
'title' => $this->l('Settings'),
|
|
'icon' => ''
|
|
),
|
|
'input' => Ets_pr_defines::getInstance()->getConfigInputs(),
|
|
'submit' => array(
|
|
'title' => $this->l('Save'),
|
|
)
|
|
),
|
|
);
|
|
$helper = new HelperForm();
|
|
$helper->show_toolbar = false;
|
|
$helper->id = $this->id;
|
|
$helper->module = $this;
|
|
$helper->identifier = $this->identifier;
|
|
$helper->submit_action = 'btnSubmitSettingsRule';
|
|
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$language = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
|
$helper->default_form_language = $language->id;
|
|
$helper->override_folder ='/';
|
|
$configTabs = array(
|
|
array(
|
|
'tab' => 'general',
|
|
'name' => $this->l('General settings'),
|
|
),
|
|
array(
|
|
'tab' => 'cronjob',
|
|
'name' => $this->l('Cronjob'),
|
|
),
|
|
);
|
|
$helper->tpl_vars = array(
|
|
'base_url' => $this->context->shop->getBaseURL(),
|
|
'language' => array(
|
|
'id_lang' => $language->id,
|
|
'iso_code' => $language->iso_code
|
|
),
|
|
'PS_ALLOW_ACCENTED_CHARS_URL', (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'),
|
|
'fields_value' => $this->getConfigFieldsValues(),
|
|
'languages' => $this->context->controller->getLanguages(),
|
|
'id_language' => $this->context->language->id,
|
|
'link' => $this->context->link,
|
|
'configTabs' => $configTabs,
|
|
);
|
|
$this->fields_form = array();
|
|
return $helper->generateForm(array($fields_form));
|
|
}
|
|
public function getConfigFieldsValues()
|
|
{
|
|
$languages = Language::getLanguages(false);
|
|
$fields = array();
|
|
$inputs = Ets_pr_defines::getInstance()->getConfigInputs();
|
|
if($inputs)
|
|
{
|
|
foreach($inputs as $input)
|
|
{
|
|
if($input['type']=='html')
|
|
continue;
|
|
if(!isset($input['lang']))
|
|
{
|
|
if($input['type']=='checkbox')
|
|
{
|
|
$fields[$input['name']] = Tools::getValue($input['name'],Configuration::get($input['name']) ? explode(',',Configuration::get($input['name'])):array());
|
|
}
|
|
else
|
|
$fields[$input['name']] = Tools::getValue($input['name'],Configuration::get($input['name']));
|
|
}
|
|
else
|
|
{
|
|
foreach($languages as $language)
|
|
{
|
|
$fields[$input['name']][$language['id_lang']] = Tools::getValue($input['name'].'_'.$language['id_lang'],Configuration::get($input['name'],$language['id_lang']));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $fields;
|
|
}
|
|
public function settingsValidation()
|
|
{
|
|
$languages = Language::getLanguages(false);
|
|
$inputs = Ets_pr_defines::getInstance()->getConfigInputs();
|
|
$id_lang_default = Configuration::get('PS_LANG_DEFAULT');
|
|
foreach($inputs as $input)
|
|
{
|
|
if($input['type']=='html')
|
|
continue;
|
|
if(isset($input['lang']) && $input['lang'])
|
|
{
|
|
if(isset($input['required']) && $input['required'])
|
|
{
|
|
$val_default = Tools::getValue($input['name'].'_'.$id_lang_default);
|
|
if(!$val_default)
|
|
{
|
|
$this->_errors[] = sprintf($this->l('%s is required'),$input['label']);
|
|
}
|
|
elseif($val_default && isset($input['validate']) && ($validate = $input['validate']) && method_exists('Validate',$validate) && !Validate::{$validate}($val_default))
|
|
$this->_errors[] = sprintf($this->l('%s is not valid'),$input['label']);
|
|
elseif($val_default && !Validate::isCleanHtml($val_default))
|
|
$this->_errors[] = sprintf($this->l('%s is not valid'),$input['label']);
|
|
else
|
|
{
|
|
foreach($languages as $language)
|
|
{
|
|
if(($value = Tools::getValue($input['name'].'_'.$language['id_lang'])) && isset($input['validate']) && ($validate = $input['validate']) && method_exists('Validate',$validate) && !Validate::{$validate}($value))
|
|
$this->_errors[] = sprintf($this->l('%s is not valid in %s'),$input['label'],$language['iso_code']);
|
|
elseif($value && !Validate::isCleanHtml($value))
|
|
$this->_errors[] = sprintf($this->l('%s is not valid in %s'),$input['label'],$language['iso_code']);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach($languages as $language)
|
|
{
|
|
if(($value = Tools::getValue($input['name'].'_'.$language['id_lang'])) && isset($input['validate']) && ($validate = $input['validate']) && method_exists('Validate',$validate) && !Validate::{$validate}($value))
|
|
$this->_errors[] = sprintf($this->l('%s is not valid in %s'),$input['label'],$language['iso_code']);
|
|
elseif($value && !Validate::isCleanHtml($value))
|
|
$this->_errors[] = sprintf($this->l('%s is not valid in %s'),$input['label'],$language['iso_code']);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$val = Tools::getValue($input['name']);
|
|
if($val===''&& isset($input['required']))
|
|
{
|
|
$this->_errors[] = sprintf($this->l('%s is required'),$input['label']);
|
|
}
|
|
if($val!=='' && isset($input['validate']) && ($validate = $input['validate']) && method_exists('Validate',$validate) && !Validate::{$validate}($val))
|
|
{
|
|
$this->_errors[] = sprintf($this->l('%s is not valid'),$input['label']);
|
|
}
|
|
elseif(is_array($val))
|
|
{
|
|
if($val && !Ets_promotion::validateArray($val))
|
|
$this->_errors[] = sprintf($this->l('%s is not valid'),$input['label']);
|
|
}
|
|
elseif($val!==''&& !Validate::isCleanHtml($val))
|
|
$this->_errors[] = sprintf($this->l('%s is not valid'),$input['label']);
|
|
}
|
|
}
|
|
}
|
|
public function submitSettingsRule()
|
|
{
|
|
$this->settingsValidation();
|
|
if (!count($this->_errors)) {
|
|
$this->_clearSmartyCacheWhenUpdateSetting();
|
|
$inputs = Ets_pr_defines::getInstance()->getConfigInputs();
|
|
$languages = Language::getLanguages(false);
|
|
$id_lang_default = Configuration::get('PS_LANG_DEFAULT');
|
|
foreach($inputs as $input)
|
|
{
|
|
if($input['type']!='html')
|
|
{
|
|
if(isset($input['lang']) && $input['lang'])
|
|
{
|
|
$values = array();
|
|
foreach($languages as $language)
|
|
{
|
|
$value_default = Tools::getValue($input['name'].'_'.$id_lang_default);
|
|
$value = Tools::getValue($input['name'].'_'.$language['id_lang']);
|
|
$values[$language['id_lang']] = ($value && Validate::isCleanHtml($value)) || !isset($input['required']) ? $value : (Validate::isCleanHtml($value_default) ? $value_default :'');
|
|
}
|
|
Configuration::updateValue($input['name'],$values);
|
|
}
|
|
else
|
|
{
|
|
$val = Tools::getValue($input['name']);
|
|
if($input['type']=='checkbox')
|
|
{
|
|
Configuration::updateValue($input['name'],$val ? implode(',',$val):'');
|
|
}
|
|
else
|
|
{
|
|
if(Validate::isCleanHtml($val))
|
|
Configuration::updateValue($input['name'],$val);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'success' => $this->l('Settings updated'),
|
|
)
|
|
)
|
|
);
|
|
} else {
|
|
die(
|
|
json_encode(
|
|
array(
|
|
'errors' => $this->displayError($this->_errors),
|
|
)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
public static function getLinkCustomerAdmin($id_customer)
|
|
{
|
|
if(version_compare(_PS_VERSION_, '1.7.6', '>='))
|
|
{
|
|
$link_customer = self::getLinkAdminController('admin_customers_view',array('customerId' => $id_customer));
|
|
}
|
|
else
|
|
$link_customer = Context::getContext()->link->getAdminLink('AdminCustomers').'&id_customer='.(int)$id_customer.'&viewcustomer';
|
|
return $link_customer;
|
|
}
|
|
public static function getLinkOrderAdmin($id_order)
|
|
{
|
|
if(version_compare(_PS_VERSION_, '1.7.7.0', '>='))
|
|
{
|
|
$link_order = self::getLinkAdminController('admin_orders_view',array('orderId' => $id_order));
|
|
}
|
|
else
|
|
$link_order = Context::getContext()->link->getAdminLink('AdminOrders').'&id_order='.(int)$id_order.'&vieworder';
|
|
return $link_order;
|
|
}
|
|
public static function getLinkAdminController($entiny,$params=array())
|
|
{
|
|
$sfContainer = call_user_func(array('\PrestaShop\PrestaShop\Adapter\SymfonyContainer','getInstance'));
|
|
if (null !== $sfContainer) {
|
|
$sfRouter = $sfContainer->get('router');
|
|
return $sfRouter->generate(
|
|
$entiny,
|
|
$params
|
|
);
|
|
}
|
|
}
|
|
public function checkExitCode($code,&$errors)
|
|
{
|
|
if(Ets_pr_rule::ruleExists($code))
|
|
{
|
|
$errors[] = $this->l('Discount code already existed');
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public function checkCreatedColumn($table,$column)
|
|
{
|
|
$fieldsCustomers = Db::getInstance()->ExecuteS('DESCRIBE '._DB_PREFIX_.pSQL($table));
|
|
$check_add=false;
|
|
foreach($fieldsCustomers as $field)
|
|
{
|
|
if($field['Field']==$column)
|
|
{
|
|
$check_add=true;
|
|
break;
|
|
}
|
|
}
|
|
return $check_add;
|
|
}
|
|
/**
|
|
* @param string $path
|
|
* @param int $permission
|
|
*
|
|
* @return bool
|
|
*
|
|
* @throws \PrestaShopException
|
|
*/
|
|
private function safeMkDir($path, $permission = 0755)
|
|
{
|
|
if (!@mkdir($concurrentDirectory = $path, $permission) && !is_dir($concurrentDirectory)) {
|
|
throw new \PrestaShopException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
private function checkOverrideDir()
|
|
{
|
|
if (defined('_PS_OVERRIDE_DIR_')) {
|
|
$psOverride = @realpath(_PS_OVERRIDE_DIR_) . DIRECTORY_SEPARATOR;
|
|
if (!is_dir($psOverride)) {
|
|
$this->safeMkDir($psOverride);
|
|
}
|
|
$base = str_replace('/', DIRECTORY_SEPARATOR, $this->getLocalPath() . 'override');
|
|
$iterator = new RecursiveDirectoryIterator($base, FilesystemIterator::SKIP_DOTS);
|
|
/** @var RecursiveIteratorIterator|\SplFileInfo[] $iterator */
|
|
$iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
|
|
$iterator->setMaxDepth(4);
|
|
foreach ($iterator as $k => $item) {
|
|
if (!$item->isDir()) {
|
|
continue;
|
|
}
|
|
$path = str_replace($base . DIRECTORY_SEPARATOR, '', $item->getPathname());
|
|
if (!@file_exists($psOverride . $path)) {
|
|
$this->safeMkDir($psOverride . $path);
|
|
@touch($psOverride . $path . DIRECTORY_SEPARATOR . '_do_not_remove');
|
|
}
|
|
}
|
|
if (!file_exists($psOverride . 'index.php')) {
|
|
Tools::copy($this->getLocalPath() . 'index.php', $psOverride . 'index.php');
|
|
}
|
|
}
|
|
}
|
|
public function replaceOverridesBeforeInstall()
|
|
{
|
|
if(version_compare(_PS_VERSION_,'1.7.7.0','<'))
|
|
{
|
|
$file_cart_content = Tools::file_get_contents(dirname(__FILE__).'/override/classes/Cart.php');
|
|
$search = array(
|
|
'public function getOrderTotal($withTaxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = false, bool $keepOrderPrices = false, $fee_payment = false, $only_cart = false, $custom = true)'
|
|
);
|
|
$replace = array(
|
|
'public function getOrderTotal($withTaxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = false, $keepOrderPrices = false, $fee_payment = false, $only_cart = false, $custom = true)'
|
|
);
|
|
$file_cart_content = str_replace($search,$replace,$file_cart_content);
|
|
file_put_contents(dirname(__FILE__).'/override/classes/Cart.php',$file_cart_content);
|
|
}
|
|
if(version_compare(_PS_VERSION_,'8.0','<'))
|
|
{
|
|
$file_cart_rule_content = Tools::file_get_contents(dirname(__FILE__).'/override/classes/CartRule.php');
|
|
$search = array(
|
|
'public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, CartCore $cart = null, $free_shipping_only = false, $highlight_only = false)'
|
|
);
|
|
$replace = array(
|
|
'public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null, $free_shipping_only = false, $highlight_only = false)'
|
|
);
|
|
$file_cart_rule_content = str_replace($search,$replace,$file_cart_rule_content);
|
|
file_put_contents(dirname(__FILE__).'/override/classes/CartRule.php',$file_cart_rule_content);
|
|
}
|
|
}
|
|
public function replaceOverridesAfterInstall()
|
|
{
|
|
if(version_compare(_PS_VERSION_,'1.7.7.0','<'))
|
|
{
|
|
$file_cart_content = Tools::file_get_contents(dirname(__FILE__).'/override/classes/Cart.php');
|
|
$search = array(
|
|
'public function getOrderTotal($withTaxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = false, $keepOrderPrices = false, $fee_payment = false, $only_cart = false, $custom = true)'
|
|
);
|
|
$replace= array(
|
|
'public function getOrderTotal($withTaxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = false, bool $keepOrderPrices = false, $fee_payment = false, $only_cart = false, $custom = true)'
|
|
);
|
|
$file_cart_content = str_replace($search,$replace,$file_cart_content);
|
|
file_put_contents(dirname(__FILE__).'/override/classes/Cart.php',$file_cart_content);
|
|
}
|
|
if(version_compare(_PS_VERSION_,'8.0','<'))
|
|
{
|
|
$file_cart_rule_content = Tools::file_get_contents(dirname(__FILE__).'/override/classes/CartRule.php');
|
|
$search = array(
|
|
'public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null, $free_shipping_only = false, $highlight_only = false)'
|
|
);
|
|
$replace = array(
|
|
'public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, CartCore $cart = null, $free_shipping_only = false, $highlight_only = false)'
|
|
);
|
|
$file_cart_rule_content = str_replace($search,$replace,$file_cart_rule_content);
|
|
file_put_contents(dirname(__FILE__).'/override/classes/CartRule.php',$file_cart_rule_content);
|
|
}
|
|
}
|
|
public function replaceOverridesOtherModuleAfterInstall()
|
|
{
|
|
if(Module::isInstalled('ets_payment_with_fee') && ($ets_payment_with_fee = Module::getInstanceByName('ets_payment_with_fee')) && method_exists($ets_payment_with_fee,'replaceOverridesAfterInstall'))
|
|
{
|
|
$ets_payment_with_fee->replaceOverridesAfterInstall();
|
|
}
|
|
if(Module::isInstalled('ets_extraoptions') && ($ets_extraoptions = Module::getInstanceByName('ets_extraoptions')) && method_exists($ets_extraoptions,'replaceOverridesAfterInstall'))
|
|
{
|
|
$ets_extraoptions->replaceOverridesAfterInstall();
|
|
}
|
|
if(Module::isInstalled('etsdiscountcombinations') && ($etsdiscountcombinations = Module::getInstanceByName('etsdiscountcombinations')) && method_exists($etsdiscountcombinations,'replaceOverridesAfterInstall'))
|
|
{
|
|
$etsdiscountcombinations->replaceOverridesAfterInstall();
|
|
}
|
|
}
|
|
public function replaceOverridesOtherModuleBeforeInstall()
|
|
{
|
|
if(Module::isInstalled('ets_payment_with_fee') && ($ets_payment_with_fee = Module::getInstanceByName('ets_payment_with_fee')) && method_exists($ets_payment_with_fee,'replaceOverridesBeforeInstall'))
|
|
{
|
|
$ets_payment_with_fee->replaceOverridesBeforeInstall();
|
|
}
|
|
if(Module::isInstalled('ets_extraoptions') && ($ets_extraoptions = Module::getInstanceByName('ets_extraoptions')) && method_exists($ets_extraoptions,'replaceOverridesBeforeInstall'))
|
|
{
|
|
$ets_extraoptions->replaceOverridesBeforeInstall();
|
|
}
|
|
if(Module::isInstalled('etsdiscountcombinations') && ($etsdiscountcombinations = Module::getInstanceByName('etsdiscountcombinations')) && method_exists($etsdiscountcombinations,'replaceOverridesBeforeInstall'))
|
|
{
|
|
$etsdiscountcombinations->replaceOverridesBeforeInstall();
|
|
}
|
|
}
|
|
public function uninstallOverrides(){
|
|
$this->replaceOverridesBeforeInstall();
|
|
$this->replaceOverridesOtherModuleBeforeInstall();
|
|
if(parent::uninstallOverrides())
|
|
{
|
|
require_once(dirname(__FILE__) . '/classes/OverrideUtil');
|
|
$class= 'Ets_pr_overrideUtil';
|
|
$method = 'restoreReplacedMethod';
|
|
call_user_func_array(array($class, $method),array($this));
|
|
$this->replaceOverridesAfterInstall();
|
|
$this->replaceOverridesOtherModuleAfterInstall();
|
|
return true;
|
|
}
|
|
$this->replaceOverridesAfterInstall();
|
|
$this->replaceOverridesOtherModuleAfterInstall();
|
|
return false;
|
|
}
|
|
public function installOverrides()
|
|
{
|
|
$this->replaceOverridesBeforeInstall();
|
|
$this->replaceOverridesOtherModuleBeforeInstall();
|
|
require_once(dirname(__FILE__) . '/classes/OverrideUtil');
|
|
$class= 'Ets_pr_overrideUtil';
|
|
$method = 'resolveConflict';
|
|
call_user_func_array(array($class, $method),array($this));
|
|
if(parent::installOverrides())
|
|
{
|
|
call_user_func_array(array($class, 'onModuleEnabled'),array($this));
|
|
$this->replaceOverridesAfterInstall();
|
|
$this->replaceOverridesOtherModuleAfterInstall();
|
|
return true;
|
|
}
|
|
$this->replaceOverridesAfterInstall();
|
|
$this->replaceOverridesOtherModuleAfterInstall();
|
|
return false;
|
|
}
|
|
public function enable($force_all = false)
|
|
{
|
|
if(!$force_all && Ets_pr_defines::checkEnableOtherShop($this->id) && $this->getOverrides() != null)
|
|
{
|
|
try {
|
|
$this->uninstallOverrides();
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
if($e)
|
|
{
|
|
//
|
|
}
|
|
}
|
|
}
|
|
$this->checkOverrideDir();
|
|
return parent::enable($force_all);
|
|
}
|
|
public function disable($force_all = false)
|
|
{
|
|
if(parent::disable($force_all))
|
|
{
|
|
if(!$force_all && Ets_pr_defines::checkEnableOtherShop($this->id))
|
|
{
|
|
if(property_exists('Tab','enabled') && method_exists($this, 'get') && $dispatcher = $this->get('event_dispatcher')){
|
|
/** @var \Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher|\Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
|
|
$dispatcher->addListener(\PrestaShopBundle\Event\ModuleManagementEvent::DISABLE, function (\PrestaShopBundle\Event\ModuleManagementEvent $event) {
|
|
Ets_pr_defines::activeTab($this->name);
|
|
});
|
|
}
|
|
if($this->getOverrides() != null)
|
|
{
|
|
try {
|
|
$this->installOverrides();
|
|
}
|
|
catch (Exception $e)
|
|
{
|
|
if($e)
|
|
{
|
|
//
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public static function registerPlugins(){
|
|
if(version_compare(_PS_VERSION_, '8.0.4', '>='))
|
|
{
|
|
$smarty = Context::getContext()->smarty->_getSmartyObj();
|
|
if(!isset($smarty->registered_plugins[ 'modifier' ][ 'implode' ]))
|
|
Context::getContext()->smarty->registerPlugin('modifier', 'implode', 'implode');
|
|
}
|
|
}
|
|
|
|
public function _getCacheId($params = null,$parentID = true)
|
|
{
|
|
$cacheId = $this->getCacheId($this->name);
|
|
$cacheId = str_replace($this->name, '', $cacheId);
|
|
$suffix ='';
|
|
if($params)
|
|
{
|
|
if(is_array($params))
|
|
$suffix .= '|'.implode('|',$params);
|
|
else
|
|
$suffix .= '|'.$params;
|
|
}
|
|
if($parentID && defined('_PS_ADMIN_DIR_') && isset($this->context->employee) && isset($this->context->employee->id))
|
|
{
|
|
$cacheId .='|'.$this->context->employee->id;
|
|
}
|
|
return $this->name . $suffix .($parentID ? $cacheId:'');
|
|
}
|
|
|
|
public function _clearSmartyCacheWhenUpdateSetting() {
|
|
$this->_clearSmartyFileCache();
|
|
}
|
|
public function _clearSmartyCacheWhenUpdatePrRule() {
|
|
$this->_clearSmartyFileCache();
|
|
$this->_clearSmartyCache('*', $this->_getCacheId(['rule_report'], false));
|
|
}
|
|
|
|
public function _clearSmartyCacheWhenUpdateConditionRule() {
|
|
$this->_clearSmartyFileCache();
|
|
$this->_clearSmartyCache('*', $this->_getCacheId(['condition'], false));
|
|
}
|
|
public function _clearSmartyCacheWhenUpdatePrCartRule() {
|
|
$this->_clearSmartyCache('*', $this->_getCacheId(['cart_voucher'], false));
|
|
}
|
|
public function _clearSmartyCacheWhenUpdatePrAction() {
|
|
$this->_clearSmartyCache('*', $this->_getCacheId(['cart_voucher'], false));
|
|
}
|
|
|
|
public function _clearSmartyFileCache() {
|
|
$this->_clearSmartyCache('*', $this->_getCacheId(['cart_voucher'], false));
|
|
$this->_clearSmartyCache('*', $this->_getCacheId(['gift_products'], false));
|
|
}
|
|
|
|
public function _clearSmartyCache($template,$cache_id = null, $compile_id = null)
|
|
{
|
|
if($cache_id===null)
|
|
$cache_id = $this->name;
|
|
if($template=='*')
|
|
{
|
|
Tools::clearCache(Context::getContext()->smarty,null, $cache_id, $compile_id);
|
|
}
|
|
else
|
|
{
|
|
Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath($template), $cache_id, $compile_id);
|
|
}
|
|
}
|
|
|
|
public function display($file, $template, $cache_id = null, $compile_id = null)
|
|
{
|
|
if (($overloaded = Module::_isTemplateOverloadedStatic(basename($file, '.php'), $template)) === null) {
|
|
return $this->l('No template found for module').' '.basename($file, '.php').(_PS_MODE_DEV_ ? ' (' . $template . ')' : '');
|
|
} else {
|
|
$this->smarty->assign([
|
|
'module_dir' => __PS_BASE_URI__ . 'modules/' . basename($file, '.php') . '/',
|
|
'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__) . 'modules/' . basename($file, '.php') . '/',
|
|
'allow_push' => isset($this->allow_push) ? $this->allow_push : false ,
|
|
]);
|
|
if ($cache_id !== null) {
|
|
Tools::enableCache();
|
|
}
|
|
if ($compile_id === null && method_exists($this,'getDefaultCompileId')) {
|
|
$compile_id = $this->getDefaultCompileId();
|
|
}
|
|
$result = $this->getCurrentSubTemplate($template, $cache_id, $compile_id);
|
|
if ($cache_id !== null) {
|
|
Tools::restoreCacheSettings();
|
|
}
|
|
$result = $result->fetch();
|
|
$this->resetCurrentSubTemplate($template, $cache_id, $compile_id);
|
|
return $result;
|
|
}
|
|
}
|
|
} |