Linux node5458.myfcloud.com 6.10.2-x86_64-linode165 #1 SMP PREEMPT_DYNAMIC Tue Jul 30 15:03:21 EDT 2024 x86_64
Apache
: 45.79.123.194 | : 18.225.234.56
16 Domain
7.4.33
addify5
shells.trxsecurity.org
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
Backdoor Scanner
Backdoor Create
Alfa Webshell
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
home /
addify5 /
.trash /
addifyfreegifts_OLD.1 /
[ HOME SHELL ]
Name
Size
Permission
Action
.pkexec
[ DIR ]
drwxr-xr-x
GCONV_PATH=.
[ DIR ]
drwxr-xr-x
classes
[ DIR ]
drwxrwxrwx
controllers
[ DIR ]
drwxrwxrwx
sql
[ DIR ]
drwxrwxrwx
translations
[ DIR ]
drwxrwxrwx
upgrade
[ DIR ]
drwxrwxrwx
views
[ DIR ]
drwxrwxrwx
.htaccess
247
B
-rwxrwxrwx
.mad-root
0
B
-rw-r--r--
addifyfreegifts.php
216.17
KB
-rwxrwxrwx
index.php
848
B
-rwxrwxrwx
logo.png
4.76
KB
-rwxrwxrwx
pwnkit
10.99
KB
-rwxr-xr-x
Delete
Unzip
Zip
${this.title}
Close
Code Editor : addifyfreegifts.php
<?php /** * 2024 Addify * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author Addify * @copyright 2024 Addify * @license http://opensource.org/licenses/afl-3.0.php */ if (!defined('_PS_VERSION_')) { exit; } require_once(_PS_MODULE_DIR_."addifyfreegifts/classes/AddifyfreegiftsModel.php"); require_once(_PS_MODULE_DIR_."addifyfreegifts/classes/AddifyfreegiftspredefinedModel.php"); require_once(_PS_MODULE_DIR_."addifyfreegifts/classes/AddifyfreegiftsPromotionModel.php"); class Addifyfreegifts extends Module { public function __construct() { $this->name = 'addifyfreegifts'; $this->tab = 'front_office_features'; $this->version = '1.3.0'; $this->author = 'Addify'; $this->need_instance = 0; $this->ps_versions_compliancy = [ 'min' => '1.7.0', 'max' => _PS_VERSION_ ]; $this->module_key = 'd4d4239ce863006ccdc584e19e8f3aca'; /** * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6) */ $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Addify Free Gifts'); $this->description = $this->l('Send Free gifts to your Customer.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get('addifyfreegifts_name')) { $this->warning = $this->l('No name provided'); } } public function install() { include_once($this->local_path.'/sql/install.php'); return parent::install() && $this->registerHook('header') && $this->registerHook('displayWrapperTop') && $this->registerHook('displayWrapperBottom') && $this->registerHook('actionCartSave') && $this->registerHook('displayExpressCheckout') && $this->registerHook('actionCartUpdateQuantityBefore') && $this->registerHook('actionObjectProductInCartDeleteBefore') && $this->registerHook('actionBeforeCartUpdateQty') && $this->registerHook('actionCustomerLogoutBefore'); } public function uninstall() { include_once($this->local_path.'/sql/uninstall.php'); return parent::uninstall() && $this->unregisterHook('header') && $this->unregisterHook('displayWrapperTop') && $this->unregisterHook('displayWrapperBottom') && $this->unregisterHook('actionCartSave') && $this->unregisterHook('displayExpressCheckout') && $this->unregisterHook('actionCartUpdateQuantityBefore') && $this->unregisterHook('actionObjectProductInCartDeleteBefore') && $this->unregisterHook('actionBeforeCartUpdateQty') && $this->unregisterHook('actionCustomerLogoutBefore') ; } public function getContent() { // if (Tools::isSubmit('add'.$this->name)) // { // return $this->renderForm(); // } // if (Tools::isSubmit('update'.$this->name)) // { // return $this->renderForm(); // } $notification = (int)Tools::getValue('notification'); if($notification == 1){ $this->context->controller->errors[] = $this->l('Object not found.'); } elseif ($notification == 2){ $this->context->controller->errors[] = $this->l('Status update failed.'); } elseif ($notification == 3){ $this->context->controller->confirmations[] = $this->l('Status updated successfully.'); } elseif ($notification == 4){ $this->context->controller->errors[] = $this->l('Rule cannot be deleted.'); } elseif ($notification == 5){ $this->context->controller->confirmations[] = $this->l('Rule deleted successfully.'); } elseif ($notification == 6){ $deleted = (int)Tools::getValue('del'); $this->context->controller->confirmations[] = sprintf($this->l('%s Rules deleted successfully.'), $deleted); } $this->postProcess(); $configUrl =$this->context->link->getAdminLink('AdminModules', true). '&configure=' . $this->name; $this->context->smarty->assign(array( 'configUrl' => $configUrl, )); if(Tools::isSubmit('Submitconfig'.$this->name)) { $this->processconfigSave(); } if(Tools::isSubmit('Submitconfig'.$this->name.'Promotion')) { $this->processConfigSavePromotion(); } if(Tools::isSubmit('Submitpost'.$this->name.'Promotion')) { $this->processSavePromotion(); } if(Tools::isSubmit('Submitpost'.$this->name)) { $this->processSave(); } if(Tools::isSubmit('Submitpost'.$this->name.'predefined')) { $this->processSavePreDefined(); } if (Tools::isSubmit('add'.$this->name) || Tools::isSubmit('update'.$this->name)) { $this->context->smarty->assign(array( 'render' => $this->renderForm(), )); return $this->display(__FILE__,'views/templates/admin/customrules.tpl'); } if (Tools::isSubmit('addPromotion'.$this->name) || Tools::isSubmit('update'.$this->name.'Promotion')) { $this->context->smarty->assign(array( 'renderpromotion' => $this->renderFormPromotion(), )); return $this->display(__FILE__,'views/templates/admin/promotionrules.tpl'); } if (Tools::isSubmit('addpredefined'.$this->name) || Tools::isSubmit('update'.$this->name.'predefined')) { $this->context->smarty->assign(array( 'renderpredefined' => $this->renderFormPreDefined(), )); return $this->display(__FILE__,'views/templates/admin/predefinedrules.tpl'); } if (Tools::isSubmit('customrules'.$this->name)) { $this->context->smarty->assign(array( 'render' => $this->renderList(), )); return $this->display(__FILE__,'views/templates/admin/customrules.tpl'); } if (Tools::isSubmit('predefinedrules'.$this->name)) { $this->context->smarty->assign(array( 'renderpredefined' => $this->renderListPreDefined(), )); return $this->display(__FILE__,'views/templates/admin/predefinedrules.tpl'); } if (Tools::isSubmit('promotions'.$this->name)) { $this->context->smarty->assign(array( 'renderConfigFormPromotion' => $this->renderConfigFormPromotion(), 'renderListPromotion' => $this->renderListPromotion(), )); return $this->display(__FILE__,'views/templates/admin/promotion.tpl'); } $this->context->smarty->assign(array( 'renderconfigForm' => $this->renderconfigForm(), )); return $this->display(__FILE__,'views/templates/admin/configure.tpl'); // return $this->renderconfigForm(). $this->renderList(); } protected function postProcess() { if (Tools::isSubmit('status'.$this->name)) { if (!AddifyfreegiftsModel::setStatus('rule_active', (int)Tools::getValue('id'))) { $notification = 2; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&customrulesaddifyfreegifts'); } else { $this->flushCache(); $notification = 3; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&customrulesaddifyfreegifts'); } } if (Tools::isSubmit('status'.$this->name.'predefined')) { if (!AddifyfreegiftspredefinedModel::setStatus('rule_active', (int)Tools::getValue('id'))) { $notification = 2; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&predefinedrulesaddifyfreegifts'); } else { $this->flushCache(); $notification = 3; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&predefinedrulesaddifyfreegifts'); } } if (Tools::isSubmit('status'.$this->name.'Promotion')) { if (!AddifyfreegiftsPromotionModel::setStatus('rule_active', (int)Tools::getValue('id'))) { $notification = 2; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&promotionsaddifyfreegifts'); } else { $this->flushCache(); $notification = 3; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&promotionsaddifyfreegifts'); } } if (Tools::isSubmit('delete'.$this->name)) { if (!Validate::isLoadedObject($id = new AddifyfreegiftsModel((int)Tools::getValue('id')))) { } else { if (!$id->delete()) { $notification = 4; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&customrulesaddifyfreegifts'); } else { $notification = 5; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&customrulesaddifyfreegifts'); } } } if (Tools::isSubmit('delete'.$this->name.'predefined')) { if (!Validate::isLoadedObject($id = new AddifyfreegiftspredefinedModel((int)Tools::getValue('id')))) { } else { if (!$id->delete()) { $notification = 4; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&predefinedrulesaddifyfreegifts'); } else { $notification = 5; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&predefinedrulesaddifyfreegifts'); } } } if (Tools::isSubmit('delete'.$this->name.'Promotion')) { if (!Validate::isLoadedObject($id = new AddifyfreegiftsPromotionModel((int)Tools::getValue('id')))) { } else { if (!$id->delete()) { $notification = 4; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&promotionsaddifyfreegifts'); } else { $notification = 5; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&promotionsaddifyfreegifts'); } } } if (Tools::isSubmit('submitBulkdelete'.$this->name)) { $postBox = Tools::getValue('addifyfreegiftsBox'); if (isset($postBox) && $postBox) { $deleted = 0; foreach ($postBox as $posts) { if (!Validate::isLoadedObject($AddifyfreegiftsModel = new AddifyfreegiftsModel((int)$posts))) { break; } else { if ($AddifyfreegiftsModel->delete()) { $deleted++; } } } if (count($this->context->controller->errors)) { $this->context->controller->errors; } else { $notification = 6; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&customrulesaddifyfreegifts'.'&del='.$deleted); } } } if (Tools::isSubmit('submitBulkdelete'.$this->name.'predefined')) { $postBox = Tools::getValue('addifyfreegiftspredefinedBox'); if (isset($postBox) && $postBox) { $deleted = 0; foreach ($postBox as $posts) { if (!Validate::isLoadedObject($AddifyfreegiftsModel = new AddifyfreegiftspredefinedModel((int)$posts))) { break; } else { if ($AddifyfreegiftsModel->delete()) { $deleted++; } } } if (count($this->context->controller->errors)) { $this->context->controller->errors; } else { $notification = 6; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&predefinedrulesaddifyfreegifts'.'&del='.$deleted); } } } if (Tools::isSubmit('submitBulkdelete'.$this->name.'Promotion')) { $postBox = Tools::getValue('addifyfreegiftsPromotionBox'); if (isset($postBox) && $postBox) { $deleted = 0; foreach ($postBox as $posts) { if (!Validate::isLoadedObject($AddifyfreegiftsModel = new AddifyfreegiftsPromotionModel((int)$posts))) { break; } else { if ($AddifyfreegiftsModel->delete()) { $deleted++; } } } if (count($this->context->controller->errors)) { $this->context->controller->errors; } else { $notification = 6; Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'¬ification='.$notification.'&promotionsaddifyfreegifts'.'&del='.$deleted); } } } } protected function renderListPreDefined() { $fields_list = array( 'id' => array( 'title' => $this->l('ID'), 'width' => 120, 'type' => 'int', 'search' => false, 'orderby' => false ), 'priority' => array( 'title' => $this->l('Priority'), 'width' => 120, 'type' => 'int', 'search' => false, 'orderby' => false ), 'title' => array( 'title' => $this->l('Title'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false ), 'rule_active' => array( 'title' => $this->l('Status'), 'width' => 140, 'active' => 'status', 'type' => 'bool', 'search' => false, 'orderby' => false, ), 'date_add' => array( 'title' => $this->l('Added Date'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false, ), 'date_update' => array( 'title' => $this->l('Updated Date'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false, ), ); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = false; $helper->identifier = 'id'; $helper->actions = array('edit', 'delete'); $helper->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected'), 'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?') ) ); $helper->listTotal = count(AddifyfreegiftspredefinedModel::getPosts()); $helper->show_toolbar = true; $helper->toolbar_btn['new'] = array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&addpredefined'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&predefinedrulesaddifyfreegifts', 'desc' => $this->l('Add new pre-defined rule') ); $helper->title = $this->l("Pre-Defined Rules"); $helper->table = "addifyfreegiftspredefined"; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&predefinedrulesaddifyfreegifts'; return $helper->generateList(AddifyfreegiftspredefinedModel::getPosts(), $fields_list); } public function renderFormPreDefined() { // Getting Categories $Category_array = Category::getCategories((int)Context::getContext()->language->id, true, false); $categories = array(); foreach ($Category_array as $category) { if ($category['id_category'] != 1) { $categories[] = array('name' => $category['name'], 'id' => $category['id_category']); } } // Getting Suppliers $Suppliers_array = Supplier::getSuppliers(false, $this->context->language->id, false, false, false, false); $Suppliers = array(); foreach ($Suppliers_array as $Supplier) { $Suppliers[] = array('name' => $Supplier['name'], 'id' => $Supplier['id_supplier']); } $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Add Pre-Defined Rule'), 'icon' => 'icon-cogs', ), 'tabs' => array( 'tab_1' => $this->l('Basic Settings'), 'tab_2' => $this->l('Rule Type'), 'tab_3' => $this->l('Gifts'), ), 'input' => array( array( 'type' => 'hidden', 'name' => 'id', 'tab' => 'tab_1', ), array( 'type' => 'switch', 'label' => $this->l('Rule Enable'), 'name' => 'rule_active', 'is_bool' => true, 'tab' => 'tab_1', 'desc' => $this->l('Enable/disable this rule.'), 'values' => array( array( 'id' => 'active_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'text', 'label' => $this->l('Title'), 'name' => 'title', 'tab' => 'tab_1', 'desc' => $this->l('Enter title for rule'), ), array( 'type' => 'text', 'label' => $this->l('Priority'), 'name' => 'priority', 'validate' => 'isInt', 'tab' => 'tab_1', 'required' => true, 'desc' => $this->l('Value must be numeric.'), ), array( 'type' => 'radio', 'label' => $this->l('Type'), 'name' => 'gift_type', 'tab' => 'tab_1', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'Automatic', 'value' => 0, 'label' => $this->l('Automatic Gifts') ), array( 'id' => 'Manual', 'value' => 1, 'label' => $this->l('Manual Gifts') ), ) ), array( 'type' => 'radio', 'label' => $this->l('Rule Type'), 'name' => 'rule_type', 'tab' => 'tab_2', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'buy1get1', 'value' => 0, 'label' => $this->l('Buy 1 Get 1 Free') ), array( 'id' => 'buy2get1', 'value' => 1, 'label' => $this->l('Buy 2 Get 1 Free') ), array( 'id' => 'buy3get1', 'value' => 2, 'label' => $this->l('Buy 3 Get 1 Free') ), ) ), array( 'type' => 'radio', 'label' => $this->l('User Buy Type'), 'name' => 'userbuy_type', 'tab' => 'tab_2', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'buyanyproduct', 'value' => 0, 'label' => $this->l('User Buys Any Product') ), array( 'id' => 'buyselectedproduct', 'value' => 1, 'label' => $this->l('User Buys Selected Product') ), array( 'id' => 'buyselectedcategory', 'value' => 2, 'label' => $this->l('User Buys Products from Selected Categories') ), array( 'id' => 'buyselectedcsupplier', 'value' => 3, 'label' => $this->l('User Buys Products from Selected Suppliers') ), ) ), array( 'type' => 'buy_products', 'label' => $this->l('Buy Products'), 'name' => 'buy_product', 'required' => true, 'tab' => 'tab_2', 'prefix' => '<i class="icon-search"></i>', 'hint' => $this->l('Search and add product(s) which you want, Users will get a gift when they buy these selected products.') ), array( 'type' => 'select', 'label' => $this->l('Categories'), 'name' => 'buy_category', 'id' => 'buy_category', 'required' => true, 'tab' => 'tab_2', 'multiple' => true, 'desc' => $this->l('Choose the Categories for whom you want, Users will get a free gift when they buy products from these categories.'), 'options' => array( 'query' => $categories, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'select', 'label' => $this->l('Suppliers'), 'name' => 'buy_supplier', 'id' => 'buy_supplier', 'required' => true, 'tab' => 'tab_2', 'multiple' => true, 'desc' => $this->l('Choose the supplier for whom you want, Users will get a gift when they buy products from these suppliers.'), 'options' => array( 'query' => $Suppliers, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'radio', 'label' => $this->l('Gift Type'), 'name' => 'giftbuy_type', 'tab' => 'tab_3', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'giftanyproduct', 'value' => 0, 'label' => $this->l('Gift Any Product') ), array( 'id' => 'giftselectedproduct', 'value' => 1, 'label' => $this->l('Gift Selected Product') ), array( 'id' => 'giftselectedcategory', 'value' => 2, 'label' => $this->l('Gift Any Product from Selected Category') ), array( 'id' => 'giftselectedcsupplier', 'value' => 3, 'label' => $this->l('Gift Any Product From Selected Suppliers') ), ) ), array( 'type' => 'gift_products', 'label' => $this->l('Gift Products'), 'name' => 'gift_product', 'required' => true, 'tab' => 'tab_3', 'prefix' => '<i class="icon-search"></i>', 'hint' => $this->l('Search and add product(s) which you want, Selected Products will be gifted. (Not add same product as buy product)') ), array( 'type' => 'select', 'label' => $this->l('Categories'), 'name' => 'gift_category', 'id' => 'gift_category', 'required' => true, 'tab' => 'tab_3', 'multiple' => true, 'desc' => $this->l('Choose the Categories for whom you want, Product from Selected Category will be gifted at random.'), 'options' => array( 'query' => $categories, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'select', 'label' => $this->l('Suppliers'), 'name' => 'gift_supplier', 'id' => 'gift_supplier', 'required' => true, 'tab' => 'tab_3', 'multiple' => true, 'desc' => $this->l('Choose the supplier for whom you want, Products from selected supplier will be gifted at random.'), 'options' => array( 'query' => $Suppliers, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'text', 'label' => $this->l('Quantity of free gift'), 'name' => 'gift_quantity', 'tab' => 'tab_3', 'required' => true, 'desc' => $this->l('Enter Quantity'), ), array( 'type' => 'date', 'label' => $this->l('Rule Validity From'), 'name' => 'Validity_from', 'tab' => 'tab_1', 'desc' => $this->l('Enter minimum date.'), ), array( 'type' => 'date', 'label' => $this->l('Rule Validity To'), 'name' => 'Validity_to', 'tab' => 'tab_1', 'desc' => $this->l('Enter maximum date.'), ), ), 'submit' => array( 'title' => $this->l('Save'), ), 'buttons' => array( 'cancel' => array( 'title' => $this->l('Cancel'), 'class' => 'btn btn-default', 'icon' => 'process-icon-cancel', 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&predefinedrulesaddifyfreegifts', ), ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->show_cancel_button = false; $helper->table = 'addifyfreegiftspredefined'; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = 'id'; $helper->submit_action = 'Submitpost'.$this->name.'predefined'; $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&predefinedrulesaddifyfreegifts'; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->back_url = $helper->currentIndex.'&token='.$helper->token; $buy_products = array(); $gift_products = array(); if (Tools::getValue('id')) { $hidepriceBlock_2 = new AddifyfreegiftspredefinedModel((int)Tools::getValue('id')); $post_accessories_tab_2 = explode(',', $hidepriceBlock_2->gift_product); foreach ($post_accessories_tab_2 as $id_pro) { if (!$this->haveThisProduct($id_pro, $gift_products) && $product_2 = AddifyfreegiftspredefinedModel::getProductById($id_pro)) { $gift_products[] = $product_2; } } } else { $gift_products = array(); } if ($post_accessories_2 = Tools::getValue('inputRestrictedProducts_2')) { $post_accessories_tab_2 = explode('-', $post_accessories_2); foreach ($post_accessories_tab_2 as $id_pro) { if (!$this->haveThisProduct($id_pro, $gift_products) && $product_2 = AddifyfreegiftspredefinedModel::getProductById($id_pro)) { $gift_products[] = $product_2; } } } if (Tools::getValue('id')) { $hidepriceBlock_3 = new AddifyfreegiftspredefinedModel((int)Tools::getValue('id')); $post_accessories_tab_3 = explode(',', $hidepriceBlock_3->buy_product); foreach ($post_accessories_tab_3 as $id_pro) { if (!$this->haveThisProduct($id_pro, $buy_products) && $product_3 = AddifyfreegiftspredefinedModel::getProductById($id_pro)) { $buy_products[] = $product_3; } } } else { $buy_products = array(); } if ($post_accessories_3 = Tools::getValue('inputRestrictedProducts_3')) { $post_accessories_tab_3 = explode('-', $post_accessories_3); foreach ($post_accessories_tab_3 as $id_pro) { if (!$this->haveThisProduct($id_pro, $buy_products) && $product_3 = AddifyfreegiftspredefinedModel::getProductById($id_pro)) { $buy_products[] = $product_3; } } } $helper->tpl_vars = array( 'fields_value' => $this->getFormValuesPreDefined(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, 'gift_products' => $gift_products, 'buy_products' => $buy_products, 'context_link' => Context::getContext()->link, ); return $helper->generateForm(array($fields_form)); } protected function getFormValuesPreDefined() { $fields_value = array(); if (Tools::getValue('id') && (Tools::isSubmit('Submitpost'.$this->name.'predefined') === false)) { $postBlock = new AddifyfreegiftspredefinedModel((int)Tools::getValue('id')); $fields_value['id'] = $postBlock->id; $fields_value['title'] = $postBlock->title; $fields_value['rule_active'] = $postBlock->rule_active; $fields_value['priority'] = $postBlock->priority; $fields_value['buy_product'] = explode(',', $postBlock->buy_product); $fields_value['buy_category[]'] = explode(",",$postBlock->buy_category); $fields_value['gift_type'] = $postBlock->gift_type; $fields_value['rule_type'] = $postBlock->rule_type; $fields_value['userbuy_type'] = $postBlock->userbuy_type; $fields_value['buy_supplier[]'] = explode(',', $postBlock->buy_supplier); $fields_value['gift_product'] = explode(',', $postBlock->gift_product); $fields_value['gift_category[]'] = explode(',', $postBlock->gift_category); $fields_value['gift_supplier[]'] = explode(',', $postBlock->gift_supplier); $fields_value['giftbuy_type'] = $postBlock->giftbuy_type; $fields_value['gift_quantity'] = $postBlock->gift_quantity; $fields_value['Validity_from'] = $postBlock->Validity_from; $fields_value['Validity_to'] = $postBlock->Validity_to; } else { $fields_value['id'] = Tools::getValue('id'); $fields_value['title'] = Tools::getValue('title'); $fields_value['priority'] = Tools::getValue('priority'); $fields_value['rule_active'] = Tools::getValue('rule_active'); $fields_value['gift_type'] = Tools::getValue('gift_type'); $fields_value['rule_type'] = Tools::getValue('rule_type'); $fields_value['userbuy_type'] = Tools::getValue('userbuy_type'); $fields_value['giftbuy_type'] = Tools::getValue('giftbuy_type'); $fields_value['gift_quantity'] = Tools::getValue('gift_quantity'); $fields_value['Validity_from'] = Tools::getValue('Validity_from'); $fields_value['Validity_to'] = Tools::getValue('Validity_to'); if (!Tools::getValue('gift_supplier')) { $fields_value['gift_supplier[]'] = Tools::getValue('gift_supplier[]'); } else { $fields_value['gift_supplier'] = implode(",",Tools::getValue('gift_supplier')); } if (!Tools::getValue('buy_supplier')) { $fields_value['buy_supplier[]'] = Tools::getValue('buy_supplier[]'); } else { $fields_value['buy_supplier'] = implode(",",Tools::getValue('buy_supplier')); } if (!Tools::getValue('buy_category')) { $fields_value['buy_category[]'] = Tools::getValue('buy_category[]'); } else { $fields_value['buy_category'] = implode(",",Tools::getValue('buy_category')); } if (!Tools::getValue('gift_product')) { $fields_value['gift_product'] = Tools::getValue('gift_product'); } else { $fields_value['gift_product'] = implode(',', Tools::getValue('gift_product')); } if (!Tools::getValue('gift_category')) { $fields_value['gift_category[]'] = Tools::getValue('gift_category[]'); } else { $fields_value['gift_category'] = implode(',', Tools::getValue('gift_category')); } if (!Tools::getValue('buy_product')) { $fields_value['buy_product'] = Tools::getValue('buy_product'); } else { $fields_value['buy_product'] = implode(',', Tools::getValue('buy_product')); } } return $fields_value; } protected function processSavePreDefined() { $call_back = 'add'; $form_values = $this->getFormValuesPreDefined(); if (!isset($form_values) && !$form_values) { return $this->context->controller->errors[] = $this->l('Empty post values.'); } if (($form_values['priority']) == 0) { $this->context->controller->errors[] = $this->l('Priority value is not valid.'); } if (!is_numeric($form_values['priority'])) { $this->context->controller->errors[] = $this->l('Priority value is not valid.'); } if (($form_values['gift_quantity']) == 0) { $this->context->controller->errors[] = $this->l('Gift Quantity value is not valid.'); } if (!is_numeric($form_values['gift_quantity'])) { $this->context->controller->errors[] = $this->l('Gift Quantity value is not valid.'); } if (count($this->context->controller->errors)) { return $this->context->controller->errors; } $dt = date("Y-m-d h:i:s"); if (($id = Tools::getValue('id'))) { $call_back = 'update'; $AddifyfreegiftsModel= new AddifyfreegiftspredefinedModel((int)$id); $AddifyfreegiftsModel->date_update = $dt; } else { $AddifyfreegiftsModel = new AddifyfreegiftspredefinedModel(); $AddifyfreegiftsModel->date_add = $dt; } $AddifyfreegiftsModel->title = $form_values['title']; $AddifyfreegiftsModel->priority = $form_values['priority']; $AddifyfreegiftsModel->rule_active = $form_values['rule_active']; $AddifyfreegiftsModel->buy_product = $form_values['buy_product']; $AddifyfreegiftsModel->buy_category = $form_values['buy_category']; $AddifyfreegiftsModel->buy_supplier = $form_values['buy_supplier']; $AddifyfreegiftsModel->gift_type = $form_values['gift_type']; $AddifyfreegiftsModel->rule_type = $form_values['rule_type']; $AddifyfreegiftsModel->userbuy_type = $form_values['userbuy_type']; $AddifyfreegiftsModel->giftbuy_type = $form_values['giftbuy_type']; $AddifyfreegiftsModel->Validity_from = $form_values['Validity_from']; $AddifyfreegiftsModel->Validity_to = $form_values['Validity_to']; $AddifyfreegiftsModel->gift_quantity = $form_values['gift_quantity']; $AddifyfreegiftsModel->gift_supplier = $form_values['gift_supplier']; $AddifyfreegiftsModel->gift_product = $form_values['gift_product']; $AddifyfreegiftsModel->gift_category = $form_values['gift_category']; if (!call_user_func(array($AddifyfreegiftsModel, $call_back))) { $this->context->controller->errors = sprintf($this->l('Something went wrong while performing operation %s'), $call_back); } else { $this->flushCache(); if($call_back=='add') { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'&predefinedrulesaddifyfreegifts'); } else { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'&predefinedrulesaddifyfreegifts'); } } } protected function renderList() { $fields_list = array( 'id' => array( 'title' => $this->l('ID'), 'width' => 120, 'type' => 'int', 'search' => false, 'orderby' => false ), 'priority' => array( 'title' => $this->l('Priority'), 'width' => 120, 'type' => 'int', 'search' => false, 'orderby' => false ), 'title' => array( 'title' => $this->l('Title'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false ), 'rule_active' => array( 'title' => $this->l('Status'), 'width' => 140, 'active' => 'status', 'type' => 'bool', 'search' => false, 'orderby' => false, ), 'date_add' => array( 'title' => $this->l('Added Date'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false, ), 'date_update' => array( 'title' => $this->l('Updated Date'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false, ), ); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = false; $helper->identifier = 'id'; $helper->actions = array('edit', 'delete'); $helper->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected'), 'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?') ) ); $helper->listTotal = count(AddifyfreegiftsModel::getPosts()); $helper->show_toolbar = true; $helper->toolbar_btn['new'] = array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&customrulesaddifyfreegifts', 'desc' => $this->l('Add new rule') ); $helper->title = $this->l("Rules"); $helper->table = "addifyfreegifts"; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&customrulesaddifyfreegifts'; return $helper->generateList(AddifyfreegiftsModel::getPosts(), $fields_list); } public function renderForm() { // Getting Categories $Category_array = Category::getCategories((int)Context::getContext()->language->id, true, false); $categories = array(); foreach ($Category_array as $category) { if ($category['id_category'] != 1) { $categories[] = array('name' => $category['name'], 'id' => $category['id_category']); } } // Getting Suppliers $Suppliers_array = Supplier::getSuppliers(false, $this->context->language->id, false, false, false, false); $Suppliers = array(); foreach ($Suppliers_array as $Supplier) { $Suppliers[] = array('name' => $Supplier['name'], 'id' => $Supplier['id_supplier']); } $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Add Rule'), 'icon' => 'icon-cogs', ), 'tabs' => array( 'tab_1' => $this->l('Basic Settings'), 'tab_2' => $this->l('Rule Type'), 'tab_3' => $this->l('Gifts'), ), 'input' => array( array( 'type' => 'hidden', 'name' => 'id', 'tab' => 'tab_1', ), array( 'type' => 'switch', 'label' => $this->l('Rule Enable'), 'name' => 'rule_active', 'tab' => 'tab_1', 'is_bool' => true, 'desc' => $this->l('Enable/disable this rule.'), 'values' => array( array( 'id' => 'active_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'text', 'label' => $this->l('Title'), 'tab' => 'tab_1', 'name' => 'title', 'desc' => $this->l('Enter title for rule'), ), array( 'type' => 'text', 'label' => $this->l('Priority'), 'name' => 'priority', 'tab' => 'tab_1', 'validate' => 'isInt', 'required' => true, 'desc' => $this->l('Value must be numeric.'), ), array( 'type' => 'group', 'label' => $this->l('Groups'), 'name' => 'groupBox[]', 'tab' => 'tab_1', 'values' => Group::getGroups(Context::getContext()->language->id), 'info_introduction' => $this->l('You now have three default customer groups.'), 'desc' => $this->l('Select customer group(s) which you want to show free gifts.'), ), array( 'type' => 'radio', 'label' => $this->l('Gift Type'), 'name' => 'gift_type', 'tab' => 'tab_1', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'Automatic', 'value' => 0, 'label' => $this->l('Automatic Gifts') ), array( 'id' => 'Manual', 'value' => 1, 'label' => $this->l('Manual Gifts') ), // array( // 'id' => 'Buy_one', // 'value' => 2, // 'label' => $this->l('Buy X Get Y(Buy One Get One)') // ), ) ), array( 'type' => 'radio', 'label' => $this->l('Rule Type'), 'name' => 'condition_option', 'id' => 'custom_rule_type', 'tab' => 'tab_2', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'buyXgetY', 'value' => 0, 'label' => $this->l('Buy X Get Y') ), array( 'id' => 'basedcartvalue', 'value' => 1, 'label' => $this->l('Based on cart value') ), ) ), array( 'type' => 'text', 'label' => $this->l('Buy X'), 'name' => 'buy_x', 'id' => 'custom_buy_x', 'tab' => 'tab_2', // 'desc' => $this->l('Enter Quantity'), ), array( 'type' => 'text', 'label' => $this->l('Get Y'), 'name' => 'get_Y', 'id' => 'custom_get_y', 'tab' => 'tab_3', // 'desc' => $this->l('Enter Quantity'), ), array( 'type' => 'text', 'label' => $this->l('Buy Quantity'), 'name' => 'buy_quantity', 'tab' => 'tab_2', 'desc' => $this->l('Enter Quantity'), ), array( 'type' => 'radio', 'label' => $this->l('User Buy Type'), 'name' => 'userbuy_type', 'id' => 'custom_userbuy_type', 'tab' => 'tab_2', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'custombuyselectedproduct', 'value' => 0, 'label' => $this->l('User Buys Selected Product') ), array( 'id' => 'custombuyanyproduct', 'value' => 1, 'label' => $this->l('User Buys Any Product') ), array( 'id' => 'custombuyselectedcategory', 'value' => 2, 'label' => $this->l('User Buys Products from Selected Categories') ), array( 'id' => 'custombuyselectedcsupplier', 'value' => 3, 'label' => $this->l('User Buys Products from Selected Suppliers') ), ) ), array( 'type' => 'select', 'label' => $this->l('Categories'), 'name' => 'buy_category', 'id' => 'custom_buy_category', 'tab' => 'tab_2', 'required' => true, 'multiple' => true, 'desc' => $this->l('Choose the Categories for whom you want, Users will get a free gift when they buy X products from these categories only'), 'options' => array( 'query' => $categories, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'select', 'label' => $this->l('Suppliers'), 'name' => 'buy_supplier', 'id' => 'custom_buy_supplier', 'required' => true, 'tab' => 'tab_2', 'multiple' => true, 'desc' => $this->l('Choose the supplier for whom you want, User will get a gift when buys X products from these suppliers.'), 'options' => array( 'query' => $Suppliers, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'radio', 'label' => $this->l('Gift Type'), 'name' => 'giftbuy_type', 'id' => 'custom_giftbuy_type', 'tab' => 'tab_3', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'customgiftselectedproduct', 'value' => 0, 'label' => $this->l('Gift Selected Product') ), array( 'id' => 'customgiftanyproduct', 'value' => 1, 'label' => $this->l('Gift Any Product') ), array( 'id' => 'customgiftselectedcategory', 'value' => 2, 'label' => $this->l('Gift Any Product from Selected Category') ), array( 'id' => 'customgiftselectedcsupplier', 'value' => 3, 'label' => $this->l('Gift Any Product From Selected Suppliers') ), ) ), array( 'type' => 'select', 'label' => $this->l('Categories'), 'name' => 'gift_category', 'id' => 'custom_gift_category', 'required' => true, 'tab' => 'tab_3', 'multiple' => true, 'desc' => $this->l('Choose the Categories for whom you want, Product from Selected Category will be gifted at random.'), 'options' => array( 'query' => $categories, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'select', 'label' => $this->l('Suppliers'), 'name' => 'gift_supplier', 'id' => 'custom_gift_supplier', 'required' => true, 'tab' => 'tab_3', 'multiple' => true, 'desc' => $this->l('Choose the supplier for whom you want, Products from selected supplier will be gifted at random.'), 'options' => array( 'query' => $Suppliers, 'id' => 'id', 'name' => 'name', ), ), // array( // 'type' => 'radio', // 'label' => $this->l('Buy Type'), // 'name' => 'buy_all_products', // 'desc' =>$this->l('Select option which you want'), // 'values' => array( // array( // 'id' => 'buy_all_products', // 'value' => 0, // 'label' => $this->l('Buy all Products'), // ), // array( // 'id' => 'buy_any_product', // 'value' => 1, // 'label' => $this->l('Buy any Product'), // ), // ), // ), array( 'type' => 'products', 'label' => $this->l('Buy products'), 'name' => 'product', 'required' => true, 'tab' => 'tab_2', 'prefix' => '<i class="icon-search"></i>', 'hint' => $this->l('Search and add product(s) which you want, User will get a gift when buys any X of these products') ), array( 'type' => 'text', 'label' => $this->l('Total Cart Amount'), 'name' => 'cart_amount', 'tab' => 'tab_2', 'desc' => $this->l('Enter Total Cart Amount, User will get gift when cart value reaches this value'), ), array( 'type' => 'config_product', 'label' => $this->l('Gift Products'), 'required' => true, 'name' => 'select_product', 'tab' => 'tab_3', 'prefix' => '<i class="icon-search"></i>', 'hint' => $this->l('Search and add product(s) which you want to add for free gifts (Not add same product as buy product).') ), array( 'type' => 'text', 'label' => $this->l('Quantity'), 'name' => 'get_quantity', 'tab' => 'tab_3', 'required' => true, 'desc' => $this->l('Enter Quantity'), ), array( 'type' => 'date', 'label' => $this->l('Rule Validity From'), 'name' => 'Validity_from', 'tab' => 'tab_1', 'desc' => $this->l('Enter minimum date.'), ), array( 'type' => 'date', 'label' => $this->l('Rule Validity To'), 'name' => 'Validity_to', 'tab' => 'tab_1', 'desc' => $this->l('Enter maximum date.'), ), ), 'submit' => array( 'title' => $this->l('Save'), ), 'buttons' => array( 'cancel' => array( 'title' => $this->l('Cancel'), 'class' => 'btn btn-default', 'icon' => 'process-icon-cancel', 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&customrulesaddifyfreegifts', ), ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->show_cancel_button = false; $helper->table = 'addifyfreegifts'; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = 'id'; $helper->submit_action = 'Submitpost'.$this->name; $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&customrulesaddifyfreegifts'; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->back_url = $helper->currentIndex.'&token='.$helper->token; $products = array(); $config_product = array(); if (Tools::getValue('id')) { $hidepriceBlock = new AddifyfreegiftsModel((int)Tools::getValue('id')); $post_accessories_tab = explode(',', $hidepriceBlock->product); foreach ($post_accessories_tab as $id_product) { if (!$this->haveThisProduct($id_product, $products) && $product = AddifyfreegiftsModel::getProductById($id_product)) { $products[] = $product; } } } else { $products = array(); } if ($post_accessories = Tools::getValue('inputRestrictedProducts')) { $post_accessories_tab = explode('-', $post_accessories); foreach ($post_accessories_tab as $id_product) { if (!$this->haveThisProduct($id_product, $products) && $product = AddifyfreegiftsModel::getProductById($id_product)) { $products[] = $product; } } } if (Tools::getValue('id')) { $hidepriceBlock_1 = new AddifyfreegiftsModel((int)Tools::getValue('id')); $post_accessories_tab_1 = explode(',', $hidepriceBlock_1->select_product); foreach ($post_accessories_tab_1 as $id_pro) { if (!$this->haveThisProduct($id_pro, $config_product) && $product_1 = AddifyfreegiftsModel::getProductById($id_pro)) { $config_product[] = $product_1; } } } else { $config_product = array(); } if ($post_accessories_1 = Tools::getValue('inputRestrictedProducts_1')) { $post_accessories_tab_1 = explode('-', $post_accessories_1); foreach ($post_accessories_tab_1 as $id_pro) { if (!$this->haveThisProduct($id_pro, $config_product) && $product_1 = AddifyfreegiftsModel::getProductById($id_pro)) { $config_product[] = $product_1; } } } $helper->tpl_vars = array( 'fields_value' => $this->getFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, 'products' => $products, 'config_product' => $config_product, 'context_link' => Context::getContext()->link, ); return $helper->generateForm(array($fields_form)); } public function haveThisProduct($id_product, $products) { foreach ($products as $product) { if ((int)$product['id_product'] == (int)$id_product) { return true; } } return false; } protected function getFormValues() { $fields_value = array(); if (Tools::getValue('id') && (Tools::isSubmit('Submitpost'.$this->name) === false)) { $postBlock = new AddifyfreegiftsModel((int)Tools::getValue('id')); $fields_value['id'] = $postBlock->id; $fields_value['title'] = $postBlock->title; $fields_value['rule_active'] = $postBlock->rule_active; $fields_value['priority'] = $postBlock->priority; $fields_value['product'] = explode(',', $postBlock->product); $fields_value['groupBox'] = explode(",",$postBlock->groupBox); $fields_value['gift_type'] = $postBlock->gift_type; $fields_value['get_quantity'] = $postBlock->get_quantity; $fields_value['buy_quantity'] = $postBlock->buy_quantity; $fields_value['cart_amount'] = $postBlock->cart_amount; $fields_value['Validity_from'] = $postBlock->Validity_from; $fields_value['Validity_to'] = $postBlock->Validity_to; $fields_value['select_product'] = explode(',', $postBlock->select_product); $fields_value['buy_all_products'] = $postBlock->buy_all_products; $fields_value['condition_option'] = $postBlock->condition_option; $fields_value['userbuy_type'] = $postBlock->userbuy_type; $fields_value['buy_category[]'] = explode(",",$postBlock->buy_category); $fields_value['buy_supplier[]'] = explode(',', $postBlock->buy_supplier); $fields_value['gift_supplier[]'] = explode(',', $postBlock->gift_supplier); $fields_value['gift_category[]'] = explode(',', $postBlock->gift_category); $fields_value['giftbuy_type'] = $postBlock->giftbuy_type; $fields_value['buy_x'] = $postBlock->buy_x; $fields_value['get_Y'] = $postBlock->get_Y; $accessed_groups_ids= $fields_value['groupBox']; } else { $fields_value['id'] = Tools::getValue('id'); $fields_value['title'] = Tools::getValue('title'); $fields_value['priority'] = Tools::getValue('priority'); $fields_value['rule_active'] = Tools::getValue('rule_active'); $fields_value['gift_type'] = Tools::getValue('gift_type'); $fields_value['get_quantity'] = Tools::getValue('get_quantity'); $fields_value['buy_quantity'] = Tools::getValue('buy_quantity'); $fields_value['cart_amount'] = Tools::getValue('cart_amount'); $fields_value['Validity_from'] = Tools::getValue('Validity_from'); $fields_value['Validity_to'] = Tools::getValue('Validity_to'); $fields_value['buy_all_products'] = Tools::getValue('buy_all_products'); $fields_value['condition_option'] = Tools::getValue('condition_option'); $fields_value['userbuy_type'] = Tools::getValue('userbuy_type'); $fields_value['giftbuy_type'] = Tools::getValue('giftbuy_type'); $fields_value['buy_x'] = Tools::getValue('buy_x'); $fields_value['get_Y'] = Tools::getValue('get_Y'); if (!Tools::getValue('groupBox')) { $fields_value['groupBox'] = Tools::getValue('groupBox'); } else { $fields_value['groupBox'] = implode(",",Tools::getValue('groupBox')); } if (!Tools::getValue('select_product')) { $fields_value['select_product'] = Tools::getValue('select_product'); } else { $fields_value['select_product'] = implode(',', Tools::getValue('select_product')); } if (!Tools::getValue('product')) { $fields_value['product'] = Tools::getValue('product'); } else { $fields_value['product'] = implode(',', Tools::getValue('product')); } if (!Tools::getValue('gift_supplier')) { $fields_value['gift_supplier[]'] = Tools::getValue('gift_supplier[]'); } else { $fields_value['gift_supplier'] = implode(",",Tools::getValue('gift_supplier')); } if (!Tools::getValue('buy_supplier')) { $fields_value['buy_supplier[]'] = Tools::getValue('buy_supplier[]'); } else { $fields_value['buy_supplier'] = implode(",",Tools::getValue('buy_supplier')); } if (!Tools::getValue('buy_category')) { $fields_value['buy_category[]'] = Tools::getValue('buy_category[]'); } else { $fields_value['buy_category'] = implode(",",Tools::getValue('buy_category')); } if (!Tools::getValue('gift_category')) { $fields_value['gift_category[]'] = Tools::getValue('gift_category[]'); } else { $fields_value['gift_category'] = implode(',', Tools::getValue('gift_category')); } $accessed_groups_ids = Tools::getValue('groupBox'); } if (!is_array($accessed_groups_ids)) { $accessed_groups_ids = array(); } // Added values of object Group $groups = Group::getGroups($this->context->language->id); if (empty($accessed_groups_ids)) { $preselected = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP')); $accessed_groups_ids = array_merge($accessed_groups_ids, $preselected); } foreach ($groups as $group) { $fields_value['groupBox_'.$group['id_group']] = (isset($accessed_groups_ids) && $accessed_groups_ids)? Tools::getValue('groupBox_'.$group['id_group'], (in_array($group['id_group'], $accessed_groups_ids))) : true; } return $fields_value; } protected function processSave() { $call_back = 'add'; $form_values = $this->getFormValues(); if (!isset($form_values) && !$form_values) { return $this->context->controller->errors[] = $this->l('Empty post values.'); } if (($form_values['priority']) == 0) { $this->context->controller->errors[] = $this->l('Priority value is not valid.'); } if (!is_numeric($form_values['priority'])) { $this->context->controller->errors[] = $this->l('Priority value is not valid.'); } if (!empty($form_values['cart_amount'])) { if (!is_numeric($form_values['cart_amount'])) { $this->context->controller->errors[] = $this->l('Total cart amount value is not valid.'); } } if (!empty($form_values['buy_x'])) { if (!is_numeric($form_values['buy_x'])) { $this->context->controller->errors[] = $this->l('Buy X value is not valid.'); } if (($form_values['buy_x']) == 0) { $this->context->controller->errors[] = $this->l('Buy X value is not valid.'); } } if (!empty($form_values['get_Y'])) { if (!is_numeric($form_values['get_Y'])) { $this->context->controller->errors[] = $this->l('Get Y value is not valid.'); } if (($form_values['get_Y']) == 0) { $this->context->controller->errors[] = $this->l('Get Y value is not valid.'); } } if (!empty($form_values['Validity_from'])) { if (!Validate::isDate($form_values['Validity_from'])) { $this->context->controller->errors[] = $this->l('Validity-from Date is not valid.'); } } if (!empty($form_values['Validity_to'])) { if (!Validate::isDate($form_values['Validity_to'])) { $this->context->controller->errors[] = $this->l('Validity-to Date is not valid.'); } } if (($form_values['get_quantity']) == 0) { $this->context->controller->errors[] = $this->l('Gift Quantity value is not valid.'); } if (!is_numeric($form_values['get_quantity'])) { $this->context->controller->errors[] = $this->l('Gift Quantity value is not valid.'); } if (!empty($form_values['buy_quantity'])) { if (($form_values['buy_quantity']) == 0) { $this->context->controller->errors[] = $this->l('Buy Quantity value is not valid.'); } if (!is_numeric($form_values['buy_quantity'])) { $this->context->controller->errors[] = $this->l('Buy Quantity value is not valid.'); } } if (count($this->context->controller->errors)) { return $this->context->controller->errors; } $dt = date("Y-m-d h:i:s"); if (($id = Tools::getValue('id'))) { $call_back = 'update'; $AddifyfreegiftsModel= new AddifyfreegiftsModel((int)$id); $AddifyfreegiftsModel->title = $form_values['title']; $AddifyfreegiftsModel->priority = $form_values['priority']; $AddifyfreegiftsModel->rule_active = $form_values['rule_active']; $AddifyfreegiftsModel->product = $form_values['product']; $AddifyfreegiftsModel->date_update = $dt; $AddifyfreegiftsModel->groupBox = $form_values['groupBox']; $AddifyfreegiftsModel->gift_type = $form_values['gift_type']; $AddifyfreegiftsModel->get_quantity = $form_values['get_quantity']; $AddifyfreegiftsModel->buy_quantity = $form_values['buy_quantity']; $AddifyfreegiftsModel->cart_amount = $form_values['cart_amount']; $AddifyfreegiftsModel->Validity_from = $form_values['Validity_from']; $AddifyfreegiftsModel->Validity_to = $form_values['Validity_to']; $AddifyfreegiftsModel->select_product = $form_values['select_product']; $AddifyfreegiftsModel->buy_all_products = $form_values['buy_all_products']; $AddifyfreegiftsModel->condition_option = $form_values['condition_option']; $AddifyfreegiftsModel->userbuy_type = $form_values['userbuy_type']; $AddifyfreegiftsModel->giftbuy_type = $form_values['giftbuy_type']; $AddifyfreegiftsModel->gift_supplier = $form_values['gift_supplier']; $AddifyfreegiftsModel->gift_category = $form_values['gift_category']; $AddifyfreegiftsModel->buy_category = $form_values['buy_category']; $AddifyfreegiftsModel->buy_supplier = $form_values['buy_supplier']; $AddifyfreegiftsModel->buy_x = $form_values['buy_x']; $AddifyfreegiftsModel->get_Y = $form_values['get_Y']; } else { $AddifyfreegiftsModel = new AddifyfreegiftsModel(); $AddifyfreegiftsModel->title = $form_values['title']; $AddifyfreegiftsModel->priority = $form_values['priority']; $AddifyfreegiftsModel->rule_active = $form_values['rule_active']; $AddifyfreegiftsModel->product = $form_values['product']; $AddifyfreegiftsModel->date_add = $dt; $AddifyfreegiftsModel->groupBox = $form_values['groupBox']; $AddifyfreegiftsModel->gift_type = $form_values['gift_type']; $AddifyfreegiftsModel->get_quantity = $form_values['get_quantity']; $AddifyfreegiftsModel->buy_quantity = $form_values['buy_quantity']; $AddifyfreegiftsModel->cart_amount = $form_values['cart_amount']; $AddifyfreegiftsModel->Validity_from = $form_values['Validity_from']; $AddifyfreegiftsModel->Validity_to = $form_values['Validity_to']; $AddifyfreegiftsModel->select_product = $form_values['select_product']; $AddifyfreegiftsModel->buy_all_products = $form_values['buy_all_products']; $AddifyfreegiftsModel->condition_option = $form_values['condition_option']; $AddifyfreegiftsModel->userbuy_type = $form_values['userbuy_type']; $AddifyfreegiftsModel->giftbuy_type = $form_values['giftbuy_type']; $AddifyfreegiftsModel->gift_supplier = $form_values['gift_supplier']; $AddifyfreegiftsModel->gift_category = $form_values['gift_category']; $AddifyfreegiftsModel->buy_category = $form_values['buy_category']; $AddifyfreegiftsModel->buy_supplier = $form_values['buy_supplier']; $AddifyfreegiftsModel->buy_x = $form_values['buy_x']; $AddifyfreegiftsModel->get_Y = $form_values['get_Y']; } if (!call_user_func(array($AddifyfreegiftsModel, $call_back))) { $this->context->controller->errors = sprintf($this->l('Something went wrong while performing operation %s'), $call_back); } else { $this->flushCache(); if($call_back=='add') { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'&customrulesaddifyfreegifts'); } else { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'&customrulesaddifyfreegifts'); } } } protected function renderListPromotion() { $fields_list = array( 'id' => array( 'title' => $this->l('ID'), 'width' => 120, 'type' => 'int', 'search' => false, 'orderby' => false ), 'title' => array( 'title' => $this->l('Title'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false ), 'rule_active' => array( 'title' => $this->l('Status'), 'width' => 140, 'active' => 'status', 'type' => 'bool', 'search' => false, 'orderby' => false, ), 'date_add' => array( 'title' => $this->l('Added Date'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false, ), 'date_update' => array( 'title' => $this->l('Updated Date'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false, ), ); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = false; $helper->identifier = 'id'; $helper->actions = array('edit', 'delete'); $helper->bulk_actions = array( 'delete' => array( 'text' => $this->l('Delete selected'), 'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?') ) ); $helper->listTotal = count(AddifyfreegiftsPromotionModel::getPosts()); $helper->show_toolbar = true; $helper->toolbar_btn['new'] = array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&addPromotion'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&promotionsaddifyfreegifts', 'desc' => $this->l('Add new rule') ); $helper->title = $this->l("Promotion Rules"); $helper->table = "addifyfreegiftsPromotion"; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&promotionsaddifyfreegifts'; return $helper->generateList(AddifyfreegiftsPromotionModel::getPosts(), $fields_list); } public function renderFormPromotion() { // Getting Categories $Category_array = Category::getCategories((int)Context::getContext()->language->id, true, false); $categories = array(); foreach ($Category_array as $category) { if ($category['id_category'] != 1) { $categories[] = array('name' => $category['name'], 'id' => $category['id_category']); } } // Getting Suppliers $Suppliers_array = Supplier::getSuppliers(false, $this->context->language->id, false, false, false, false); $Suppliers = array(); foreach ($Suppliers_array as $Supplier) { $Suppliers[] = array('name' => $Supplier['name'], 'id' => $Supplier['id_supplier']); } $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Add'), 'icon' => 'icon-cogs', ), 'input' => array( array( 'type' => 'hidden', 'name' => 'id', ), array( 'type' => 'switch', 'label' => $this->l('Enable Promotion'), 'name' => 'rule_active', 'is_bool' => true, 'desc' => $this->l('Enable/disable this promotion.'), 'values' => array( array( 'id' => 'active_on', 'value' => true, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => false, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'text', 'label' => $this->l('Title'), 'name' => 'title', 'desc' => $this->l('Enter title for promotion'), ), array( 'type' => 'radio', 'label' => $this->l('Type'), 'name' => 'condition_type', 'desc' => $this->l('Select option which you want'), 'values' => array( array( 'id' => 'whole', 'value' => 0, 'label' => $this->l('Whole Site') ), array( 'id' => 'Products', 'value' => 1, 'label' => $this->l('Products') ), array( 'id' => 'Categories', 'value' => 2, 'label' => $this->l('Categories') ), array( 'id' => 'Suppliers', 'value' => 3, 'label' => $this->l('Suppliers') ), ) ), array( 'type' => 'promotionproducts', 'label' => $this->l('Products'), 'name' => 'promotion_product', 'prefix' => '<i class="icon-search"></i>', 'hint' => $this->l('Please select same products that you have selected while creating gifting rules.') ), array( 'type' => 'select', 'label' => $this->l('Categories'), 'name' => 'category', 'id' => 'category', 'multiple' => true, 'desc' => $this->l('Please select the same categories that you have selected while creating gifting rules.'), 'options' => array( 'query' => $categories, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'select', 'label' => $this->l('Suppliers'), 'name' => 'supplier', 'id' => 'supplier', 'multiple' => true, 'desc' => $this->l('Please select same suppliers that you have selected while creating gifting rules.'), 'options' => array( 'query' => $Suppliers, 'id' => 'id', 'name' => 'name', ), ), ), 'submit' => array( 'title' => $this->l('Save'), ), 'buttons' => array( 'cancel' => array( 'title' => $this->l('Cancel'), 'class' => 'btn btn-default', 'icon' => 'process-icon-cancel', 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&promotionsaddifyfreegifts', ), ) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->show_cancel_button = false; $helper->table = 'addifyfreegiftsPromotion'; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = 'id'; $helper->submit_action = 'Submitpost'.$this->name.'Promotion'; $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name.'&promotionsaddifyfreegifts'; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->back_url = $helper->currentIndex.'&token='.$helper->token; $promotionproducts = array(); if (Tools::getValue('id')) { $hidepriceBlock_4 = new AddifyfreegiftsPromotionModel((int)Tools::getValue('id')); $post_accessories_tab_4 = explode(',', $hidepriceBlock_4->product); foreach ($post_accessories_tab_4 as $id_pro) { if (!$this->haveThisProduct($id_pro, $promotionproducts) && $product_4 = AddifyfreegiftsPromotionModel::getProductById($id_pro)) { $promotionproducts[] = $product_4; } } } else { $promotionproducts = array(); } if ($post_accessories_4 = Tools::getValue('inputRestrictedProducts_4')) { $post_accessories_tab_4 = explode('-', $post_accessories_4); foreach ($post_accessories_tab_4 as $id_pro) { if (!$this->haveThisProduct($id_pro, $promotionproducts) && $product_4 = AddifyfreegiftsPromotionModel::getProductById($id_pro)) { $promotionproducts[] = $product_4; } } } $helper->tpl_vars = array( 'fields_value' => $this->getFormValuesPromotion(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, 'promotionproducts' => $promotionproducts, 'context_link' => Context::getContext()->link, ); return $helper->generateForm(array($fields_form)); } protected function getFormValuesPromotion() { $fields_value = array(); if (Tools::getValue('id') && (Tools::isSubmit('Submitpost'.$this->name.'Promotion') === false)) { $postBlock = new AddifyfreegiftsPromotionModel((int)Tools::getValue('id')); $fields_value['id'] = $postBlock->id; $fields_value['title'] = $postBlock->title; $fields_value['rule_active'] = $postBlock->rule_active; $fields_value['condition_type'] = $postBlock->condition_type; $fields_value['promotion_product'] = explode(',', $postBlock->product); $fields_value['category[]'] = explode(",",$postBlock->category); $fields_value['supplier[]'] = explode(',', $postBlock->supplier); } else { $fields_value['id'] = Tools::getValue('id'); $fields_value['title'] = Tools::getValue('title'); $fields_value['condition_type'] = Tools::getValue('condition_type'); $fields_value['rule_active'] = Tools::getValue('rule_active'); if (!Tools::getValue('supplier')) { $fields_value['supplier[]'] = Tools::getValue('supplier[]'); } else { $fields_value['supplier'] = implode(",",Tools::getValue('supplier')); } if (!Tools::getValue('category')) { $fields_value['category[]'] = Tools::getValue('category[]'); } else { $fields_value['category'] = implode(",",Tools::getValue('category')); } if (!Tools::getValue('promotion_product')) { $fields_value['product'] = Tools::getValue('promotion_product'); } else { $fields_value['product'] = implode(',', Tools::getValue('promotion_product')); } } return $fields_value; } protected function processSavePromotion() { $call_back = 'add'; $form_values = $this->getFormValuesPromotion(); if (!isset($form_values) && !$form_values) { return $this->context->controller->errors[] = $this->l('Empty post values.'); } $dt = date("Y-m-d h:i:s"); if (($id = Tools::getValue('id'))) { $call_back = 'update'; $AddifyfreegiftsModel= new AddifyfreegiftsPromotionModel((int)$id); $AddifyfreegiftsModel->date_update = $dt; } else { $AddifyfreegiftsModel = new AddifyfreegiftsPromotionModel(); $AddifyfreegiftsModel->date_add = $dt; } $AddifyfreegiftsModel->title = $form_values['title']; $AddifyfreegiftsModel->condition_type = $form_values['condition_type']; $AddifyfreegiftsModel->rule_active = $form_values['rule_active']; $AddifyfreegiftsModel->product = $form_values['product']; $AddifyfreegiftsModel->category = $form_values['category']; $AddifyfreegiftsModel->supplier = $form_values['supplier']; if (!call_user_func(array($AddifyfreegiftsModel, $call_back))) { $this->context->controller->errors = sprintf($this->l('Something went wrong while performing operation %s'), $call_back); } else { $this->flushCache(); if($call_back=='add') { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'&promotionsaddifyfreegifts'); } else { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'&promotionsaddifyfreegifts'); } } } public function flushCache() { Tools::clearSmartyCache(); Tools::clearXMLCache(); Media::clearCache(); Tools::generateIndex(); if (true === Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=') && is_callable(array('Tools', 'clearAllCache'))) { Tools::clearAllCache(); } } protected function renderconfigForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('General Setting'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'switch', 'label' => $this->l('Module Active'), 'name' => 'addifyfreegifts_module_enable', 'desc' => $this->l('Activate/Deactivate'), 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Activate') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Deactivate') ), ), ), ), 'submit' => array( 'title' => $this->l('Save'), ), ) ); $helper = new HelperForm(); $helper->show_toolbar = false; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->identifier = $this->identifier; $helper->submit_action = 'Submitconfig'.$this->name; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getconfigFormValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } protected function getconfigFormValues() { $fields_value = array(); if((Tools::isSubmit('Submitconfig'.$this->name) === false)) { $fields_value['addifyfreegifts_module_enable'] = Configuration::get('addifyfreegifts_module_enable'); } else { $fields_value['addifyfreegifts_module_enable'] = Tools::getValue('addifyfreegifts_module_enable'); } return $fields_value; } protected function processconfigSave() { $form_values = $this->getconfigFormValues(); Configuration::updateValue('addifyfreegifts_module_enable', $form_values['addifyfreegifts_module_enable']); $this->flushCache(); Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } protected function renderConfigFormPromotion() { $get_img = Configuration::get('addifyfreegifts_Background_image'); $baseUrl = $this->context->shop->getBaseURL(true); $afg_image=""; if($get_img) { $this->context->smarty->assign(array( 'baseUrl' => $baseUrl, 'get_img' => $get_img, )); $afg_image = $this->context->smarty->fetch(_PS_MODULE_DIR_.'addifyfreegifts/views/templates/admin/image_html.tpl'); } $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Design Settings'), ), 'input' => array( array( 'type' => 'hidden', 'name' => 'addifyfreegifts_image_id' ), array( 'type' => 'select', 'label' => $this->l('Position'), 'name' => 'addifyfreegifts_banner_position', 'desc' => $this->l(''), 'options' => array( 'query' => array( array( 'id' => '1', // The value of the 'value' attribute of the <option> tag. 'name' => 'Top Bar' // The value of the text content of the <option> tag. ), array( 'id' => '2', 'name' => 'Bottom Bar' ), ), 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'text', 'label' => $this->l('Bar Width'), 'name' => 'addifyfreegifts_Bar_Width', 'desc' => $this->l(''), 'col' => 2, 'suffix' => 'px' ), array( 'type' => 'switch', 'label' => $this->l('Enable Background Image'), 'name' => 'addifyfreegifts_enable_bg_image', 'desc' => $this->l('Activate/Deactivate'), 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ), ), ), array( 'type' => 'file', 'label' => $this->l('Background Image'), 'display_image' => true, 'name' => 'addifyfreegifts_Background_image', 'desc' => $this->l('Recommended size 800 x 800px for default theme. JPG, GIF or PNG format are valid.'), 'image' => $afg_image, ), array( 'type' => 'color', 'label' => $this->l('Background Color'), 'name' => 'addifyfreegifts_bg_color', 'desc' => $this->l(''), ), array( 'type' => 'color', 'label' => $this->l('Text Color'), 'name' => 'addifyfreegifts_text_color', 'desc' => $this->l(''), ), array( 'type' => 'text', 'label' => $this->l('Text font'), 'col' => 2, 'name' => 'addifyfreegifts_text_font', 'desc' => $this->l(''), 'suffix' => 'px' ), array( 'type' => 'textarea', 'label' => $this->l('Message'), 'name' => 'message', 'lang' => true, 'class' => 'rte', 'autoload_rte' => true, 'desc' => $this->l('This message will be displayed for banner'), ), ), 'submit' => array( 'title' => $this->l('Save'), ), ) ); $helper = new HelperForm(); $helper->show_toolbar = false; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->identifier = $this->identifier; $helper->submit_action = 'Submitconfig'.$this->name.'Promotion'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name.'&promotionsaddifyfreegifts'; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFormValuesPromotion(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } protected function getConfigFormValuesPromotion() { $languages = Language::getLanguages(); $fields_value = array(); if((Tools::isSubmit('Submitconfig'.$this->name.'Promotion') === false)) { $fields_value['addifyfreegifts_banner_position'] = Configuration::get('addifyfreegifts_banner_position'); $fields_value['addifyfreegifts_Bar_Width'] = Configuration::get('addifyfreegifts_Bar_Width'); $fields_value['addifyfreegifts_image_id'] = Configuration::get('addifyfreegifts_Background_image'); $fields_value['addifyfreegifts_bg_color'] = Configuration::get('addifyfreegifts_bg_color'); $fields_value['addifyfreegifts_text_color'] = Configuration::get('addifyfreegifts_text_color'); $fields_value['addifyfreegifts_text_font'] = Configuration::get('addifyfreegifts_text_font'); $fields_value['addifyfreegifts_enable_bg_image'] = Configuration::get('addifyfreegifts_enable_bg_image'); foreach ($languages as $language) { $fields_value['message'][$language['id_lang']] = Configuration::get('message_'.$language['id_lang']); } } else { $fields_value['addifyfreegifts_banner_position'] = Tools::getValue('addifyfreegifts_banner_position'); $fields_value['addifyfreegifts_Bar_Width'] = Tools::getValue('addifyfreegifts_Bar_Width'); $fields_value['addifyfreegifts_image_id'] = Tools::getValue('addifyfreegifts_image_id'); $fields_value['addifyfreegifts_bg_color'] = Tools::getValue('addifyfreegifts_bg_color'); $fields_value['addifyfreegifts_text_color'] = Tools::getValue('addifyfreegifts_text_color'); $fields_value['addifyfreegifts_text_font'] = Tools::getValue('addifyfreegifts_text_font'); $fields_value['addifyfreegifts_enable_bg_image'] = Tools::getValue('addifyfreegifts_enable_bg_image'); foreach ($languages as $lang) { $fields_value['message_'.$lang['id_lang']] = Tools::getValue('message_'.$lang['id_lang']); } // For image if (isset($_FILES['addifyfreegifts_Background_image'])) { $target_dir = _PS_MODULE_DIR_.'addifyfreegifts/views/img/'; $without_extension = Tools::substr(basename($_FILES['addifyfreegifts_Background_image']["name"]), 0, strrpos(basename($_FILES['addifyfreegifts_Background_image']["name"]), ".")); $ext = Tools::substr(basename($_FILES['addifyfreegifts_Background_image']["name"]), strrpos(basename($_FILES['addifyfreegifts_Background_image']["name"]), '.') ); $t=time(); $key=($t).(date("Y-m-d",$t)); $target_file = $target_dir . $without_extension.$key.$ext; $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); if (file_exists($target_file)) { $uploadOk = 0; } if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "" ) { $uploadOk = 0; $this->context->controller->errors['logoimg_format'] = $this->l('Sorry, your file is not a Image only JPG, JPEG, PNG & GIF files are allowed'); } if ($uploadOk == 0) { } else { if (move_uploaded_file($_FILES['addifyfreegifts_Background_image']["tmp_name"], $target_file)) { $fields_value['addifyfreegifts_Background_image'] = $without_extension.$key.$ext; $fields_value['addifyfreegifts_image_id'] = $without_extension.$key.$ext; } } } } return $fields_value; } protected function processConfigSavePromotion() { $languages = Language::getLanguages(); $form_values = $this->getConfigFormValuesPromotion(); // if (Configuration::get('addifyfreegifts_Background_image') != $form_values['addifyfreegifts_image_id']) { // $target_dir = _PS_MODULE_DIR_.'addifyfreegifts/views/img/'; // unlink($target_dir.Configuration::get('addifyfreegifts_Background_image')); // } Configuration::updateValue('addifyfreegifts_banner_position', $form_values['addifyfreegifts_banner_position']); Configuration::updateValue('addifyfreegifts_Bar_Width', $form_values['addifyfreegifts_Bar_Width']); Configuration::updateValue('addifyfreegifts_Background_image', $form_values['addifyfreegifts_image_id']); Configuration::updateValue('addifyfreegifts_bg_color', $form_values['addifyfreegifts_bg_color']); Configuration::updateValue('addifyfreegifts_text_color', $form_values['addifyfreegifts_text_color']); Configuration::updateValue('addifyfreegifts_text_font', $form_values['addifyfreegifts_text_font']); Configuration::updateValue('addifyfreegifts_enable_bg_image', $form_values['addifyfreegifts_enable_bg_image']); foreach ($languages as $lang) { Configuration::updateValue('message_'.$lang['id_lang'], $form_values['message_'.$lang['id_lang']],True); } $this->flushCache(); Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name.'&promotionsaddifyfreegifts'); } public function hookActionObjectProductInCartDeleteBefore($params) { $type = Dispatcher::getInstance()->getController(); if($type == 'cart'){ $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); $context=Context::getContext(); if ($addifyfreegifts_module_enable == 1 && !empty($context->cart->id)) { $id_shop = $context->shop->id; $id_country = $context->country->id; $id_currency = $context->cart->id_currency; $id_customer = 0; $id_cart = $context->cart->id; $cartproducts = $context->cart->getProducts(true); if (Tools::getValue('delete')) { $id_product = $params['id_product']; $id_product_attribute = $params['id_product_attribute']; foreach ($cartproducts as $cartproduct) { if ($cartproduct['id_product'] == $id_product) { $quantity = $cartproduct['cart_quantity']; $specific_price = SpecificPrice::getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, 0, $quantity, $id_product_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $giftpro_quan = $this->context->cookie->giftpro_quan; $giftproauto_quan = $this->context->cookie->giftproauto_quan; if (!empty($this->context->cookie->delete_ids)) { $delete_ids = explode(',', $this->context->cookie->delete_ids); if (!in_array($id_product, $delete_ids)) { $delete_ids[] = $id_product; $dataa = implode(',', $delete_ids); $this->context->cookie->__set('delete_ids', $dataa); } SpecificPrice::deleteByIdCart($id_cart, $id_product, $id_product_attribute); $new_cart = new Cart($id_cart); $new_cart->deleteProduct($id_product, $id_product_attribute); if ($giftpro_quan) { if ($giftpro_quan == 0) { $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('Rule_Ids_buy'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); $this->context->cookie->__unset('Add_gift_ids'); }else{ $final_cookiee = $giftpro_quan - 1; $this->context->cookie->__set('giftpro_quan',$final_cookiee); } } if ($giftproauto_quan) { if ($giftproauto_quan == 0) { $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('Rule_Ids_buy'); $this->context->cookie->__unset('Add_gift_ids'); $this->context->cookie->__unset('giftproauto_quan'); }else{ $finalauto_cookiee = $giftproauto_quan - 1; $this->context->cookie->__set('giftproauto_quan',$finalauto_cookiee); $this->context->cookie->__unset('flag'); } } } else{ $this->context->cookie->__set('delete_ids', $id_product); SpecificPrice::deleteByIdCart($id_cart, $id_product, $id_product_attribute); $new_cart = new Cart($id_cart); $new_cart->deleteProduct($id_product, $id_product_attribute); if ($giftpro_quan) { if ($giftpro_quan == 0) { $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('Rule_Ids_buy'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); $this->context->cookie->__unset('Add_gift_ids'); }else{ $final_cookiee = $giftpro_quan - 1; $this->context->cookie->__set('giftpro_quan',$final_cookiee); } } if ($giftproauto_quan) { if ($giftproauto_quan == 0) { $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('Rule_Ids_buy'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftproauto_quan'); $this->context->cookie->__unset('Add_gift_ids'); }else{ $finalauto_cookiee = $giftproauto_quan - 1; $this->context->cookie->__set('giftproauto_quan',$finalauto_cookiee); $this->context->cookie->__unset('flag'); } } } } } } } } } } } public function hookActionCustomerLogoutBefore() { $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); if ($addifyfreegifts_module_enable == 1) { $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Rule_Ids_buy'); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); $this->context->cookie->__unset('giftproauto_quan'); $this->context->cookie->__unset('Add_gift_ids'); } } public function deleteGiftFromCart() { $context=Context::getContext(); $type = Dispatcher::getInstance()->getController(); if ($type == 'index' || $type == 'product' || $type == 'cart') { $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); if ($addifyfreegifts_module_enable == 1 && !empty($context->cart->id)) { $cart_pro_id = []; $cart_categ_id = []; $cart_supp_id = []; $checkcustomer = $context->customer; $check_group_id = $checkcustomer->id_default_group; $id_shop = $context->shop->id; $id_country = $context->country->id; $id_currency = $context->cart->id_currency; $id_customer = 0; $id_cart = (int)$context->cart->id; $id_lang = (int)$context->language->id; $cartproducts = $context->cart->getProducts(true); $total_cart_amount = preg_replace("/[^0-9.]/", "", Cart::getTotalCart($id_cart, true)); $today = date("Y-m-d"); foreach ($cartproducts as $value_id) { $cart_pro_id[] = $value_id['id_product']; $category_ids = Product::getProductCategories($value_id['id_product']); $arraymerge = array_merge($cart_categ_id,$category_ids); $cart_categ_id = array_unique($arraymerge); $product = new Product($value_id['id_product']); $id_supplier = (int) $product->id_supplier; $cart_supp_id[] = $id_supplier; } $gift_pro_ids = []; $simple_pro_ids = []; foreach ($cartproducts as $cartproduct) { $pro_idd = $cartproduct['id_product']; $pro_quantityy = $cartproduct['cart_quantity']; $pro_attri_id = $cartproduct['id_product_attribute']; $specific_price = SpecificPrice::getSpecificPrice($pro_idd, $id_shop, $id_currency, $id_country, 0, $pro_quantityy, $pro_attri_id, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $gift_pro_ids[] = array('id_product' => $cartproduct['id_product'], 'quantity' => $cartproduct['cart_quantity'], 'attribute' => $cartproduct['id_product_attribute']); } } else{ $simple_pro_ids[] = array('id_product' => $cartproduct['id_product'], 'quantity' => $cartproduct['cart_quantity'], 'attribute' => $cartproduct['id_product_attribute']); } } if (!empty($this->context->cookie->Rule_Ids_buy)) { if ($gift_pro_ids) { foreach ($gift_pro_ids as $gift_product_id) { if (in_array($gift_product_id['id_product'], $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id['id_product'], $id_shop, $id_currency, $id_country, 0, $gift_product_id['quantity'], $gift_product_id['attribute'], $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id['id_product'], $gift_product_id['attribute']); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id['id_product'], $gift_product_id['attribute']); $this->context->cookie->__unset('Rule_Ids_buy'); $this->context->cookie->__unset('flag'); } } } } } } if (!empty($this->context->cookie->Rule_Ids_auto)) { $rule_id = $this->context->cookie->Rule_Ids_auto; $result = AddifyfreegiftsModel::getrulebyid($rule_id, $check_group_id, $today); $PreDefinedRule = AddifyfreegiftspredefinedModel::getPreDefinedRuleById($rule_id, $today); if($PreDefinedRule){ $PreDefinedRuleDelete = AddifyfreegiftspredefinedModel::getPreDefinedRuleDelete($cart_pro_id, $cart_categ_id, $cart_supp_id, $id_lang); if ($PreDefinedRuleDelete) { $gift_rules_products_ids = ''; if ($PreDefinedRuleDelete['giftbuy_type'] == 0) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_rules_products_ids = $ids_products; } elseif ($PreDefinedRuleDelete['giftbuy_type'] == 1) { $gift_rules_products_ids = explode(",",$PreDefinedRuleDelete['gift_product']); } elseif ($PreDefinedRuleDelete['giftbuy_type'] == 2) { $gift_categorys = explode(",",$PreDefinedRuleDelete['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } elseif ($PreDefinedRuleDelete['giftbuy_type'] == 3) { $gift_suppliers = explode(",",$PreDefinedRuleDelete['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Add_gift_ids'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftproauto_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $PreDefinedRuleDelete['gift_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } elseif ($result) { if ($result[0]['gift_type'] == 0) { $gift_rules_products_ids = ''; if ($result[0]['giftbuy_type'] == 1) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_rules_products_ids = $ids_products; } elseif ($result[0]['giftbuy_type'] == 0) { $gift_rules_products_ids = explode(",",$result[0]['select_product']); } elseif ($result[0]['giftbuy_type'] == 2) { $gift_categorys = explode(",",$result[0]['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } elseif ($result[0]['giftbuy_type'] == 3) { $gift_suppliers = explode(",",$result[0]['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } if ($result[0]['condition_option'] == 1) { if (!empty($result[0]['cart_amount'])) { if ($total_cart_amount < $result[0]['cart_amount']) { foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Add_gift_ids'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftproauto_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $result[0]['get_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } } if ($result[0]['condition_option'] == 0) { if (!empty($result[0]['product'])) { if (empty($result[0]['buy_all_products']) && $result[0]['buy_all_products'] == '') { $rules_products_ids = explode(",",$result[0]['product']); $i = 0; $j=0; $k=0; $buy_quantity_check = 0; foreach ($rules_products_ids as $value) { if (!in_array($value, $cart_pro_id)) { $i++; }else{ $k++; } foreach ($cartproducts as $cartproduct) { if ($cartproduct['id_product'] == $value) { if ($result[0]['buy_x'] > 1) { if ($cartproduct['cart_quantity'] < $result[0]['buy_quantity']) { $j = count($rules_products_ids); } }else{ if ($cartproduct['cart_quantity'] < $result[0]['buy_quantity']) { $j++; } } } } } if ($k != count($rules_products_ids)) { if ($j != 0) { if ($j == count($rules_products_ids) || $j < $result[0]['buy_quantity']) { $buy_quantity_check = 1; } } }else{ if ($j == count($rules_products_ids)) { $buy_quantity_check = 1; } } $getX = 1; if (!empty($result[0]['buy_x'])) { $getX = (int)$result[0]['buy_x']; } $getXcheck = 0; if ($getX == 1) { if ($i == count($rules_products_ids)) { $getXcheck = 1; } } else{ if ($i != $getX && $i != 0) { $getXcheck = 1; } } if ($getXcheck == 1 || $buy_quantity_check == 1) { foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Add_gift_ids'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftproauto_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $result[0]['get_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } elseif ($result[0]['buy_all_products'] == 0) { $rules_products_ids = explode(",",$result[0]['product']); $i = 0; foreach ($rules_products_ids as $value) { if (in_array($value, $cart_pro_id)) { $i++; } } if ($i != count($rules_products_ids)) { foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Add_gift_ids'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftproauto_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $result[0]['get_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } elseif ($result[0]['buy_all_products'] == 1) { $rules_products_ids = explode(",",$result[0]['product']); $i = 0; foreach ($rules_products_ids as $value) { if (!in_array($value, $cart_pro_id)) { $i++; } } if ($i == count($rules_products_ids)) { foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Add_gift_ids'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftproauto_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $result[0]['get_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } } } } } else{ if ($gift_pro_ids) { foreach ($gift_pro_ids as $gift_product_id) { if (in_array($gift_product_id['id_product'], $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id['id_product'], $id_shop, $id_currency, $id_country, 0, $gift_product_id['quantity'], $gift_product_id['attribute'], $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id['id_product'], $gift_product_id['attribute']); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id['id_product'], $gift_product_id['attribute']); $this->context->cookie->__unset('Rule_Ids_auto'); $this->context->cookie->__unset('Add_gift_ids'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftproauto_quan'); } } } } } } } // for delete of manual condition if (!empty($this->context->cookie->Rule_Ids_manual)) { $rule_id = $this->context->cookie->Rule_Ids_manual; $result = AddifyfreegiftsModel::getrulebyid($rule_id, $check_group_id, $today); $PreDefinedRule = AddifyfreegiftspredefinedModel::getPreDefinedRuleById($rule_id, $today); if($PreDefinedRule){ $PreDefinedRuleDelete = AddifyfreegiftspredefinedModel::getPreDefinedRuleDelete($cart_pro_id, $cart_categ_id, $cart_supp_id, $id_lang); if ($PreDefinedRuleDelete) { $gift_rules_products_ids = ''; if ($PreDefinedRuleDelete['giftbuy_type'] == 0) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_rules_products_ids = $ids_products; } elseif ($PreDefinedRuleDelete['giftbuy_type'] == 1) { $gift_rules_products_ids = explode(",",$PreDefinedRuleDelete['gift_product']); } elseif ($PreDefinedRuleDelete['giftbuy_type'] == 2) { $gift_categorys = explode(",",$PreDefinedRuleDelete['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } elseif ($PreDefinedRuleDelete['giftbuy_type'] == 3) { $gift_suppliers = explode(",",$PreDefinedRuleDelete['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $PreDefinedRuleDelete['gift_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } elseif ($result) { if ($result[0]['gift_type'] == 1) { $gift_rules_products_ids = ''; if ($result[0]['giftbuy_type'] == 1) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_rules_products_ids = $ids_products; } elseif ($result[0]['giftbuy_type'] == 0) { $gift_rules_products_ids = explode(",",$result[0]['select_product']); } elseif ($result[0]['giftbuy_type'] == 2) { $gift_categorys = explode(",",$result[0]['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } elseif ($result[0]['giftbuy_type'] == 3) { $gift_suppliers = explode(",",$result[0]['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } if ($result[0]['condition_option'] == 1) { if (!empty($result[0]['cart_amount'])) { if ($total_cart_amount < $result[0]['cart_amount']) { foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $result[0]['get_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } } if ($result[0]['condition_option'] == 0) { if (!empty($result[0]['product'])) { if (empty($result[0]['buy_all_products']) && $result[0]['buy_all_products'] == '') { $rules_products_ids = explode(",",$result[0]['product']); $i = 0; $j=0; $k=0; $buy_quantity_check = 0; foreach ($rules_products_ids as $value) { if (!in_array($value, $cart_pro_id)) { $i++; }else{ $k++; } foreach ($cartproducts as $cartproduct) { if ($cartproduct['id_product'] == $value) { if ($result[0]['buy_x'] > 1) { if ($cartproduct['cart_quantity'] < $result[0]['buy_quantity']) { $j = count($rules_products_ids); } }else{ if ($cartproduct['cart_quantity'] < $result[0]['buy_quantity']) { $j++; } } } } } if ($k != count($rules_products_ids)) { if ($j == count($rules_products_ids) || $j < $result[0]['buy_quantity']) { $buy_quantity_check = 1; } }else{ if ($j == count($rules_products_ids)) { $buy_quantity_check = 1; } } $getX = 1; if (!empty($result[0]['buy_x'])) { $getX = (int)$result[0]['buy_x']; } $getXcheck = 0; if ($getX == 1) { if ($i == count($rules_products_ids)) { $getXcheck = 1; } } else{ if ($i != $getX && $i != 0) { $getXcheck = 1; } } if ($getXcheck == 1 || $buy_quantity_check == 1) { foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $result[0]['get_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } elseif ($result[0]['buy_all_products'] == 0) { $rules_products_ids = explode(",",$result[0]['product']); $i = 0; foreach ($rules_products_ids as $value) { if (in_array($value, $cart_pro_id)) { $i++; } } if ($i != count($rules_products_ids)) { foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $result[0]['get_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } elseif ($result[0]['buy_all_products'] == 1) { $rules_products_ids = explode(",",$result[0]['product']); $i = 0; foreach ($rules_products_ids as $value) { if (!in_array($value, $cart_pro_id)) { $i++; } } if ($i == count($rules_products_ids)) { foreach ($gift_rules_products_ids as $gift_product_id) { $default_attribute = Product::getDefaultAttribute($gift_product_id); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id, $default_attribute); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); if (in_array($gift_product_id, $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id, $id_shop, $id_currency, $id_country, 0, $result[0]['get_quantity'], $default_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id, $default_attribute); } } } } } } } } } } else{ if ($gift_pro_ids) { foreach ($gift_pro_ids as $gift_product_id) { if (in_array($gift_product_id['id_product'], $cart_pro_id)) { $specific_price = SpecificPrice::getSpecificPrice($gift_product_id['id_product'], $id_shop, $id_currency, $id_country, 0, $gift_product_id['quantity'], $gift_product_id['attribute'], $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $new_cart = new Cart($id_cart); $new_cart->deleteProduct($gift_product_id['id_product'], $gift_product_id['attribute']); SpecificPrice::deleteByIdCart($id_cart, $gift_product_id['id_product'], $gift_product_id['attribute']); $this->context->cookie->__unset('Rule_Ids_manual'); $this->context->cookie->__unset('flag'); $this->context->cookie->__unset('giftpro_quan'); } } } } } } } } } } public function checkGiftsProducts($context, $rule, $gift_product_id) { $cart_proo_id = []; $cartproductts = $context->cart->getProducts(true); $gift_category_ids = Product::getProductCategories($gift_product_id); $product_obj = new Product($gift_product_id); $gift_id_supplier = (int) $product_obj->id_supplier; foreach ($cartproductts as $value_id) { $cart_proo_id[] = $value_id['id_product']; } if (!in_array($gift_product_id, $cart_proo_id)) { if ($rule['userbuy_type'] == 2) { $i=0; if (!empty($rule['buy_category'])) { $category_ids = explode(",",$rule['buy_category']); foreach ($category_ids as $value) { if (in_array($value, $gift_category_ids)) { return false; } } } } elseif ($rule['userbuy_type'] == 3) { $i=0; if (!empty($rule['buy_supplier'])) { $supplier_ids = explode(",",$rule['buy_supplier']); if (in_array($gift_id_supplier, $supplier_ids)) { return false; } } } return true; } return false; } public function hookActionCartSave() { $context=Context::getContext(); $type = Dispatcher::getInstance()->getController(); if ($type == 'index' || $type == 'product' || $type == 'cart') { $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); if ($addifyfreegifts_module_enable == 1 && !empty($context->cart->id)) { $this->deleteGiftFromCart(); $cart_pro_id = []; $cart_categ_id = []; $cart_supp_id = []; $checkcustomer = $context->customer; $check_group_id = $checkcustomer->id_default_group; $id_shop = $context->shop->id; $id_country = $context->country->id; $id_currency = $context->cart->id_currency; $id_customer = 0; $id_cart = (int)$context->cart->id; $id_lang = (int)$context->language->id; $cartproducts = $context->cart->getProducts(true); $total_cart_amount = preg_replace("/[^0-9.]/", "", Cart::getTotalCart($id_cart, true)); $today = date("Y-m-d"); foreach ($cartproducts as $value_id) { $cart_pro_id[] = $value_id['id_product']; $category_ids = Product::getProductCategories($value_id['id_product']); $arraymerge = array_merge($cart_categ_id,$category_ids); $cart_categ_id = array_unique($arraymerge); $product = new Product($value_id['id_product']); $id_supplier = (int) $product->id_supplier; $cart_supp_id[] = $id_supplier; } $gift_pro_ids = []; $simple_pro_ids = []; foreach ($cartproducts as $cartproduct) { $pro_idd = $cartproduct['id_product']; $pro_quantityy = $cartproduct['cart_quantity']; $pro_attri_id = $cartproduct['id_product_attribute']; $specific_price = SpecificPrice::getSpecificPrice($pro_idd, $id_shop, $id_currency, $id_country, 0, $pro_quantityy, $pro_attri_id, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $gift_pro_ids[] = array('id_product' => $cartproduct['id_product'], 'quantity' => $cartproduct['cart_quantity'], 'attribute' => $cartproduct['id_product_attribute']); } } else{ $simple_pro_ids[] = array('id_product' => $cartproduct['id_product'], 'quantity' => $cartproduct['cart_quantity'], 'attribute' => $cartproduct['id_product_attribute']); } } // for add gift of auto condition $PreDefinedRuleOne = AddifyfreegiftspredefinedModel::getPreDefinedRuleOne($today, $cart_pro_id, $cart_categ_id, $cart_supp_id); $getrulesone = AddifyfreegiftsModel::getruleone($check_group_id, $total_cart_amount, $today, $cart_pro_id, $cartproducts, $cart_categ_id, $cart_supp_id, $id_lang); if ($PreDefinedRuleOne) { if ($PreDefinedRuleOne['gift_type'] == 0) { $delete_ids = explode(',', $this->context->cookie->delete_ids); $gift_ids = ''; if ($PreDefinedRuleOne['giftbuy_type'] == 0) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_ids = $ids_products; } elseif ($PreDefinedRuleOne['giftbuy_type'] == 1) { if (!empty($PreDefinedRuleOne['gift_product'])) { $gift_ids = explode(",",$PreDefinedRuleOne['gift_product']); } } elseif ($PreDefinedRuleOne['giftbuy_type'] == 2) { if (!empty($PreDefinedRuleOne['gift_category'])) { $gift_categorys = explode(",",$PreDefinedRuleOne['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_ids = array_unique($ids_products); } } elseif ($PreDefinedRuleOne['giftbuy_type'] == 3) { if (!empty($PreDefinedRuleOne['gift_supplier'])) { $gift_suppliers = explode(",",$PreDefinedRuleOne['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_ids = array_unique($ids_products); } } $random_gift = array_rand($gift_ids,1); // while (true) { // if (in_array($gift_ids[$random_gift], $cart_pro_id)) { // $random_gift = array_rand($gift_ids,1); // }else{ // break; // } // } if (!empty($PreDefinedRuleOne['Validity_from'])) { $Validity_from = $PreDefinedRuleOne['Validity_from']; } else{ $Validity_from = 0; } if (!empty($PreDefinedRuleOne['Validity_to'])) { $Validity_to = $PreDefinedRuleOne['Validity_to']; } else{ $Validity_to = 0; } if ($this->context->cookie->flag != 1) { if (!in_array($gift_ids[$random_gift], $delete_ids)) { $checkGiftsProducts = $this->checkGiftsProducts($context, $PreDefinedRuleOne, $gift_ids[$random_gift]); if ($checkGiftsProducts) { $default_attribute = Product::getDefaultAttribute($gift_ids[$random_gift]); $rrr = AddifyfreegiftspredefinedModel::specific_price_rule_exists($gift_ids[$random_gift], $default_attribute, $id_shop, 0, $id_country, $id_currency, $id_customer, $PreDefinedRuleOne['gift_quantity'], $Validity_from, $Validity_to, $id_cart); if ($rrr == 0) { $specific_price = new SpecificPrice(); $specific_price->id_product = $gift_ids[$random_gift]; $specific_price->id_product_attribute = $default_attribute; $specific_price->id_cart = $id_cart; $specific_price->from_quantity = $PreDefinedRuleOne['gift_quantity']; $specific_price->price = 0; $specific_price->reduction_type = 'percentage'; $specific_price->reduction_tax = 1; $specific_price->id_shop = $id_shop; $specific_price->id_currency = $id_currency; $specific_price->id_country = $id_country; $specific_price->id_group = 0; $specific_price->id_customer = $id_customer; $specific_price->reduction = 0.0; $specific_price->from = $Validity_from; $specific_price->to = $Validity_to; $specific_price->add(); } $this->context->cookie->__set('flag', 1); $new_cart = new Cart($id_cart); $new_cart->updateQty($PreDefinedRuleOne['gift_quantity'], $gift_ids[$random_gift], $default_attribute); $random_gift_ids = $gift_ids[$random_gift]; if ($this->context->cookie->Add_gift_ids) { $explode_gift_ids = explode(',', $this->context->cookie->Add_gift_ids); $explode_gift_ids[] = $gift_ids[$random_gift]; $random_gift_ids = implode(',', $explode_gift_ids); } $this->context->cookie->__set('Add_gift_ids', $random_gift_ids); $this->context->cookie->__set('Rule_Ids_auto', $PreDefinedRuleOne['id']); } } } } } elseif ($getrulesone) { // add gift auto in cart if ($getrulesone['gift_type'] == 0) { $gift_ids = ''; if ($getrulesone['giftbuy_type'] == 1) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_ids = $ids_products; } elseif ($getrulesone['giftbuy_type'] == 0) { if (!empty($getrulesone['select_product'])) { $gift_ids = explode(",",$getrulesone['select_product']); } } elseif ($getrulesone['giftbuy_type'] == 2) { if (!empty($getrulesone['gift_category'])) { $gift_categorys = explode(",",$getrulesone['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_ids = array_unique($ids_products); } } elseif ($getrulesone['giftbuy_type'] == 3) { if (!empty($getrulesone['gift_supplier'])) { $gift_suppliers = explode(",",$getrulesone['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_ids = array_unique($ids_products); } } $delete_ids = explode(',', $this->context->cookie->delete_ids); $getY = 1; if (!empty($getrulesone['get_Y'])) { $getY = (int)$getrulesone['get_Y']; } $random_gifts = (array) array_rand($gift_ids,$getY); // if ($this->context->cookie->flag != 1) { // while (true) { // $i = 0; // foreach ($random_gifts as $random_gift) { // if (!in_array($gift_ids[$random_gift], $cart_pro_id)) { // $i++; // } // } // if ($i == count($random_gifts)) { // break; // }else{ // $random_gifts = (array) array_rand($gift_ids,$getY); // } // } // } if (!empty($getrulesone['Validity_from'])) { $Validity_from = $getrulesone['Validity_from']; } else{ $Validity_from = 0; } if (!empty($getrulesone['Validity_to'])) { $Validity_to = $getrulesone['Validity_to']; } else{ $Validity_to = 0; } $addcartflag = 0; if (empty($this->context->cookie->giftproauto_quan)) { $this->context->cookie->__set('giftproauto_quan', 0); } foreach ($random_gifts as $random_gift_key => $random_gift) { $giftproauto_quan = (int)$this->context->cookie->giftproauto_quan; if ($giftproauto_quan < $getY) { if ($this->context->cookie->flag != 1) { if (!in_array($gift_ids[$random_gift], $delete_ids)) { $checkGiftsProducts = $this->checkGiftsProducts($context, $getrulesone, $gift_ids[$random_gift]); if ($checkGiftsProducts) { $default_attribute = Product::getDefaultAttribute($gift_ids[$random_gift]); $rrr = AddifyfreegiftsModel::specific_price_rule_exists($gift_ids[$random_gift], $default_attribute, $id_shop, 0, $id_country, $id_currency, $id_customer, $getrulesone['get_quantity'], $Validity_from, $Validity_to, $id_cart); if ($rrr == 0) { $specific_price = new SpecificPrice(); $specific_price->id_product = $gift_ids[$random_gift]; $specific_price->id_product_attribute = $default_attribute; $specific_price->id_cart = $id_cart; $specific_price->from_quantity = $getrulesone['get_quantity']; $specific_price->price = 0; $specific_price->reduction_type = 'percentage'; $specific_price->reduction_tax = 1; $specific_price->id_shop = $id_shop; $specific_price->id_currency = $id_currency; $specific_price->id_country = $id_country; $specific_price->id_group = 0; $specific_price->id_customer = $id_customer; $specific_price->reduction = 0.0; $specific_price->from = $Validity_from; $specific_price->to = $Validity_to; $specific_price->add(); } $addcartflag = 1; $final_co = $this->context->cookie->giftproauto_quan + 1; $this->context->cookie->__set('giftproauto_quan', $final_co); $new_cart = new Cart((int)$id_cart); $new_cart->updateQty((int)$getrulesone['get_quantity'], (int)$gift_ids[$random_gift], (int)$default_attribute); $random_gift_ids = $gift_ids[$random_gift]; if ($this->context->cookie->Add_gift_ids) { $explode_gift_ids = explode(',', $this->context->cookie->Add_gift_ids); $explode_gift_ids[] = $gift_ids[$random_gift]; $random_gift_ids = implode(',', $explode_gift_ids); } $this->context->cookie->__set('Add_gift_ids', $random_gift_ids); } } } } } if ($addcartflag == 1) { $this->context->cookie->__set('flag', 1); $this->context->cookie->__set('Rule_Ids_auto', $getrulesone['id']); } } if ($getrulesone['gift_type'] == 2) { $gift_ids = ''; if ($getrulesone['giftbuy_type'] == 1) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_ids = $ids_products; } elseif ($getrulesone['giftbuy_type'] == 0) { if (!empty($getrulesone['select_product'])) { $gift_ids = explode(",",$getrulesone['select_product']); } } elseif ($getrulesone['giftbuy_type'] == 2) { if (!empty($getrulesone['gift_category'])) { $gift_categorys = explode(",",$getrulesone['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_ids = array_unique($ids_products); } } elseif ($getrulesone['giftbuy_type'] == 3) { if (!empty($getrulesone['gift_supplier'])) { $gift_suppliers = explode(",",$getrulesone['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_ids = array_unique($ids_products); } } $delete_ids = explode(',', $this->context->cookie->delete_ids); $random_gift = array_rand($gift_ids,1); // while (true) { // if (in_array($gift_ids[$random_gift], $cart_pro_id)) { // $random_gift = array_rand($gift_ids,1); // }else{ // break; // } // } if (!empty($getrulesone['Validity_from'])) { $Validity_from = $getrulesone['Validity_from']; } else{ $Validity_from = 0; } if (!empty($getrulesone['Validity_to'])) { $Validity_to = $getrulesone['Validity_to']; } else{ $Validity_to = 0; } if ($this->context->cookie->flag != 1) { if (!in_array($gift_ids[$random_gift], $delete_ids)) { $checkGiftsProducts = $this->checkGiftsProducts($context, $getrulesone, $gift_ids[$random_gift]); if ($checkGiftsProducts) { $default_attribute = Product::getDefaultAttribute($gift_ids[$random_gift]); $rrr = AddifyfreegiftsModel::specific_price_rule_exists($gift_ids[$random_gift], $default_attribute, $id_shop, 0, $id_country, $id_currency, $id_customer, $getrulesone['get_quantity'], $Validity_from, $Validity_to, $id_cart); if ($rrr == 0) { $specific_price = new SpecificPrice(); $specific_price->id_product = $gift_ids[$random_gift]; $specific_price->id_product_attribute = $default_attribute; $specific_price->id_cart = $id_cart; $specific_price->from_quantity = $getrulesone['get_quantity']; $specific_price->price = 0; $specific_price->reduction_type = 'percentage'; $specific_price->reduction_tax = 1; $specific_price->id_shop = $id_shop; $specific_price->id_currency = $id_currency; $specific_price->id_country = $id_country; $specific_price->id_group = 0; $specific_price->id_customer = $id_customer; $specific_price->reduction = 0.0; $specific_price->from = $Validity_from; $specific_price->to = $Validity_to; $specific_price->add(); } $this->context->cookie->__set('flag', 1); $new_cart = new Cart($id_cart); $new_cart->updateQty($getrulesone['get_quantity'], $gift_ids[$random_gift], $default_attribute); $this->context->cookie->__set('Rule_Ids_buy', $getrulesone['id']); $random_gift_ids = $gift_ids[$random_gift]; if ($this->context->cookie->Add_gift_ids) { $explode_gift_ids = explode(',', $this->context->cookie->Add_gift_ids); $explode_gift_ids[] = $gift_ids[$random_gift]; $random_gift_ids = implode(',', $explode_gift_ids); } $this->context->cookie->__set('Add_gift_ids', $random_gift_ids); } } } } } } } } // manual add to cart public function hookDisplayExpressCheckout() { $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); $context=Context::getContext(); if ($addifyfreegifts_module_enable == 1 && !empty($context->cart->id)) { // if ($this->context->cookie->flag != 1) { $cart_pro_id = []; $cart_categ_id = []; $cart_supp_id = []; $cartproducts = $context->cart->getProducts(true); $checkcustomer = $this->context->customer; $check_group_id = $checkcustomer->id_default_group; $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); $id_shop = $context->shop->id; $id_country = $context->country->id; $id_currency = $context->cart->id_currency; $id_lang = (int)$context->language->id; $id_customer = 0; $id_cart = $context->cart->id; $total_cart_amount = preg_replace("/[^0-9.]/", "", Cart::getTotalCart($id_cart, true)); $today = date("Y-m-d"); foreach ($cartproducts as $value_id) { $cart_pro_id[] = $value_id['id_product']; $category_ids = Product::getProductCategories($value_id['id_product']); $arraymerge = array_merge($cart_categ_id,$category_ids); $cart_categ_id = array_unique($arraymerge); $product = new Product($value_id['id_product']); $id_supplier = (int) $product->id_supplier; $cart_supp_id[] = $id_supplier; } $PreDefinedRuleOne = AddifyfreegiftspredefinedModel::getPreDefinedRuleOne($today, $cart_pro_id, $cart_categ_id, $cart_supp_id); $getrulesone = AddifyfreegiftsModel::getruleone($check_group_id, $total_cart_amount, $today, $cart_pro_id, $cartproducts, $cart_categ_id, $cart_supp_id, $id_lang); if ($PreDefinedRuleOne) { if ($this->context->cookie->flag != 1) { if ($PreDefinedRuleOne['gift_type'] == 1) { $getY = 1; $gift_rules_products_ids = ''; if ($PreDefinedRuleOne['giftbuy_type'] == 0) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_rules_products_ids = $ids_products; } elseif ($PreDefinedRuleOne['giftbuy_type'] == 1) { if (!empty($PreDefinedRuleOne['gift_product'])) { $gift_rules_products_ids = explode(",",$PreDefinedRuleOne['gift_product']); } } elseif ($PreDefinedRuleOne['giftbuy_type'] == 2) { if (!empty($PreDefinedRuleOne['gift_category'])) { $gift_categorys = explode(",",$PreDefinedRuleOne['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } } elseif ($PreDefinedRuleOne['giftbuy_type'] == 3) { if (!empty($PreDefinedRuleOne['gift_supplier'])) { $gift_suppliers = explode(",",$PreDefinedRuleOne['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } } $product_details = []; if (!empty($gift_rules_products_ids)) { if (!empty($PreDefinedRuleOne['Validity_from'])) { $Validity_from = $PreDefinedRuleOne['Validity_from']; } else{ $Validity_from = 0; } if (!empty($PreDefinedRuleOne['Validity_to'])) { $Validity_to = $PreDefinedRuleOne['Validity_to']; } else{ $Validity_to = 0; } $delete_ids = explode(',', $this->context->cookie->delete_ids); foreach ($gift_rules_products_ids as $gift_product_id) { if (!in_array($gift_product_id, $delete_ids)) { if (!in_array($gift_product_id, $cart_pro_id)) { $product_name = Product::getProductName($gift_product_id); $default_attribute = Product::getDefaultAttribute($gift_product_id); $link = new Link(); $Product = new Product($gift_product_id); $cover_id = Product::getCover($gift_product_id); $link_rewrite = $Product->link_rewrite[$id_lang]; $img_url = $link->getImageLink($link_rewrite, $cover_id['id_image']); $product_details[] = array("product_id" => $gift_product_id, "product_name" => $product_name, "img_url" => $img_url, "product_quan" => $PreDefinedRuleOne['gift_quantity'], "default_attribute" => $default_attribute, "id_shop" => $id_shop, "id_country" => $id_country, "id_currency" => $id_currency, "id_customer" => $id_customer, "id_cart" => $id_cart, "group_id" => 0, "id_rule" => $PreDefinedRuleOne['id'], "Validity_from" => $Validity_from, "Validity_to" => $Validity_to); } } } if (empty($this->context->cookie->giftpro_quan)) { $this->context->cookie->__set('giftpro_quan', 0); } if (!empty($product_details)) { $this->context->smarty->assign(array( 'product_details' => $product_details, 'get_Y' => $getY, 'giftpro_quan' => $this->context->cookie->giftpro_quan, )); return $this -> display(__FILE__, '/views/templates/front/manual.tpl'); } else{ return $this -> display(__FILE__, '/views/templates/front/remove.tpl'); } } } } else{ return $this -> display(__FILE__, '/views/templates/front/remove.tpl'); } } elseif ($getrulesone) { $getY = 1; if (!empty($getrulesone['get_Y'])) { $getY = (int)$getrulesone['get_Y']; } $giftpro_quan = $this->context->cookie->giftpro_quan; if ($giftpro_quan < $getY) { if ($getrulesone['gift_type'] == 1) { $gift_rules_products_ids = ''; if ($getrulesone['giftbuy_type'] == 1) { // Get all products $products = Product::getProducts((int)$context->language->id, 0, 0, 'id_product', 'ASC'); $ids_products = []; foreach ($products as $product) { $ids_products[] = $product['id_product']; } $gift_rules_products_ids = $ids_products; } elseif ($getrulesone['giftbuy_type'] == 0) { if (!empty($getrulesone['select_product'])) { $gift_rules_products_ids = explode(",",$getrulesone['select_product']); } } elseif ($getrulesone['giftbuy_type'] == 2) { if (!empty($getrulesone['gift_category'])) { $gift_categorys = explode(",",$getrulesone['gift_category']); $ids_products = []; foreach ($gift_categorys as $key => $category_id) { $category = new Category($category_id); // Get products in the category $products = $category->getProducts((int)$context->language->id, 1, 100); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } } elseif ($getrulesone['giftbuy_type'] == 3) { if (!empty($getrulesone['gift_supplier'])) { $gift_suppliers = explode(",",$getrulesone['gift_supplier']); $ids_products = []; foreach ($gift_suppliers as $key => $supplier_id) { // Load products by supplier ID $products = AddifyfreegiftspredefinedModel::getProductBySupplierId((int)$supplier_id); foreach ($products as $product) { $ids_products[] = $product['id_product']; } } $gift_rules_products_ids = array_unique($ids_products); } } $product_details = []; if (!empty($gift_rules_products_ids)) { if (!empty($getrulesone['Validity_from'])) { $Validity_from = $getrulesone['Validity_from']; } else{ $Validity_from = 0; } if (!empty($getrulesone['Validity_to'])) { $Validity_to = $getrulesone['Validity_to']; } else{ $Validity_to = 0; } $delete_ids = explode(',', $this->context->cookie->delete_ids); foreach ($gift_rules_products_ids as $gift_product_id) { if (!in_array($gift_product_id, $delete_ids)) { if (!in_array($gift_product_id, $cart_pro_id)) { $product_name = Product::getProductName($gift_product_id); $default_attribute = Product::getDefaultAttribute($gift_product_id); $link = new Link(); $Product = new Product($gift_product_id); $cover_id = Product::getCover($gift_product_id); $link_rewrite = $Product->link_rewrite[$id_lang]; $img_url = $link->getImageLink($link_rewrite, $cover_id['id_image']); $product_details[] = array("product_id" => $gift_product_id, "product_name" => $product_name, "img_url" => $img_url, "get_product_gift_quan" => $getY, "product_quan" => $getrulesone['get_quantity'], "default_attribute" => $default_attribute, "id_shop" => $id_shop, "id_country" => $id_country, "id_currency" => $id_currency, "id_customer" => $id_customer, "id_cart" => $id_cart, "group_id" => 0, "id_rule" => $getrulesone['id'], "Validity_from" => $Validity_from, "Validity_to" => $Validity_to); } } } if (empty($this->context->cookie->giftpro_quan)) { $this->context->cookie->__set('giftpro_quan', 0); } if (!empty($product_details)) { $this->context->smarty->assign(array( 'product_details' => $product_details, 'get_Y' => $getY, 'giftpro_quan' => $this->context->cookie->giftpro_quan, )); return $this -> display(__FILE__, '/views/templates/front/manual.tpl'); } else{ return $this -> display(__FILE__, '/views/templates/front/remove.tpl'); } } } } else{ return $this -> display(__FILE__, '/views/templates/front/remove.tpl'); } } else{ return $this -> display(__FILE__, '/views/templates/front/remove.tpl'); } // } // else{ // return $this -> display(__FILE__, '/views/templates/front/remove.tpl'); // } } } public function hookDisplayWrapperTop($params) { if (Configuration::get('addifyfreegifts_module_enable') == 0 || Configuration::get('addifyfreegifts_banner_position') == 2) { return; } $id_product = (int)Tools::getValue('id_product'); $id_category = (int)Tools::getValue('id_category'); $id_supplier = 0; if ($id_product) { // Get the product object $product = new Product($id_product); // Check if the product has a supplier if ($product->id_supplier) { $id_supplier = (int) $product->id_supplier; } } $PromotionRule = AddifyfreegiftsPromotionModel::getPromotionRule($id_product,$id_supplier, $id_category); if (!$PromotionRule) { return; } $addifyfreegifts_Background_image = ''; $addifyfreegifts_bg_color = Configuration::get('addifyfreegifts_bg_color'); $addifyfreegifts_text_color = Configuration::get('addifyfreegifts_text_color'); $addifyfreegifts_enable_bg_image = Configuration::get('addifyfreegifts_enable_bg_image'); $addifyfreegifts_text_font = Configuration::get('addifyfreegifts_text_font'); $addifyfreegifts_Bar_Width = Configuration::get('addifyfreegifts_Bar_Width'); $baseUrl = $this->context->shop->getBaseURL(true); $id_lang = (int)$this->context->language->id; $message = Configuration::get('message_'.$id_lang); if ($addifyfreegifts_enable_bg_image) { $addifyfreegifts_Background_image = Configuration::get('addifyfreegifts_Background_image'); } $this->context->smarty->assign(array( 'Background_image' => $addifyfreegifts_Background_image, 'addifyfreegifts_Bar_Width' => $addifyfreegifts_Bar_Width, 'baseUrl' => $baseUrl, 'addifyfreegifts_bg_color' => $addifyfreegifts_bg_color, 'addifyfreegifts_text_color' => $addifyfreegifts_text_color, 'addifyfreegifts_text_font' => $addifyfreegifts_text_font, 'message' => $message, )); return $this -> display(__FILE__, '/views/templates/front/header.tpl'); } public function hookDisplayWrapperBottom($params) { if (Configuration::get('addifyfreegifts_module_enable') == 0 || Configuration::get('addifyfreegifts_banner_position') == 1) { return; } $id_product = (int)Tools::getValue('id_product'); $id_category = (int)Tools::getValue('id_category'); $id_supplier = 0; if ($id_product) { // Get the product object $product = new Product($id_product); // Check if the product has a supplier if ($product->id_supplier) { $id_supplier = (int) $product->id_supplier; } } $PromotionRule = AddifyfreegiftsPromotionModel::getPromotionRule($id_product,$id_supplier, $id_category); if (!$PromotionRule) { return; } $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); $addifyfreegifts_Background_image = ''; $addifyfreegifts_Bar_Width = Configuration::get('addifyfreegifts_Bar_Width'); $addifyfreegifts_bg_color = Configuration::get('addifyfreegifts_bg_color'); $addifyfreegifts_enable_bg_image = Configuration::get('addifyfreegifts_enable_bg_image'); $addifyfreegifts_text_color = Configuration::get('addifyfreegifts_text_color'); $addifyfreegifts_text_font = Configuration::get('addifyfreegifts_text_font'); $baseUrl = $this->context->shop->getBaseURL(true); $id_lang = (int)$this->context->language->id; $message = Configuration::get('message_'.$id_lang); if ($addifyfreegifts_enable_bg_image) { $addifyfreegifts_Background_image = Configuration::get('addifyfreegifts_Background_image'); } $this->context->smarty->assign(array( 'Background_image' => $addifyfreegifts_Background_image, 'addifyfreegifts_Bar_Width' => $addifyfreegifts_Bar_Width, 'addifyfreegifts_bg_color' => $addifyfreegifts_bg_color, 'addifyfreegifts_text_color' => $addifyfreegifts_text_color, 'addifyfreegifts_text_font' => $addifyfreegifts_text_font, 'baseUrl' => $baseUrl, 'message' => $message, )); return $this -> display(__FILE__, '/views/templates/front/footer.tpl'); } public function hookHeader() { // echo "<pre>"; // print_r(Context::getContext()->cookie->Add_gift_ids);exit; $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); $context=Context::getContext(); if ($addifyfreegifts_module_enable == 1 && !empty($context->cart->id)) { $link = new Link(); $afg_ajax_link = $link->getModuleLink($this->name, 'addtocart'); Media::addJsDef(array( "afg_ajax_link" => $afg_ajax_link, )); $type = Dispatcher::getInstance()->getController(); if ($type == "cart") { $predefinedrules = AddifyfreegiftspredefinedModel::getPreDefinedRule(); $rules = AddifyfreegiftsModel::getrule(); if ($rules || $predefinedrules) { $this->context->controller->addJS($this->_path.'views/js/afg_manual.js'); $this->context->controller->addJS($this->_path.'views/js/addtocart.js'); } } } } public function quantitynotchange() { $context=Context::getContext(); $id_shop = $context->shop->id; $id_country = $context->country->id; $id_currency = $context->cart->id_currency; $id_customer = 0; $id_cart = $context->cart->id; $id_product = Tools::getValue('id_product'); $id_product_attribute = Tools::getValue('id_product_attribute'); $rules = AddifyfreegiftsModel::getrule(); $predefinedrules = AddifyfreegiftspredefinedModel::getPreDefinedRule(); if (Tools::getValue('update') && Tools::getValue('op')) { if ($rules || $predefinedrules) { foreach ($rules as $rule) { $specific_price = SpecificPrice::getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, 0, $rule['get_quantity'], $id_product_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $arr = []; $arr[]=$this->l('Quantity of this product cannot change'); $respon = json_encode($arr); echo $respon; die(); } } } foreach ($predefinedrules as $predefinedrule) { $specific_price = SpecificPrice::getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, 0, $predefinedrule['gift_quantity'], $id_product_attribute, $id_customer,$id_cart); if ($specific_price) { if ($specific_price['price'] == 0) { $arr = []; $arr[]=$this->l('Quantity of this product cannot change'); $respon = json_encode($arr); echo $respon; die(); } } } } } } public function hookActionBeforeCartUpdateQty() { $type = Dispatcher::getInstance()->getController(); if($type == 'cart'){ $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); $context=Context::getContext(); if ($addifyfreegifts_module_enable == 1 && !empty($context->cart->id)) { $this->quantitynotchange(); } } } public function hookActionCartUpdateQuantityBefore() { $type = Dispatcher::getInstance()->getController(); if($type == 'cart'){ $addifyfreegifts_module_enable = Configuration::get('addifyfreegifts_module_enable'); $context=Context::getContext(); if ($addifyfreegifts_module_enable == 1 && !empty($context->cart->id)) { $this->quantitynotchange(); } } } }
Close