Advertisement
Guest User

mailalerts help

a guest
Jul 1st, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 37.65 KB | None | 0 0
  1. <?php
  2. /**
  3.  * 2007-2015 PrestaShop
  4.  *
  5.  * NOTICE OF LICENSE
  6.  *
  7.  * This source file is subject to the Academic Free License (AFL 3.0)
  8.  * that is bundled with this package in the file LICENSE.txt.
  9.  * It is also available through the world-wide-web at this URL:
  10.  * http://opensource.org/licenses/afl-3.0.php
  11.  * If you did not receive a copy of the license and are unable to
  12.  * obtain it through the world-wide-web, please send an email
  13.  * to license@prestashop.com so we can send you a copy immediately.
  14.  *
  15.  * DISCLAIMER
  16.  *
  17.  * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18.  * versions in the future. If you wish to customize PrestaShop for your
  19.  * needs please refer to http://www.prestashop.com for more information.
  20.  *
  21.  * @author    PrestaShop SA <contact@prestashop.com>
  22.  * @copyright 2007-2015 PrestaShop SA
  23.  * @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  24.  * International Registered Trademark & Property of PrestaShop SA
  25.  */
  26.  
  27. if (!defined('_CAN_LOAD_FILES_'))
  28.     exit;
  29.  
  30. include_once(dirname(__FILE__).'/MailAlert.php');
  31.  
  32. class MailAlerts extends Module
  33. {
  34.     protected $html = '';
  35.  
  36.     protected $merchant_mails;
  37.     protected $merchant_order;
  38.     protected $merchant_oos;
  39.     protected $customer_qty;
  40.     protected $merchant_coverage;
  41.     protected $product_coverage;
  42.     protected $order_edited;
  43.     protected $return_slip;
  44.  
  45.     const __MA_MAIL_DELIMITOR__ = "\n";
  46.  
  47.     public function __construct()
  48.     {
  49.         $this->name = 'mailalerts';
  50.         $this->tab = 'administration';
  51.         $this->version = '3.6.0';
  52.         $this->author = 'PrestaShop';
  53.         $this->need_instance = 0;
  54.  
  55.         $this->controllers = array('account');
  56.  
  57.         $this->bootstrap = true;
  58.         parent::__construct();
  59.  
  60.         if ($this->id)
  61.             $this->init();
  62.  
  63.         $this->displayName = $this->l('Mail alerts');
  64.         $this->description = $this->l('Sends e-mail notifications to customers and merchants.');
  65.         $this->confirmUninstall = $this->l('Are you sure you want to delete all customer notifications?');
  66.     }
  67.  
  68.     protected function init()
  69.     {
  70.         $this->merchant_mails = str_replace(',', self::__MA_MAIL_DELIMITOR__, (string)Configuration::get('MA_MERCHANT_MAILS'));
  71.         $this->merchant_order = (int)Configuration::get('MA_MERCHANT_ORDER');
  72.         $this->merchant_oos = (int)Configuration::get('MA_MERCHANT_OOS');
  73.         $this->customer_qty = (int)Configuration::get('MA_CUSTOMER_QTY');
  74.         $this->merchant_coverage = (int)Configuration::getGlobalValue('MA_MERCHANT_COVERAGE');
  75.         $this->product_coverage = (int)Configuration::getGlobalValue('MA_PRODUCT_COVERAGE');
  76.         $this->order_edited = (int)Configuration::getGlobalValue('MA_ORDER_EDIT');
  77.         $this->return_slip = (int)Configuration::getGlobalValue('MA_RETURN_SLIP');
  78.     }
  79.  
  80.     public function install($delete_params = true)
  81.     {
  82.         if (!parent::install() ||
  83.             !$this->registerHook('actionValidateOrder') ||
  84.             !$this->registerHook('actionUpdateQuantity') ||
  85.             !$this->registerHook('actionProductOutOfStock') ||
  86.             !$this->registerHook('displayCustomerAccount') ||
  87.             !$this->registerHook('displayMyAccountBlock') ||
  88.             !$this->registerHook('actionProductDelete') ||
  89.             !$this->registerHook('actionProductAttributeDelete') ||
  90.             !$this->registerHook('actionProductAttributeUpdate') ||
  91.             !$this->registerHook('actionProductCoverage') ||
  92.             !$this->registerHook('actionOrderReturn') ||
  93.             !$this->registerHook('actionOrderEdited') ||
  94.             !$this->registerHook('displayHeader'))
  95.             return false;
  96.  
  97.         if ($delete_params)
  98.         {
  99.             Configuration::updateValue('MA_MERCHANT_ORDER', 1);
  100.             Configuration::updateValue('MA_MERCHANT_OOS', 1);
  101.             Configuration::updateValue('MA_CUSTOMER_QTY', 1);
  102.             Configuration::updateValue('MA_ORDER_EDIT', 1);
  103.             Configuration::updateValue('MA_RETURN_SLIP', 1);
  104.             Configuration::updateValue('MA_MERCHANT_MAILS', Configuration::get('PS_SHOP_EMAIL'));
  105.             Configuration::updateValue('MA_LAST_QTIES', (int)Configuration::get('PS_LAST_QTIES'));
  106.             Configuration::updateGlobalValue('MA_MERCHANT_COVERAGE', 0);
  107.             Configuration::updateGlobalValue('MA_PRODUCT_COVERAGE', 0);
  108.  
  109.             $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.MailAlert::$definition['table'].'`
  110.                 (
  111.                     `id_customer` int(10) unsigned NOT NULL,
  112.                     `customer_email` varchar(128) NOT NULL,
  113.                     `id_product` int(10) unsigned NOT NULL,
  114.                     `id_product_attribute` int(10) unsigned NOT NULL,
  115.                     `id_shop` int(10) unsigned NOT NULL,
  116.                     `id_lang` int(10) unsigned NOT NULL,
  117.                     PRIMARY KEY  (`id_customer`,`customer_email`,`id_product`,`id_product_attribute`,`id_shop`)
  118.                 ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
  119.  
  120.             if (!Db::getInstance()->execute($sql))
  121.                 return false;
  122.         }
  123.  
  124.         return true;
  125.     }
  126.  
  127.     public function uninstall($delete_params = true)
  128.     {
  129.         if ($delete_params)
  130.         {
  131.             Configuration::deleteByName('MA_MERCHANT_ORDER');
  132.             Configuration::deleteByName('MA_MERCHANT_OOS');
  133.             Configuration::deleteByName('MA_CUSTOMER_QTY');
  134.             Configuration::deleteByName('MA_MERCHANT_MAILS');
  135.             Configuration::deleteByName('MA_LAST_QTIES');
  136.             Configuration::deleteByName('MA_MERCHANT_COVERAGE');
  137.             Configuration::deleteByName('MA_PRODUCT_COVERAGE');
  138.             Configuration::deleteByName('MA_ORDER_EDIT');
  139.             Configuration::deleteByName('MA_RETURN_SLIP');
  140.  
  141.             if (!Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.MailAlert::$definition['table']))
  142.                 return false;
  143.         }
  144.  
  145.         return parent::uninstall();
  146.     }
  147.  
  148.     public function reset()
  149.     {
  150.         if (!$this->uninstall(false))
  151.             return false;
  152.         if (!$this->install(false))
  153.             return false;
  154.  
  155.         return true;
  156.     }
  157.  
  158.     public function getContent()
  159.     {
  160.         $this->html = '';
  161.  
  162.         $this->postProcess();
  163.  
  164.         $this->html .= $this->renderForm();
  165.  
  166.         return $this->html;
  167.     }
  168.  
  169.     protected function postProcess()
  170.     {
  171.         $errors = array();
  172.  
  173.         if (Tools::isSubmit('submitMailAlert'))
  174.         {
  175.             if (!Configuration::updateValue('MA_CUSTOMER_QTY', (int)Tools::getValue('MA_CUSTOMER_QTY')))
  176.                 $errors[] = $this->l('Cannot update settings');
  177.         }
  178.         else if (Tools::isSubmit('submitMAMerchant'))
  179.         {
  180.             $emails = (string)Tools::getValue('MA_MERCHANT_MAILS');
  181.  
  182.             if (!$emails || empty($emails))
  183.                 $errors[] = $this->l('Please type one (or more) e-mail address');
  184.             else
  185.             {
  186.                 $emails = str_replace(',', self::__MA_MAIL_DELIMITOR__, $emails);
  187.                 $emails = explode(self::__MA_MAIL_DELIMITOR__, $emails);
  188.                 foreach ($emails as $k => $email)
  189.                 {
  190.                     $email = trim($email);
  191.                     if (!empty($email) && !Validate::isEmail($email))
  192.                     {
  193.                         $errors[] = $this->l('Invalid e-mail:').' '.Tools::safeOutput($email);
  194.                         break;
  195.                     }
  196.                     elseif (!empty($email) && count($email) > 0)
  197.                         $emails[$k] = $email;
  198.                     else
  199.                         unset($emails[$k]);
  200.                 }
  201.  
  202.                 $emails = implode(self::__MA_MAIL_DELIMITOR__, $emails);
  203.  
  204.                 if (!Configuration::updateValue('MA_MERCHANT_MAILS', (string)$emails))
  205.                     $errors[] = $this->l('Cannot update settings');
  206.                 elseif (!Configuration::updateValue('MA_MERCHANT_ORDER', (int)Tools::getValue('MA_MERCHANT_ORDER')))
  207.                     $errors[] = $this->l('Cannot update settings');
  208.                 elseif (!Configuration::updateValue('MA_MERCHANT_OOS', (int)Tools::getValue('MA_MERCHANT_OOS')))
  209.                     $errors[] = $this->l('Cannot update settings');
  210.                 elseif (!Configuration::updateValue('MA_LAST_QTIES', (int)Tools::getValue('MA_LAST_QTIES')))
  211.                     $errors[] = $this->l('Cannot update settings');
  212.                 elseif (!Configuration::updateGlobalValue('MA_MERCHANT_COVERAGE', (int)Tools::getValue('MA_MERCHANT_COVERAGE')))
  213.                     $errors[] = $this->l('Cannot update settings');
  214.                 elseif (!Configuration::updateGlobalValue('MA_PRODUCT_COVERAGE', (int)Tools::getValue('MA_PRODUCT_COVERAGE')))
  215.                     $errors[] = $this->l('Cannot update settings');
  216.                 elseif (!Configuration::updateGlobalValue('MA_ORDER_EDIT', (int)Tools::getValue('MA_ORDER_EDIT')))
  217.                     $errors[] = $this->l('Cannot update settings');
  218.                 elseif (!Configuration::updateGlobalValue('MA_RETURN_SLIP', (int)Tools::getValue('MA_RETURN_SLIP')))
  219.                     $errors[] = $this->l('Cannot update settings');
  220.             }
  221.         }
  222.  
  223.         if (count($errors) > 0)
  224.             $this->html .= $this->displayError(implode('<br />', $errors));
  225.         else
  226.             $this->html .= $this->displayConfirmation($this->l('Settings updated successfully'));
  227.  
  228.         $this->init();
  229.     }
  230.  
  231.     public function getAllMessages($id)
  232.     {
  233.         $messages = Db::getInstance()->executeS('
  234.             SELECT `message`
  235.             FROM `'._DB_PREFIX_.'message`
  236.             WHERE `id_order` = '.(int)$id.'
  237.             ORDER BY `id_message` ASC');
  238.         $result = array();
  239.         foreach ($messages as $message)
  240.             $result[] = $message['message'];
  241.  
  242.         return implode('<br/>', $result);
  243.     }
  244.  
  245.     public function hookActionValidateOrder($params)
  246.     {
  247.         if (!$this->merchant_order || empty($this->merchant_mails))
  248.             return;
  249.  
  250.         // Getting differents vars
  251.         $context = Context::getContext();
  252.         $id_lang = (int)$context->language->id;
  253.         $id_shop = (int)$context->shop->id;
  254.         $currency = $params['currency'];
  255.         $order = $params['order'];
  256.         $customer = $params['customer'];
  257.         $configuration = Configuration::getMultiple(
  258.             array(
  259.                 'PS_SHOP_EMAIL',
  260.                 'PS_MAIL_METHOD',
  261.                 'PS_MAIL_SERVER',
  262.                 'PS_MAIL_USER',
  263.                 'PS_MAIL_PASSWD',
  264.                 'PS_SHOP_NAME',
  265.                 'PS_MAIL_COLOR'
  266.             ), $id_lang, null, $id_shop
  267.         );
  268.         $delivery = new Address((int)$order->id_address_delivery);
  269.         $invoice = new Address((int)$order->id_address_invoice);
  270.         $order_date_text = Tools::displayDate($order->date_add);
  271.         $carrier = new Carrier((int)$order->id_carrier);
  272.         $message = $this->getAllMessages($order->id);
  273.  
  274.         if (!$message || empty($message))
  275.             $message = $this->l('No message');
  276.  
  277.         $items_table = '';
  278.  
  279.         $products = $params['order']->getProducts();
  280.         $customized_datas = Product::getAllCustomizedDatas((int)$params['cart']->id);
  281.         Product::addCustomizationPrice($products, $customized_datas);
  282.         foreach ($products as $key => $product)
  283.         {
  284.             $unit_price = Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC ? $product['product_price'] : $product['product_price_wt'];
  285.  
  286.             $customization_text = '';
  287.             if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']]))
  288.             {
  289.                 foreach ($customized_datas[$product['product_id']][$product['product_attribute_id']][$order->id_address_delivery] as $customization)
  290.                 {
  291.                     if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD]))
  292.                         foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] as $text)
  293.                             $customization_text .= $text['name'].': '.$text['value'].'<br />';
  294.  
  295.                     if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
  296.                         $customization_text .= count($customization['datas'][Product::CUSTOMIZE_FILE]).' '.$this->l('image(s)').'<br />';
  297.  
  298.                     $customization_text .= '---<br />';
  299.                 }
  300.                 if (method_exists('Tools', 'rtrimString'))
  301.                     $customization_text = Tools::rtrimString($customization_text, '---<br />');
  302.                 else
  303.                     $customization_text = preg_replace('/---<br \/>$/', '', $customization_text);
  304.             }
  305.  
  306.             $url = $context->link->getProductLink($product['product_id']);
  307.             $items_table .=
  308.                 '<tr style="background-color:'.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
  309.                     <td style="padding:0.6em 0.4em;">'.$product['product_reference'].'</td>
  310.                     <td style="padding:0.6em 0.4em;">
  311.                         <strong><a href="'.$url.'">'.$product['product_name'].'</a>'
  312.                             .(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '')
  313.                             .(!empty($customization_text) ? '<br />'.$customization_text : '')
  314.                         .'</strong>
  315.                     </td>
  316.                     <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td>
  317.                     <td style="padding:0.6em 0.4em; text-align:center;">'.(int)$product['product_quantity'].'</td>
  318.                     <td style="padding:0.6em 0.4em; text-align:right;">'
  319.                         .Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false)
  320.                     .'</td>
  321.                 </tr>';
  322.         }
  323.         foreach ($params['order']->getCartRules() as $discount)
  324.         {
  325.             $items_table .=
  326.                 '<tr style="background-color:#EBECEE;">
  327.                         <td colspan="4" style="padding:0.6em 0.4em; text-align:right;">'.$this->l('Voucher code:').' '.$discount['name'].'</td>
  328.                     <td style="padding:0.6em 0.4em; text-align:right;">-'.Tools::displayPrice($discount['value'], $currency, false).'</td>
  329.             </tr>';
  330.         }
  331.         if ($delivery->id_state)
  332.             $delivery_state = new State((int)$delivery->id_state);
  333.         if ($invoice->id_state)
  334.             $invoice_state = new State((int)$invoice->id_state);
  335.  
  336.         if (Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC)
  337.             $total_products = $order->getTotalProductsWithoutTaxes();
  338.         else
  339.             $total_products = $order->getTotalProductsWithTaxes();
  340.  
  341.         $order_state = $params['orderStatus'];
  342.  
  343.         // Filling-in vars for email
  344.         $template_vars = array(
  345.             '{firstname}' => $customer->firstname,
  346.             '{lastname}' => $customer->lastname,
  347.             '{email}' => $customer->email,
  348.             '{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"),
  349.             '{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"),
  350.             '{delivery_block_html}' => MailAlert::getFormatedAddress(
  351.                 $delivery, '<br />', array(
  352.                     'firstname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>',
  353.                     'lastname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>'
  354.                 )
  355.             ),
  356.             '{invoice_block_html}' => MailAlert::getFormatedAddress(
  357.                 $invoice, '<br />', array(
  358.                     'firstname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>',
  359.                     'lastname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>'
  360.                 )
  361.             ),
  362.             '{delivery_company}' => $delivery->company,
  363.             '{delivery_firstname}' => $delivery->firstname,
  364.             '{delivery_lastname}' => $delivery->lastname,
  365.             '{delivery_address1}' => $delivery->address1,
  366.             '{delivery_address2}' => $delivery->address2,
  367.             '{delivery_city}' => $delivery->city,
  368.             '{delivery_postal_code}' => $delivery->postcode,
  369.             '{delivery_country}' => $delivery->country,
  370.             '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '',
  371.             '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile,
  372.             '{delivery_other}' => $delivery->other,
  373.             '{invoice_company}' => $invoice->company,
  374.             '{invoice_firstname}' => $invoice->firstname,
  375.             '{invoice_lastname}' => $invoice->lastname,
  376.             '{invoice_address2}' => $invoice->address2,
  377.             '{invoice_address1}' => $invoice->address1,
  378.             '{invoice_city}' => $invoice->city,
  379.             '{invoice_postal_code}' => $invoice->postcode,
  380.             '{invoice_country}' => $invoice->country,
  381.             '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '',
  382.             '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile,
  383.             '{invoice_other}' => $invoice->other,
  384.             //'{order_name}' => $order->reference,
  385.             '{order_name}' => $order->id,
  386.             '{order_status}' => $order_state->name,
  387.             '{shop_name}' => $configuration['PS_SHOP_NAME'],
  388.             '{date}' => $order_date_text,
  389.             '{carrier}' => (($carrier->name == '0') ? $configuration['PS_SHOP_NAME'] : $carrier->name),
  390.             '{payment}' => Tools::substr($order->payment, 0, 32),
  391.             '{items}' => $items_table,
  392.             '{total_paid}' => Tools::displayPrice($order->total_paid, $currency),
  393.             '{total_products}' => Tools::displayPrice($total_products, $currency),
  394.             '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency),
  395.             '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency),
  396.             '{total_tax_paid}' => Tools::displayPrice(
  397.                 ($order->total_products_wt - $order->total_products) + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl),
  398.                 $currency,
  399.                 false
  400.             ),
  401.             '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency),
  402.             '{currency}' => $currency->sign,
  403.             '{gift}' => (bool)$order->gift,
  404.             '{gift_message}' => $order->gift_message,
  405.             '{message}' => $message
  406.         );
  407.  
  408.         // Shop iso
  409.         $iso = Language::getIsoById((int)Configuration::get('PS_LANG_DEFAULT'));
  410.  
  411.         // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
  412.         $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails);
  413.         foreach ($merchant_mails as $merchant_mail)
  414.         {
  415.             // Default language
  416.             $mail_id_lang = $id_lang;
  417.             $mail_iso = $iso;
  418.  
  419.             // Use the merchant lang if he exists as an employee
  420.             $results = Db::getInstance()->executeS('
  421.                 SELECT `id_lang` FROM `'._DB_PREFIX_.'employee`
  422.                 WHERE `email` = \''.pSQL($merchant_mail).'\'
  423.             ');
  424.             if ($results)
  425.             {
  426.                 $user_iso = Language::getIsoById((int)$results[0]['id_lang']);
  427.                 if ($user_iso)
  428.                 {
  429.                     $mail_id_lang = (int)$results[0]['id_lang'];
  430.                     $mail_iso = $user_iso;
  431.                 }
  432.             }
  433.  
  434.             $dir_mail = false;
  435.             if (file_exists(dirname(__FILE__).'/mails/'.$mail_iso.'/new_order.txt') &&
  436.                 file_exists(dirname(__FILE__).'/mails/'.$mail_iso.'/new_order.html'))
  437.                 $dir_mail = dirname(__FILE__).'/mails/';
  438.  
  439.             if (file_exists(_PS_MAIL_DIR_.$mail_iso.'/new_order.txt') &&
  440.                 file_exists(_PS_MAIL_DIR_.$mail_iso.'/new_order.html'))
  441.                 $dir_mail = _PS_MAIL_DIR_;
  442.  
  443.             if ($dir_mail)
  444.                 Mail::Send(
  445.                     $mail_id_lang,
  446.                     'new_order',
  447.                     sprintf(Mail::l('New order : #%d - %s', $mail_id_lang), $order->id, $order->reference),
  448.                     $template_vars,
  449.                     $merchant_mail,
  450.                     null,
  451.                     $configuration['PS_SHOP_EMAIL'],
  452.                     $configuration['PS_SHOP_NAME'],
  453.                     null,
  454.                     null,
  455.                     $dir_mail,
  456.                     null,
  457.                     $id_shop
  458.                 );
  459.         }
  460.     }
  461.  
  462.     public function hookActionProductOutOfStock($params)
  463.     {
  464.         if (!$this->customer_qty ||
  465.             !Configuration::get('PS_STOCK_MANAGEMENT') ||
  466.             Product::isAvailableWhenOutOfStock($params['product']->out_of_stock))
  467.             return;
  468.  
  469.         $context = Context::getContext();
  470.         $id_product = (int)$params['product']->id;
  471.         $id_product_attribute = 0;
  472.         $id_customer = (int)$context->customer->id;
  473.  
  474.         if ((int)$context->customer->id <= 0)
  475.             $this->context->smarty->assign('email', 1);
  476.         elseif (MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute, (int)$context->shop->id))
  477.             return;
  478.  
  479.         $this->context->smarty->assign(
  480.             array(
  481.                 'id_product' => $id_product,
  482.                 'id_product_attribute' => $id_product_attribute
  483.             )
  484.         );
  485.  
  486.         return $this->display(__FILE__, 'product.tpl');
  487.     }
  488.  
  489.     public function hookActionUpdateQuantity($params)
  490.     {
  491.         $id_product = (int)$params['id_product'];
  492.         $id_product_attribute = (int)$params['id_product_attribute'];
  493.  
  494.         $quantity = (int)$params['quantity'];
  495.         $context = Context::getContext();
  496.         $id_shop = (int)$context->shop->id;
  497.         $id_lang = (int)$context->language->id;
  498.         $product = new Product($id_product, false, $id_lang, $id_shop, $context);
  499.         $product_has_attributes = $product->hasAttributes();
  500.         $configuration = Configuration::getMultiple(
  501.             array(
  502.                 'MA_LAST_QTIES',
  503.                 'PS_STOCK_MANAGEMENT',
  504.                 'PS_SHOP_EMAIL',
  505.                 'PS_SHOP_NAME'
  506.             ), null, null, $id_shop
  507.         );
  508.         $ma_last_qties = (int)$configuration['MA_LAST_QTIES'];
  509.  
  510.         $check_oos = ($product_has_attributes && $id_product_attribute) || (!$product_has_attributes && !$id_product_attribute);
  511.  
  512.         if ($check_oos &&
  513.             $product->active == 1 &&
  514.             (int)$quantity <= $ma_last_qties &&
  515.             !(!$this->merchant_oos || empty($this->merchant_mails)) &&
  516.             $configuration['PS_STOCK_MANAGEMENT'])
  517.         {
  518.             $iso = Language::getIsoById($id_lang);
  519.             $product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang);
  520.             $template_vars = array(
  521.                 '{qty}' => $quantity,
  522.                 '{last_qty}' => $ma_last_qties,
  523.                 '{product}' => $product_name
  524.             );
  525.  
  526.             // Do not send mail if multiples product are created / imported.
  527.             if (!defined('PS_MASS_PRODUCT_CREATION') &&
  528.                 file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.txt') &&
  529.                 file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.html'))
  530.             {
  531.                 // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
  532.                 $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails);
  533.                 foreach ($merchant_mails as $merchant_mail)
  534.                 {
  535.                     Mail::Send(
  536.                         $id_lang,
  537.                         'productoutofstock',
  538.                         Mail::l('Product out of stock', $id_lang),
  539.                         $template_vars,
  540.                         $merchant_mail,
  541.                         null,
  542.                         (string)$configuration['PS_SHOP_EMAIL'],
  543.                         (string)$configuration['PS_SHOP_NAME'],
  544.                         null,
  545.                         null,
  546.                         dirname(__FILE__).'/mails/',
  547.                         false,
  548.                         $id_shop
  549.                     );
  550.                 }
  551.             }
  552.         }
  553.  
  554.         if ($this->customer_qty && $quantity > 0)
  555.             MailAlert::sendCustomerAlert((int)$product->id, (int)$params['id_product_attribute']);
  556.     }
  557.  
  558.     public function hookActionProductAttributeUpdate($params)
  559.     {
  560.         $sql = '
  561.             SELECT `id_product`, `quantity`
  562.             FROM `'._DB_PREFIX_.'stock_available`
  563.             WHERE `id_product_attribute` = '.(int)$params['id_product_attribute'];
  564.  
  565.         $result = Db::getInstance()->getRow($sql);
  566.  
  567.         if ($this->customer_qty && $result['quantity'] > 0)
  568.             MailAlert::sendCustomerAlert((int)$result['id_product'], (int)$params['id_product_attribute']);
  569.     }
  570.  
  571.     public function hookDisplayCustomerAccount()
  572.     {
  573.         return $this->customer_qty ? $this->display(__FILE__, 'my-account.tpl') : null;
  574.     }
  575.  
  576.     public function hookDisplayMyAccountBlock($params)
  577.     {
  578.         return $this->hookDisplayCustomerAccount($params);
  579.     }
  580.  
  581.     public function hookActionProductDelete($params)
  582.     {
  583.         $sql = '
  584.             DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
  585.             WHERE `id_product` = '.(int)$params['product']->id;
  586.  
  587.         Db::getInstance()->execute($sql);
  588.     }
  589.  
  590.     public function hookActionAttributeDelete($params)
  591.     {
  592.         if ($params['deleteAllAttributes'])
  593.             $sql = '
  594.                 DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
  595.                 WHERE `id_product` = '.(int)$params['id_product'];
  596.         else
  597.             $sql = '
  598.                 DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
  599.                 WHERE `id_product_attribute` = '.(int)$params['id_product_attribute'].'
  600.                 AND `id_product` = '.(int)$params['id_product'];
  601.  
  602.         Db::getInstance()->execute($sql);
  603.     }
  604.  
  605.     public function hookActionProductCoverage($params)
  606.     {
  607.         // if not advanced stock management, nothing to do
  608.         if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
  609.             return;
  610.  
  611.         // retrieves informations
  612.         $id_product = (int)$params['id_product'];
  613.         $id_product_attribute = (int)$params['id_product_attribute'];
  614.         $warehouse = $params['warehouse'];
  615.         $product = new Product($id_product);
  616.  
  617.         if (!Validate::isLoadedObject($product))
  618.             return;
  619.  
  620.         if (!$product->advanced_stock_management)
  621.             return;
  622.  
  623.         // sets warehouse id to get the coverage
  624.         if (!Validate::isLoadedObject($warehouse))
  625.             $id_warehouse = 0;
  626.         else
  627.             $id_warehouse = (int)$warehouse->id;
  628.  
  629.         // coverage of the product
  630.         $warning_coverage = (int)Configuration::getGlobalValue('MA_PRODUCT_COVERAGE');
  631.  
  632.         $coverage = StockManagerFactory::getManager()->getProductCoverage($id_product, $id_product_attribute, $warning_coverage, $id_warehouse);
  633.  
  634.         // if we need to send a notification
  635.         if ($product->active == 1 &&
  636.             ($coverage < $warning_coverage) && !empty($this->merchant_mails) &&
  637.             Configuration::getGlobalValue('MA_MERCHANT_COVERAGE'))
  638.         {
  639.             $context = Context::getContext();
  640.             $id_lang = (int)$context->language->id;
  641.             $id_shop = (int)$context->shop->id;
  642.             $iso = Language::getIsoById($id_lang);
  643.             $product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang);
  644.             $template_vars = array(
  645.                 '{current_coverage}' => $coverage,
  646.                 '{warning_coverage}' => $warning_coverage,
  647.                 '{product}' => pSQL($product_name)
  648.             );
  649.  
  650.             if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.txt') &&
  651.                 file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.html'))
  652.             {
  653.                 // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
  654.                 $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails);
  655.                 foreach ($merchant_mails as $merchant_mail)
  656.                 {
  657.                     Mail::Send(
  658.                         $id_lang,
  659.                         'productcoverage',
  660.                         Mail::l('Stock coverage', $id_lang),
  661.                         $template_vars,
  662.                         $merchant_mail,
  663.                         null,
  664.                         (string)Configuration::get('PS_SHOP_EMAIL'),
  665.                         (string)Configuration::get('PS_SHOP_NAME'),
  666.                         null,
  667.                         null,
  668.                         dirname(__FILE__).'/mails/',
  669.                         null,
  670.                         $id_shop
  671.                     );
  672.                 }
  673.             }
  674.         }
  675.     }
  676.  
  677.     public function hookDisplayHeader()
  678.     {
  679.         $this->page_name = Dispatcher::getInstance()->getController();
  680.         if (in_array($this->page_name, array('product', 'account')))
  681.         {
  682.             $this->context->controller->addJS($this->_path.'js/mailalerts.js');
  683.             $this->context->controller->addCSS($this->_path.'css/mailalerts.css', 'all');
  684.         }
  685.     }
  686.  
  687.     /**
  688.      * Send a mail when a customer return an order.
  689.      *
  690.      * @param array $params Hook params.
  691.      */
  692.     public function hookActionOrderReturn($params)
  693.     {
  694.         if (!$this->return_slip || empty($this->return_slip))
  695.             return;
  696.  
  697.         $context = Context::getContext();
  698.         $id_lang = (int)$context->language->id;
  699.         $id_shop = (int)$context->shop->id;
  700.         $configuration = Configuration::getMultiple(
  701.             array(
  702.                 'PS_SHOP_EMAIL',
  703.                 'PS_MAIL_METHOD',
  704.                 'PS_MAIL_SERVER',
  705.                 'PS_MAIL_USER',
  706.                 'PS_MAIL_PASSWD',
  707.                 'PS_SHOP_NAME',
  708.                 'PS_MAIL_COLOR'
  709.             ), $id_lang, null, $id_shop
  710.         );
  711.  
  712.         // Shop iso
  713.         $iso = Language::getIsoById((int)Configuration::get('PS_LANG_DEFAULT'));
  714.  
  715.         $order = new Order((int)$params['orderReturn']->id_order);
  716.         $customer = new Customer((int)$params['orderReturn']->id_customer);
  717.         $delivery = new Address((int)$order->id_address_delivery);
  718.         $invoice = new Address((int)$order->id_address_invoice);
  719.         $order_date_text = Tools::displayDate($order->date_add);
  720.         if ($delivery->id_state)
  721.             $delivery_state = new State((int)$delivery->id_state);
  722.         if ($invoice->id_state)
  723.             $invoice_state = new State((int)$invoice->id_state);
  724.  
  725.         $order_return_products = OrderReturn::getOrdersReturnProducts($params['orderReturn']->id, $order);
  726.  
  727.         $items_table = '';
  728.         foreach ($order_return_products as $key => $product)
  729.         {
  730.             $url = $context->link->getProductLink($product['product_id']);
  731.             $items_table .=
  732.                 '<tr style="background-color:'.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
  733.                     <td style="padding:0.6em 0.4em;">'.$product['product_reference'].'</td>
  734.                     <td style="padding:0.6em 0.4em;">
  735.                         <strong><a href="'.$url.'">'.$product['product_name'].'</a>
  736.                     </strong>
  737.                     </td>
  738.                     <td style="padding:0.6em 0.4em; text-align:center;">'.(int)$product['product_quantity'].'</td>
  739.                 </tr>';
  740.         }
  741.  
  742.         $template_vars = array(
  743.             '{firstname}' => $customer->firstname,         
  744.             '{lastname}' => $customer->lastname,
  745.             '{email}' => $customer->email,
  746.             '{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"),
  747.             '{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"),
  748.             '{delivery_block_html}' => MailAlert::getFormatedAddress(
  749.                 $delivery, '<br />', array(
  750.                     'firstname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>',
  751.                     'lastname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>'
  752.                 )
  753.             ),
  754.             '{invoice_block_html}' => MailAlert::getFormatedAddress(
  755.                 $invoice, '<br />', array(
  756.                     'firstname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>',
  757.                     'lastname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>'
  758.                 )
  759.             ),
  760.             '{delivery_company}' => $delivery->company,
  761.             '{delivery_firstname}' => $delivery->firstname,
  762.             '{delivery_lastname}' => $delivery->lastname,
  763.             '{delivery_address1}' => $delivery->address1,
  764.             '{delivery_address2}' => $delivery->address2,
  765.             '{delivery_city}' => $delivery->city,
  766.             '{delivery_postal_code}' => $delivery->postcode,
  767.             '{delivery_country}' => $delivery->country,
  768.             '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '',
  769.             '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile,
  770.             '{delivery_other}' => $delivery->other,
  771.             '{invoice_company}' => $invoice->company,
  772.             '{invoice_firstname}' => $invoice->firstname,
  773.             '{invoice_lastname}' => $invoice->lastname,
  774.             '{invoice_address2}' => $invoice->address2,
  775.             '{invoice_address1}' => $invoice->address1,
  776.             '{invoice_city}' => $invoice->city,
  777.             '{invoice_postal_code}' => $invoice->postcode,
  778.             '{invoice_country}' => $invoice->country,
  779.             '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '',
  780.             '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile,
  781.             '{invoice_other}' => $invoice->other,
  782.             //'{order_name}' => $order->reference, změna z reference na id
  783.             '{order_name}' => $order->id,
  784.             '{shop_name}' => $order->reference,
  785.             '{date}' => $order_date_text,
  786.             '{items}' => $items_table,
  787.             '{message}' => Tools::purifyHTML($params['orderReturn']->question)
  788.         );
  789.  
  790.         // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
  791.         $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails);
  792.         foreach ($merchant_mails as $merchant_mail)
  793.         {
  794.             // Default language
  795.             $mail_id_lang = $id_lang;
  796.             $mail_iso = $iso;
  797.  
  798.             // Use the merchant lang if he exists as an employee
  799.             $results = Db::getInstance()->executeS('
  800.                 SELECT `id_lang` FROM `'._DB_PREFIX_.'employee`
  801.                 WHERE `email` = \''.pSQL($merchant_mail).'\'
  802.             ');
  803.             if ($results)
  804.             {
  805.                 $user_iso = Language::getIsoById((int)$results[0]['id_lang']);
  806.                 if ($user_iso)
  807.                 {
  808.                     $mail_id_lang = (int)$results[0]['id_lang'];
  809.                     $mail_iso = $user_iso;
  810.                 }
  811.             }
  812.  
  813.             $dir_mail = false;
  814.             if (file_exists(dirname(__FILE__).'/mails/'.$mail_iso.'/return_slip.txt') &&
  815.                 file_exists(dirname(__FILE__).'/mails/'.$mail_iso.'/return_slip.html'))
  816.                 $dir_mail = dirname(__FILE__).'/mails/';
  817.  
  818.             if (file_exists(_PS_MAIL_DIR_.$mail_iso.'/return_slip.txt') &&
  819.                 file_exists(_PS_MAIL_DIR_.$mail_iso.'/return_slip.html'))
  820.                 $dir_mail = _PS_MAIL_DIR_;
  821.  
  822.             if ($dir_mail)
  823.                 Mail::Send(
  824.                     $mail_id_lang,
  825.                     'return_slip',
  826.                     sprintf(Mail::l('New return from order #%d - %s', $mail_id_lang), $order->id, $order->reference),
  827.                     $template_vars,
  828.                     $merchant_mail,
  829.                     null,
  830.                     $configuration['PS_SHOP_EMAIL'],
  831.                     $configuration['PS_SHOP_NAME'],
  832.                     null,
  833.                     null,
  834.                     $dir_mail,
  835.                     null,
  836.                     $id_shop
  837.                 );
  838.         }
  839.     }
  840.  
  841.  
  842.     /**
  843.      * Send a mail when an order is modified.
  844.      *
  845.      * @param array $params Hook params.
  846.      */
  847.     public function hookActionOrderEdited($params)
  848.     {
  849.         if (!$this->order_edited || empty($this->order_edited))
  850.             return;
  851.  
  852.         $order = $params['order'];
  853.  
  854.         $data = array(
  855.             '{lastname}' => $order->getCustomer()->lastname,
  856.             '{firstname}' => $order->getCustomer()->firstname,
  857.             '{id_order}' => (int)$order->id,
  858.             '{order_name}' => $order->getUniqReference()
  859.         );
  860.  
  861.         Mail::Send(
  862.             (int)$order->id_lang,
  863.             'order_changed',
  864.             Mail::l('Your order has been changed', (int)$order->id_lang),
  865.             $data,
  866.             $order->getCustomer()->email,
  867.             $order->getCustomer()->firstname.' '.$order->getCustomer()->lastname,
  868.             null, null, null, null, _PS_MAIL_DIR_, true, (int)$order->id_shop);
  869.     }
  870.  
  871.     public function renderForm()
  872.     {
  873.         $fields_form_1 = array(
  874.             'form' => array(
  875.                 'legend' => array(
  876.                     'title' => $this->l('Customer notifications'),
  877.                     'icon' => 'icon-cogs'
  878.                 ),
  879.                 'input' => array(
  880.                     array(
  881.                         'type' => 'switch',
  882.                         'is_bool' => true, //retro compat 1.5
  883.                         'label' => $this->l('Product availability'),
  884.                         'name' => 'MA_CUSTOMER_QTY',
  885.                         'desc' => $this->l('Gives the customer the option of receiving a notification when an out-of-stock product is available again.'),
  886.                         'values' => array(
  887.                             array(
  888.                                 'id' => 'active_on',
  889.                                 'value' => 1,
  890.                                 'label' => $this->l('Enabled')
  891.                             ),
  892.                             array(
  893.                                 'id' => 'active_off',
  894.                                 'value' => 0,
  895.                                 'label' => $this->l('Disabled')
  896.                             )
  897.                         ),
  898.                     ),
  899.                     array(
  900.                         'type' => 'switch',
  901.                         'is_bool' => true, //retro compat 1.5
  902.                         'label' => $this->l('Order edit'),
  903.                         'name' => 'MA_ORDER_EDIT',
  904.                         'desc' => $this->l('Send a notification to the customer when an order is edited.'),
  905.                         'values' => array(
  906.                             array(
  907.                                 'id' => 'active_on',
  908.                                 'value' => 1,
  909.                                 'label' => $this->l('Enabled')
  910.                             ),
  911.                             array(
  912.                                 'id' => 'active_off',
  913.                                 'value' => 0,
  914.                                 'label' => $this->l('Disabled')
  915.                             )
  916.                         ),
  917.                     ),
  918.                 ),
  919.                 'submit' => array(
  920.                     'title' => $this->l('Save'),
  921.                     'class' => 'btn btn-default pull-right',
  922.                     'name' => 'submitMailAlert',
  923.                 )
  924.             ),
  925.         );
  926.  
  927.         $fields_form_2 = array(
  928.             'form' => array(
  929.                 'legend' => array(
  930.                     'title' => $this->l('Merchant notifications'),
  931.                     'icon' => 'icon-cogs'
  932.                 ),
  933.                 'input' => array(
  934.                     array(
  935.                         'type' => 'switch',
  936.                         'is_bool' => true, //retro compat 1.5
  937.                         'label' => $this->l('New order'),
  938.                         'name' => 'MA_MERCHANT_ORDER',
  939.                         'desc' => $this->l('Receive a notification when an order is placed.'),
  940.                         'values' => array(
  941.                             array(
  942.                                 'id' => 'active_on',
  943.                                 'value' => 1,
  944.                                 'label' => $this->l('Enabled')
  945.                             ),
  946.                             array(
  947.                                 'id' => 'active_off',
  948.                                 'value' => 0,
  949.                                 'label' => $this->l('Disabled')
  950.                             )
  951.                         ),
  952.                     ),
  953.                     array(
  954.                         'type' => 'switch',
  955.                         'is_bool' => true, //retro compat 1.5
  956.                         'label' => $this->l('Out of stock'),
  957.                         'name' => 'MA_MERCHANT_OOS',
  958.                         'desc' => $this->l('Receive a notification if the available quantity of a product is below the following threshold.'),
  959.                         'values' => array(
  960.                             array(
  961.                                 'id' => 'active_on',
  962.                                 'value' => 1,
  963.                                 'label' => $this->l('Enabled')
  964.                             ),
  965.                             array(
  966.                                 'id' => 'active_off',
  967.                                 'value' => 0,
  968.                                 'label' => $this->l('Disabled')
  969.                             )
  970.                         ),
  971.                     ),
  972.                     array(
  973.                         'type' => 'text',
  974.                         'label' => $this->l('Threshold'),
  975.                         'name' => 'MA_LAST_QTIES',
  976.                         'class' => 'fixed-width-xs',
  977.                         'desc' => $this->l('Quantity for which a product is considered out of stock.'),
  978.                     ),
  979.                     array(
  980.                         'type' => 'switch',
  981.                         'is_bool' => true, //retro compat 1.5
  982.                         'label' => $this->l('Coverage warning'),
  983.                         'name' => 'MA_MERCHANT_COVERAGE',
  984.                         'desc' => $this->l('Receive a notification when a product has insufficient coverage.'),
  985.                         'values' => array(
  986.                             array(
  987.                                 'id' => 'active_on',
  988.                                 'value' => 1,
  989.                                 'label' => $this->l('Enabled')
  990.                             ),
  991.                             array(
  992.                                 'id' => 'active_off',
  993.                                 'value' => 0,
  994.                                 'label' => $this->l('Disabled')
  995.                             )
  996.                         ),
  997.                     ),
  998.                     array(
  999.                         'type' => 'text',
  1000.                         'label' => $this->l('Coverage'),
  1001.                         'name' => 'MA_PRODUCT_COVERAGE',
  1002.                         'class' => 'fixed-width-xs',
  1003.                         'desc' => $this->l('Stock coverage, in days. Also, the stock coverage of a given product will be calculated based on this number.'),
  1004.                     ),
  1005.                     array(
  1006.                         'type' => 'switch',
  1007.                         'is_bool' => true, //retro compat 1.5
  1008.                         'label' => $this->l('Returns'),
  1009.                         'name' => 'MA_RETURN_SLIP',
  1010.                         'desc' => $this->l('Receive a notification when a customer requests a merchandise return.'),
  1011.                         'values' => array(
  1012.                             array(
  1013.                                 'id' => 'active_on',
  1014.                                 'value' => 1,
  1015.                                 'label' => $this->l('Enabled')
  1016.                             ),
  1017.                             array(
  1018.                                 'id' => 'active_off',
  1019.                                 'value' => 0,
  1020.                                 'label' => $this->l('Disabled')
  1021.                             )
  1022.                         ),
  1023.                     ),
  1024.                     array(
  1025.                         'type' => 'textarea',
  1026.                         'cols' => 36,
  1027.                         'rows' => 4,
  1028.                         'label' => $this->l('E-mail addresses'),
  1029.                         'name' => 'MA_MERCHANT_MAILS',
  1030.                         'desc' => $this->l('One e-mail address per line (e.g. bob@example.com).'),
  1031.                     ),
  1032.                 ),
  1033.                 'submit' => array(
  1034.                     'title' => $this->l('Save'),
  1035.                     'class' => 'btn btn-default pull-right',
  1036.                     'name' => 'submitMAMerchant',
  1037.                 )
  1038.             ),
  1039.         );
  1040.  
  1041.         $helper = new HelperForm();
  1042.         $helper->show_toolbar = false;
  1043.         $helper->table = $this->table;
  1044.         $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
  1045.         $helper->default_form_language = $lang->id;
  1046.         $helper->module = $this;
  1047.         $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
  1048.         $helper->identifier = $this->identifier;
  1049.         $helper->submit_action = 'submitMailAlertConfiguration';
  1050.         $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
  1051.             .'&configure='.$this->name
  1052.             .'&tab_module='.$this->tab
  1053.             .'&module_name='.$this->name;
  1054.         $helper->token = Tools::getAdminTokenLite('AdminModules');
  1055.         $helper->tpl_vars = array(
  1056.             'fields_value' => $this->getConfigFieldsValues(),
  1057.             'languages' => $this->context->controller->getLanguages(),
  1058.             'id_language' => $this->context->language->id
  1059.         );
  1060.  
  1061.         return $helper->generateForm(array($fields_form_1, $fields_form_2));
  1062.     }
  1063.  
  1064.     public function getConfigFieldsValues()
  1065.     {
  1066.         return array(
  1067.             'MA_CUSTOMER_QTY' => Tools::getValue('MA_CUSTOMER_QTY', Configuration::get('MA_CUSTOMER_QTY')),
  1068.             'MA_MERCHANT_ORDER' => Tools::getValue('MA_MERCHANT_ORDER', Configuration::get('MA_MERCHANT_ORDER')),
  1069.             'MA_MERCHANT_OOS' => Tools::getValue('MA_MERCHANT_OOS', Configuration::get('MA_MERCHANT_OOS')),
  1070.             'MA_LAST_QTIES' => Tools::getValue('MA_LAST_QTIES', Configuration::get('MA_LAST_QTIES')),
  1071.             'MA_MERCHANT_COVERAGE' => Tools::getValue('MA_MERCHANT_COVERAGE', Configuration::get('MA_MERCHANT_COVERAGE')),
  1072.             'MA_PRODUCT_COVERAGE' => Tools::getValue('MA_PRODUCT_COVERAGE', Configuration::get('MA_PRODUCT_COVERAGE')),
  1073.             'MA_MERCHANT_MAILS' => Tools::getValue('MA_MERCHANT_MAILS', Configuration::get('MA_MERCHANT_MAILS')),
  1074.             'MA_ORDER_EDIT' => Tools::getValue('MA_ORDER_EDIT', Configuration::get('MA_ORDER_EDIT')),
  1075.             'MA_RETURN_SLIP' => Tools::getValue('MA_RETURN_SLIP', Configuration::get('MA_RETURN_SLIP')),
  1076.         );
  1077.     }
  1078. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement