[*] MO : MailAlerts : multishop/multilang full compatibility

Customers will receive alerts based on the real context of the moment they subscribed to the alert (sho, theme & language)

SQL update table : `ps_mailalert_customer_oos`
=========================================

ALTER TABLE `ps_mailalert_customer_oos`
ADD `id_lang` INT( 10 ) UNSIGNED NOT NULL ,
DROP PRIMARY KEY ,
ADD PRIMARY KEY ( `id_customer` , `customer_email` , `id_product` , `id_product_attribute` , `id_shop` ) ;
This commit is contained in:
Nicolas Sorosac committed 2013-09-10 10:24:40 +02:00
1 parent 4968a792b4
commit c4681c1fb1
3 files changed
+182 -112

No files matched your search

+46 -17
View File
@@ -36,6 +36,8 @@ class MailAlert extends ObjectModel
public $id_shop; public $id_shop;
public $id_lang;
/** /**
* @see ObjectModel::$definition * @see ObjectModel::$definition
*/ */
@@ -47,15 +49,19 @@ class MailAlert extends ObjectModel
'customer_email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true), 'customer_email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true),
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true), 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
'id_product_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true), 'id_product_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true) 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true)
), ),
); );
public static function customerHasNotification($id_customer, $id_product, $id_product_attribute, $id_shop = null) public static function customerHasNotification($id_customer, $id_product, $id_product_attribute, $id_shop = null, $id_lang = null)
{ {
if ($id_shop == null) if ($id_shop == null)
$id_shop = Context::getContext()->shop->id; $id_shop = Context::getContext()->shop->id;
if ($id_lang == null)
$id_lang = Context::getContext()->language->id;
$customer = new Customer($id_customer); $customer = new Customer($id_customer);
$customer_email = $customer->email; $customer_email = $customer->email;
@@ -70,14 +76,15 @@ class MailAlert extends ObjectModel
return count(Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)); return count(Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql));
} }
public static function deleteAlert($id_customer, $customer_email, $id_product, $id_product_attribute) public static function deleteAlert($id_customer, $customer_email, $id_product, $id_product_attribute, $id_shop)
{ {
$sql = ' $sql = '
DELETE FROM `'._DB_PREFIX_.self::$definition['table'].'` DELETE FROM `'._DB_PREFIX_.self::$definition['table'].'`
WHERE '.(($id_customer > 0) ? '(`customer_email` = \''.pSQL($customer_email).'\' OR `id_customer` = '.(int)$id_customer.')' : WHERE '.(($id_customer > 0) ? '(`customer_email` = \''.pSQL($customer_email).'\' OR `id_customer` = '.(int)$id_customer.')' :
'`customer_email` = \''.pSQL($customer_email).'\''). '`customer_email` = \''.pSQL($customer_email).'\'').
' AND `id_product` = '.(int)$id_product.' ' AND `id_product` = '.(int)$id_product.'
AND `id_product_attribute` = '.(int)$id_product_attribute; AND `id_product_attribute` = '.(int)$id_product_attribute.'
AND `id_shop` = '.(int)$id_shop;
return Db::getInstance()->execute($sql); return Db::getInstance()->execute($sql);
} }
@@ -160,17 +167,23 @@ class MailAlert extends ObjectModel
public static function sendCustomerAlert($id_product, $id_product_attribute) public static function sendCustomerAlert($id_product, $id_product_attribute)
{ {
$link = new Link(); $link = new Link();
$context = Context::getContext()->cloneContext();
$id_lang = (int)Context::getContext()->language->id;
$product = new Product((int)$id_product, false, $id_lang);
$templateVars = array(
'{product}' => (is_array($product->name) ? $product->name[$id_lang] : $product->name),
'{product_link}' => $link->getProductLink($product)
);
$customers = self::getCustomers($id_product, $id_product_attribute); $customers = self::getCustomers($id_product, $id_product_attribute);
foreach ($customers as $customer) foreach ($customers as $customer)
{ {
$id_shop = (int)$customer['id_shop'];
$id_lang = (int)$customer['id_lang'];
$context->shop->id = $id_shop;
$context->language->id = $id_lang;
$product = new Product((int)$id_product, false, $id_lang, $id_shop);
$product_link = $link->getProductLink($product, $product->link_rewrite, null, null, $id_lang, $id_shop);
$templateVars = array(
'{product}' => (is_array($product->name) ? $product->name[$id_lang] : $product->name),
'{product_link}' => $product_link
);
if ($customer['id_customer']) if ($customer['id_customer'])
{ {
$customer = new Customer((int)$customer['id_customer']); $customer = new Customer((int)$customer['id_customer']);
@@ -182,14 +195,30 @@ class MailAlert extends ObjectModel
$customer_id = 0; $customer_id = 0;
$customer_email = $customer['customer_email']; $customer_email = $customer['customer_email'];
} }
$iso = Language::getIsoById($id_lang); $iso = Language::getIsoById($id_lang);
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.txt') && if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.txt') &&
file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.html')) file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.html'))
Mail::Send((int)Configuration::get('PS_LANG_DEFAULT'), 'customer_qty', Mail::l('Product available', $id_lang), $templateVars, strval($customer_email), NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/'); Mail::Send(
$id_lang,
'customer_qty',
Mail::l('Product available', $id_lang),
$templateVars,
strval($customer_email),
NULL,
strval(Configuration::get('PS_SHOP_EMAIL', null, null, $id_shop)),
strval(Configuration::get('PS_SHOP_NAME', null, null, $id_shop)),
NULL,
NULL,
dirname(__FILE__).'/mails/',
false,
$id_shop
);
Hook::exec('actionModuleMailAlertSendCustomer', array('product' => (is_array($product->name) ? $product->name[$id_lang] : $product->name), 'link' => $link->getProductLink($product), 'customer' => $customer, 'product_obj' => $product)); Hook::exec('actionModuleMailAlertSendCustomer', array('product' => (is_array($product->name) ? $product->name[$id_lang] : $product->name), 'link' => $product_link, 'customer' => $customer, 'product_obj' => $product));
self::deleteAlert((int)$customer_id, strval($customer_email), (int)$id_product, (int)$id_product_attribute);
self::deleteAlert((int)$customer_id, strval($customer_email), (int)$id_product, (int)$id_product_attribute, $id_shop);
} }
} }
@@ -244,7 +273,7 @@ class MailAlert extends ObjectModel
public static function getCustomers($id_product, $id_product_attribute) public static function getCustomers($id_product, $id_product_attribute)
{ {
$sql = ' $sql = '
SELECT id_customer, customer_email SELECT id_customer, customer_email, id_shop, id_lang
FROM `'._DB_PREFIX_.self::$definition['table'].'` FROM `'._DB_PREFIX_.self::$definition['table'].'`
WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute; WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute;
@@ -64,8 +64,10 @@ class MailalertsActionsModuleFrontController extends ModuleFrontController
if (!Validate::isLoadedObject($product)) if (!Validate::isLoadedObject($product))
die('0'); die('0');
if (MailAlert::deleteAlert((int)Context::getContext()->customer->id, (int)Context::getContext()->customer->email, (int)$product->id, (int)$this->id_product_attribute)) $context = Context::getContext();
if (MailAlert::deleteAlert((int)$context->customer->id, (int)$context->customer->email, (int)$product->id, (int)$this->id_product_attribute))
die('0'); die('0');
die(1); die(1);
} }
@@ -74,29 +76,32 @@ class MailalertsActionsModuleFrontController extends ModuleFrontController
*/ */
public function processAdd() public function processAdd()
{ {
if (Context::getContext()->customer->isLogged()) $context = Context::getContext();
if ($context->customer->isLogged())
{ {
$id_customer = (int)Context::getContext()->customer->id; $id_customer = (int)$context->customer->id;
$customer = new Customer($id_customer); $customer = new Customer($id_customer);
$customer_email = strval($customer->email); $customer_email = strval($customer->email);
} }
else else
{ {
$customer_email = strval(Tools::getValue('customer_email')); $customer_email = strval(Tools::getValue('customer_email'));
$customer = Context::getContext()->customer->getByEmail($customer_email); $customer = $context->customer->getByEmail($customer_email);
$id_customer = (isset($customer->id) && ($customer->id != null)) ? (int)$customer->id : null; $id_customer = (isset($customer->id) && ($customer->id != null)) ? (int)$customer->id : null;
} }
$id_product = (int)Tools::getValue('id_product'); $id_product = (int)Tools::getValue('id_product');
$id_product_attribute = (int)Tools::getValue('id_product_attribute'); $id_product_attribute = (int)Tools::getValue('id_product_attribute');
$id_shop = (int)Context::getContext()->shop->id; $id_shop = (int)$context->shop->id;
$product = new Product($id_product, null, null, $id_shop, Context::getContext()); $id_lang = (int)$context->language->id;
$product = new Product($id_product, false, $id_lang, $id_shop, $context);
$mailAlert = MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute, $id_shop); $mailAlert = MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute, $id_shop);
if ($mailAlert) if ($mailAlert)
die('2'); die('2');
else if (!Validate::isLoadedObject($product)) elseif (!Validate::isLoadedObject($product))
die('0'); die('0');
$mailAlert = new MailAlert(); $mailAlert = new MailAlert();
@@ -106,10 +111,11 @@ class MailalertsActionsModuleFrontController extends ModuleFrontController
$mailAlert->id_product = (int)$id_product; $mailAlert->id_product = (int)$id_product;
$mailAlert->id_product_attribute = (int)$id_product_attribute; $mailAlert->id_product_attribute = (int)$id_product_attribute;
$mailAlert->id_shop = (int)$id_shop; $mailAlert->id_shop = (int)$id_shop;
$mailAlert->id_lang = (int)$id_lang;
if ($mailAlert->add() !== false) if ($mailAlert->add() !== false)
die('1'); die('1');
die('0'); die('0');
} }
@@ -122,15 +128,15 @@ class MailalertsActionsModuleFrontController extends ModuleFrontController
die('0'); die('0');
$id_customer = (int)$this->context->customer->id; $id_customer = (int)$this->context->customer->id;
if (!$id_product = (int)(Tools::getValue('id_product')))
die ('0');
$id_product_attribute = (int)(Tools::getValue('id_product_attribute'));
$id_shop = (int)Context::getContext()->shop->id;
if (MailAlert::customerHasNotification((int)$id_customer, (int)$id_product, (int)$id_product_attribute, (int)$id_shop)) if (!$id_product = (int)(Tools::getValue('id_product')))
die ('1'); die('0');
$id_product_attribute = (int)(Tools::getValue('id_product_attribute'));
if (MailAlert::customerHasNotification((int)$id_customer, (int)$id_product, (int)$id_product_attribute, (int)$this->context->shop->id))
die('1');
die('0'); die('0');
} }
} }
+114 -79
View File
@@ -40,13 +40,13 @@ class MailAlerts extends Module
private $_merchant_coverage; private $_merchant_coverage;
private $_product_coverage; private $_product_coverage;
const __MA_MAIL_DELIMITOR__ = ','; const __MA_MAIL_DELIMITOR__ = "\n";
public function __construct() public function __construct()
{ {
$this->name = 'mailalerts'; $this->name = 'mailalerts';
$this->tab = 'administration'; $this->tab = 'administration';
$this->version = '2.4'; $this->version = '2.5';
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
@@ -100,7 +100,8 @@ class MailAlerts extends Module
`id_product` int(10) unsigned NOT NULL, `id_product` int(10) unsigned NOT NULL,
`id_product_attribute` int(10) unsigned NOT NULL, `id_product_attribute` int(10) unsigned NOT NULL,
`id_shop` int(10) unsigned NOT NULL, `id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_customer`,`customer_email`,`id_product`,`id_product_attribute`) `id_lang` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_customer`,`customer_email`,`id_product`,`id_product_attribute`,`id_shop`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
if (!Db::getInstance()->execute($sql)) if (!Db::getInstance()->execute($sql))
@@ -161,7 +162,7 @@ class MailAlerts extends Module
$errors[] = $this->l('Invalid e-mail:').' '.Tools::safeOutput($email); $errors[] = $this->l('Invalid e-mail:').' '.Tools::safeOutput($email);
break; break;
} }
else if (!empty($email) && count($email) > 0) elseif (!empty($email) && count($email) > 0)
$emails[$k] = $email; $emails[$k] = $email;
else else
unset($emails[$k]); unset($emails[$k]);
@@ -171,15 +172,15 @@ class MailAlerts extends Module
if (!Configuration::updateValue('MA_MERCHANT_MAILS', strval($emails))) if (!Configuration::updateValue('MA_MERCHANT_MAILS', strval($emails)))
$errors[] = $this->l('Cannot update settings'); $errors[] = $this->l('Cannot update settings');
else if (!Configuration::updateValue('MA_MERCHANT_ORDER', (int)Tools::getValue('mA_merchand_order'))) elseif (!Configuration::updateValue('MA_MERCHANT_ORDER', (int)Tools::getValue('mA_merchand_order')))
$errors[] = $this->l('Cannot update settings'); $errors[] = $this->l('Cannot update settings');
else if (!Configuration::updateValue('MA_MERCHANT_OOS', (int)Tools::getValue('mA_merchand_oos'))) elseif (!Configuration::updateValue('MA_MERCHANT_OOS', (int)Tools::getValue('mA_merchand_oos')))
$errors[] = $this->l('Cannot update settings'); $errors[] = $this->l('Cannot update settings');
else if (!Configuration::updateValue('MA_LAST_QTIES', (int)Tools::getValue('MA_LAST_QTIES'))) elseif (!Configuration::updateValue('MA_LAST_QTIES', (int)Tools::getValue('MA_LAST_QTIES')))
$errors[] = $this->l('Cannot update settings'); $errors[] = $this->l('Cannot update settings');
else if (!Configuration::updateGlobalValue('MA_MERCHANT_COVERAGE', (int)Tools::getValue('mA_merchant_coverage'))) elseif (!Configuration::updateGlobalValue('MA_MERCHANT_COVERAGE', (int)Tools::getValue('mA_merchant_coverage')))
$errors[] = $this->l('Cannot update settings'); $errors[] = $this->l('Cannot update settings');
else if (!Configuration::updateGlobalValue('MA_PRODUCT_COVERAGE', (int)Tools::getValue('MA_PRODUCT_COVERAGE'))) elseif (!Configuration::updateGlobalValue('MA_PRODUCT_COVERAGE', (int)Tools::getValue('MA_PRODUCT_COVERAGE')))
$errors[] = $this->l('Cannot update settings'); $errors[] = $this->l('Cannot update settings');
} }
} }
@@ -262,14 +263,16 @@ class MailAlerts extends Module
return; return;
// Getting differents vars // Getting differents vars
$id_lang = (int)Context::getContext()->language->id; $context = Context::getContext();
$id_lang = (int)$context->language->id;
$id_shop = (int)$context->shop->id;
$currency = $params['currency']; $currency = $params['currency'];
$configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME'));
$order = $params['order']; $order = $params['order'];
$customer = $params['customer']; $customer = $params['customer'];
$configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_COLOR'), $id_lang, null, $id_shop);
$delivery = new Address((int)$order->id_address_delivery); $delivery = new Address((int)$order->id_address_delivery);
$invoice = new Address((int)$order->id_address_invoice); $invoice = new Address((int)$order->id_address_invoice);
$order_date_text = Tools::displayDate($order->date_add); $order_date_text = Tools::displayDate($order->date_add, (int)$id_lang);
$carrier = new Carrier((int)$order->id_carrier); $carrier = new Carrier((int)$order->id_carrier);
$message = $order->getFirstMessage(); $message = $order->getFirstMessage();
@@ -288,7 +291,6 @@ class MailAlerts extends Module
$customization_text = ''; $customization_text = '';
if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']])) if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']]))
{ {
foreach ($customized_datas[$product['product_id']][$product['product_attribute_id']] as $customization) foreach ($customized_datas[$product['product_id']][$product['product_attribute_id']] as $customization)
{ {
if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_])) if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_]))
@@ -339,11 +341,11 @@ class MailAlerts extends Module
'{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"), '{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"),
'{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"), '{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"),
'{delivery_block_html}' => MailAlert::getFormatedAddress($delivery, '<br />', array( '{delivery_block_html}' => MailAlert::getFormatedAddress($delivery, '<br />', array(
'firstname' => '<span style="color:'.Configuration::get('PS_MAIL_COLOR').'; font-weight:bold;">%s</span>', 'firstname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>',
'lastname' => '<span style="color:'.Configuration::get('PS_MAIL_COLOR').'; font-weight:bold;">%s</span>')), 'lastname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>')),
'{invoice_block_html}' => MailAlert::getFormatedAddress($invoice, '<br />', array( '{invoice_block_html}' => MailAlert::getFormatedAddress($invoice, '<br />', array(
'firstname' => '<span style="color:'.Configuration::get('PS_MAIL_COLOR').' font-weight:bold;">%s</span>', 'firstname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].' font-weight:bold;">%s</span>',
'lastname' => '<span style="color:'.Configuration::get('PS_MAIL_COLOR').'; font-weight:bold;">%s</span>')), 'lastname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>')),
'{delivery_company}' => $delivery->company, '{delivery_company}' => $delivery->company,
'{delivery_firstname}' => $delivery->firstname, '{delivery_firstname}' => $delivery->firstname,
'{delivery_lastname}' => $delivery->lastname, '{delivery_lastname}' => $delivery->lastname,
@@ -353,9 +355,7 @@ class MailAlerts extends Module
'{delivery_postal_code}' => $delivery->postcode, '{delivery_postal_code}' => $delivery->postcode,
'{delivery_country}' => $delivery->country, '{delivery_country}' => $delivery->country,
'{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '',
'{delivery_phone}' => $delivery->phone, '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile,
'{delivery_phone_mobile}' => $delivery->phone_mobile,
'{delivery_vat_number}' => $delivery->vat_number,
'{delivery_other}' => $delivery->other, '{delivery_other}' => $delivery->other,
'{invoice_company}' => $invoice->company, '{invoice_company}' => $invoice->company,
'{invoice_firstname}' => $invoice->firstname, '{invoice_firstname}' => $invoice->firstname,
@@ -366,21 +366,18 @@ class MailAlerts extends Module
'{invoice_postal_code}' => $invoice->postcode, '{invoice_postal_code}' => $invoice->postcode,
'{invoice_country}' => $invoice->country, '{invoice_country}' => $invoice->country,
'{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '',
'{invoice_phone}' => $invoice->phone, '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile,
'{invoice_phone_mobile}' => $invoice->phone_mobile,
'{invoice_vat_number}' => $invoice->vat_number,
'{invoice_other}' => $invoice->other, '{invoice_other}' => $invoice->other,
'{order_name}' => sprintf('%06d', $order->id), '{order_name}' => sprintf('%06d', $order->id),
'{shop_name}' => Configuration::get('PS_SHOP_NAME'), '{shop_name}' => $configuration['PS_SHOP_NAME'],
'{date}' => $order_date_text, '{date}' => $order_date_text,
'{carrier}' => (($carrier->name == '0') ? Configuration::get('PS_SHOP_NAME') : $carrier->name), '{carrier}' => (($carrier->name == '0') ? $configuration['PS_SHOP_NAME'] : $carrier->name),
'{payment}' => Tools::substr($order->payment, 0, 32), '{payment}' => Tools::substr($order->payment, 0, 32),
'{items}' => $items_table, '{items}' => $items_table,
'{total_paid}' => Tools::displayPrice($order->total_paid, $currency), '{total_paid}' => Tools::displayPrice($order->total_paid, $currency),
'{total_products}' => Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency), '{total_products}' => Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency),
'{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency),
'{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency),
'{total_tax_paid}' => Tools::displayPrice(($order->total_products_wt - $order->total_products) + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $currency, false),
'{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency),
'{currency}' => $currency->sign, '{currency}' => $currency->sign,
'{message}' => $message '{message}' => $message
@@ -390,19 +387,28 @@ class MailAlerts extends Module
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.txt') && if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.txt') &&
file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.html')) file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.html'))
Mail::Send( {
$id_lang, // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
$template, $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails);
sprintf(Mail::l('New order - #%06d', $id_lang), $order->id), foreach ($merchant_mails as $merchant_mail)
$template_vars, {
explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails), Mail::Send(
null, $id_lang,
$configuration['PS_SHOP_EMAIL'], $template,
$configuration['PS_SHOP_NAME'], sprintf(Mail::l('New order - #%06d', $id_lang), $order->id),
null, $template_vars,
null, $merchant_mail,
dirname(__FILE__).'/mails/' null,
); $configuration['PS_SHOP_EMAIL'],
$configuration['PS_SHOP_NAME'],
null,
null,
dirname(__FILE__).'/mails/',
null,
$id_shop
);
}
}
} }
public function hookActionProductOutOfStock($params) public function hookActionProductOutOfStock($params)
@@ -410,18 +416,20 @@ class MailAlerts extends Module
if (!$this->_customer_qty || !Configuration::get('PS_STOCK_MANAGEMENT') || Product::isAvailableWhenOutOfStock($params['product']->out_of_stock)) if (!$this->_customer_qty || !Configuration::get('PS_STOCK_MANAGEMENT') || Product::isAvailableWhenOutOfStock($params['product']->out_of_stock))
return; return;
$context = Context::getContext();
$id_product = (int)$params['product']->id; $id_product = (int)$params['product']->id;
$id_product_attribute = 0; $id_product_attribute = 0;
$id_customer = (int)Context::getContext()->customer->id; $id_customer = (int)$context->customer->id;
if (!(int)Context::getContext()->customer->isLogged()) if ((int)$context->customer->id <= 0)
$this->context->smarty->assign('email', 1); $this->context->smarty->assign('email', 1);
else if (MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute)) elseif (MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute, (int)$context->shop->id))
return; return;
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'id_product' => $id_product, 'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute)); 'id_product_attribute' => $id_product_attribute
));
return $this->display(__FILE__, 'product.tpl'); return $this->display(__FILE__, 'product.tpl');
} }
@@ -431,33 +439,47 @@ class MailAlerts extends Module
$id_product = (int)$params['id_product']; $id_product = (int)$params['id_product'];
$id_product_attribute = (int)$params['id_product_attribute']; $id_product_attribute = (int)$params['id_product_attribute'];
$quantity = (int)$params['quantity']; $quantity = (int)$params['quantity'];
$id_shop = (int)Context::getContext()->shop->id; $context = Context::getContext();
$id_lang = (int)Context::getContext()->language->id; $id_shop = (int)$context->shop->id;
$product = new Product($id_product, true, $id_lang, $id_shop, Context::getContext()); $id_lang = (int)$context->language->id;
$ma_last_qties = (int)Configuration::get('MA_LAST_QTIES'); $product = new Product($id_product, true, $id_lang, $id_shop, $context);
$configuration = Configuration::getMultiple(array('MA_LAST_QTIES', 'PS_STOCK_MANAGEMENT', 'PS_SHOP_EMAIL', 'PS_SHOP_NAME'), $id_lang, null, $id_shop);
$ma_last_qties = (int)$configuration['MA_LAST_QTIES'];
if ($product->active == 1 && (int)$quantity <= $ma_last_qties && !(!$this->_merchant_oos || empty($this->_merchant_mails)) && Configuration::get('PS_STOCK_MANAGEMENT')) if ($product->active == 1 && (int)$quantity <= $ma_last_qties && !(!$this->_merchant_oos || empty($this->_merchant_mails)) && $configuration['PS_STOCK_MANAGEMENT'])
{ {
$iso = Language::getIsoById($id_lang); $iso = Language::getIsoById($id_lang);
$product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang); $product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang);
$template_vars = array( $template_vars = array(
'{qty}' => $quantity, '{qty}' => $quantity,
'{last_qty}' => $ma_last_qties, '{last_qty}' => $ma_last_qties,
'{product}' => $product_name); '{product}' => $product_name
);
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.txt') && if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.txt') &&
file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.html')) file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.html'))
Mail::Send($id_lang, {
'productoutofstock', // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
Mail::l('Product out of stock', $id_lang), $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails);
$template_vars, foreach ($merchant_mails as $merchant_mail)
explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails), {
null, Mail::Send(
strval(Configuration::get('PS_SHOP_EMAIL')), $id_lang,
strval(Configuration::get('PS_SHOP_NAME')), 'productoutofstock',
null, Mail::l('Product out of stock', $id_lang),
null, $template_vars,
dirname(__FILE__).'/mails/'); $merchant_mail,
null,
strval($configuration['PS_SHOP_EMAIL']),
strval($configuration['PS_SHOP_NAME']),
null,
null,
dirname(__FILE__).'/mails/',
false,
$id_shop
);
}
}
} }
if ($this->_customer_qty && $quantity > 0) if ($this->_customer_qty && $quantity > 0)
@@ -541,31 +563,44 @@ class MailAlerts extends Module
$coverage = StockManagerFactory::getManager()->getProductCoverage($id_product, $id_product_attribute, $warning_coverage, $id_warehouse); $coverage = StockManagerFactory::getManager()->getProductCoverage($id_product, $id_product_attribute, $warning_coverage, $id_warehouse);
// if we need to send a notification // if we need to send a notification
if ($product->active == 1 && $coverage !== -1 && ($coverage < $warning_coverage) && !empty($this->_merchant_mails) && if ($product->active == 1 &&
($coverage < $warning_coverage) && !empty($this->_merchant_mails) &&
Configuration::getGlobalValue('MA_MERCHANT_COVERAGE')) Configuration::getGlobalValue('MA_MERCHANT_COVERAGE'))
{ {
$id_lang = (int)Context::getContext()->language->id; $context = Context::getContext();
$id_lang = (int)$context->language->id;
$id_shop = (int)$context->shop->id;
$iso = Language::getIsoById($id_lang); $iso = Language::getIsoById($id_lang);
$product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang); $product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang);
$template_vars = array( $template_vars = array(
'{current_coverage}' => $coverage, '{current_coverage}' => $coverage,
'{warning_coverage}' => $warning_coverage, '{warning_coverage}' => $warning_coverage,
'{product}' => pSQL($product_name)); '{product}' => pSQL($product_name)
);
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.txt') && if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.txt') &&
file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.html')) file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.html'))
{ {
Mail::Send($id_lang, // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients
'productcoverage', $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails);
Mail::l('Stock coverage', $id_lang), foreach ($merchant_mails as $merchant_mail)
$template_vars, {
explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails), Mail::Send(
null, $id_lang,
strval(Configuration::get('PS_SHOP_EMAIL')), 'productcoverage',
strval(Configuration::get('PS_SHOP_NAME')), Mail::l('Stock coverage', $id_lang),
null, $template_vars,
null, $merchant_mail,
dirname(__FILE__).'/mails/'); null,
strval(Configuration::get('PS_SHOP_EMAIL')),
strval(Configuration::get('PS_SHOP_NAME')),
null,
null,
dirname(__FILE__).'/mails/',
null,
$id_shop
);
}
} }
} }
} }