From b361e985c058ebdf376ca3ef5bc9e59433d7421c Mon Sep 17 00:00:00 2001 From: bMancone Date: Mon, 5 Mar 2012 18:52:25 +0000 Subject: [PATCH] // Added hook actionProductCoverage in mailalerts module and updated StockManager git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13860 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/stock/StockManager.php | 10 ++ modules/mailalerts/config.xml | 2 +- modules/mailalerts/mailalerts.php | 110 ++++++++++++++++-- .../mailalerts/mails/de/productcoverage.html | 33 ++++++ .../mailalerts/mails/de/productcoverage.txt | 10 ++ .../mailalerts/mails/en/productcoverage.html | 33 ++++++ .../mailalerts/mails/en/productcoverage.txt | 10 ++ .../mailalerts/mails/es/productcoverage.html | 33 ++++++ .../mailalerts/mails/es/productcoverage.txt | 10 ++ .../mailalerts/mails/fr/productcoverage.html | 34 ++++++ .../mailalerts/mails/fr/productcoverage.txt | 8 ++ .../mailalerts/mails/it/productcoverage.html | 33 ++++++ .../mailalerts/mails/it/productcoverage.txt | 10 ++ 13 files changed, 325 insertions(+), 11 deletions(-) create mode 100644 modules/mailalerts/mails/de/productcoverage.html create mode 100644 modules/mailalerts/mails/de/productcoverage.txt create mode 100644 modules/mailalerts/mails/en/productcoverage.html create mode 100644 modules/mailalerts/mails/en/productcoverage.txt create mode 100644 modules/mailalerts/mails/es/productcoverage.html create mode 100644 modules/mailalerts/mails/es/productcoverage.txt create mode 100644 modules/mailalerts/mails/fr/productcoverage.html create mode 100644 modules/mailalerts/mails/fr/productcoverage.txt create mode 100644 modules/mailalerts/mails/it/productcoverage.html create mode 100644 modules/mailalerts/mails/it/productcoverage.txt diff --git a/classes/stock/StockManager.php b/classes/stock/StockManager.php index 297b5a2e2..d81ec8948 100644 --- a/classes/stock/StockManager.php +++ b/classes/stock/StockManager.php @@ -406,6 +406,16 @@ class StockManagerCore implements StockManagerInterface } } + // if we remove a usable quantity, exec hook + if ($is_usable) + Hook::exec('actionProductCoverage', + array( + 'id_product' => $id_product, + 'id_product_attribute' => $id_product_attribute, + 'warehouse' => $warehouse + ) + ); + return $return; } diff --git a/modules/mailalerts/config.xml b/modules/mailalerts/config.xml index c5cd76f14..7d42bdd97 100755 --- a/modules/mailalerts/config.xml +++ b/modules/mailalerts/config.xml @@ -2,7 +2,7 @@ mailalerts - + diff --git a/modules/mailalerts/mailalerts.php b/modules/mailalerts/mailalerts.php index c45094a1d..98edfdcac 100644 --- a/modules/mailalerts/mailalerts.php +++ b/modules/mailalerts/mailalerts.php @@ -38,6 +38,8 @@ class MailAlerts extends Module private $_merchant_order; private $_merchant_oos; private $_customer_qty; + private $_merchant_coverage; + private $_product_coverage; const __MA_MAIL_DELIMITOR__ = ','; @@ -45,7 +47,7 @@ class MailAlerts extends Module { $this->name = 'mailalerts'; $this->tab = 'administration'; - $this->version = '2.3'; + $this->version = '2.4'; $this->author = 'PrestaShop'; parent::__construct(); @@ -64,6 +66,8 @@ class MailAlerts extends Module $this->_merchant_order = (int)Configuration::get('MA_MERCHANT_ORDER'); $this->_merchant_oos = (int)Configuration::get('MA_MERCHANT_OOS'); $this->_customer_qty = (int)Configuration::get('MA_CUSTOMER_QTY'); + $this->_merchant_coverage = (int)Configuration::getGlobalValue('MA_MERCHANT_COVERAGE'); + $this->_product_coverage = (int)Configuration::getGlobalValue('MA_PRODUCT_COVERAGE'); } public function install() @@ -78,6 +82,7 @@ class MailAlerts extends Module !$this->registerHook('actionProductAttributeDelete') || !$this->registerHook('actionProductAttributeUpdate') || !$this->registerHook('actionProductUpdate') || + !$this->registerHook('actionProductCoverage') || !$this->registerHook('displayHeader')) return false; @@ -86,6 +91,8 @@ class MailAlerts extends Module Configuration::updateValue('MA_CUSTOMER_QTY', 1); Configuration::updateValue('MA_MERCHANT_MAILS', Configuration::get('PS_SHOP_EMAIL')); Configuration::updateValue('MA_LAST_QTIES', (int)Configuration::get('PS_LAST_QTIES')); + Configuration::updateGlobalValue('MA_MERCHANT_COVERAGE', 0); + Configuration::updateGlobalValue('MA_PRODUCT_COVERAGE', 0); $sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.MailAlert::$definition['table'].'` ( @@ -110,6 +117,8 @@ class MailAlerts extends Module Configuration::deleteByName('MA_CUSTOMER_QTY'); Configuration::deleteByName('MA_MERCHANT_MAILS'); Configuration::deleteByName('MA_LAST_QTIES'); + Configuration::deleteByName('MA_MERCHANT_COVERAGE'); + Configuration::deleteByName('MA_PRODUCT_COVERAGE'); if (!Db::getInstance()->execute('DROP TABLE '._DB_PREFIX_.MailAlert::$definition['table'])) return false; @@ -169,6 +178,10 @@ class MailAlerts extends Module $errors[] = $this->l('Cannot update settings'); else if (!Configuration::updateValue('MA_LAST_QTIES', (int)Tools::getValue('MA_LAST_QTIES'))) $errors[] = $this->l('Cannot update settings'); + else if (!Configuration::updateGlobalValue('MA_MERCHANT_COVERAGE', (int)Tools::getValue('mA_merchant_coverage'))) + $errors[] = $this->l('Cannot update settings'); + else if (!Configuration::updateGlobalValue('MA_PRODUCT_COVERAGE', (int)Tools::getValue('MA_PRODUCT_COVERAGE'))) + $errors[] = $this->l('Cannot update settings'); } } @@ -181,7 +194,8 @@ class MailAlerts extends Module public function _displayForm() { return '
-
'.$this->l('Customer notification').' +
'.$this->l('Customer notifications').' +
 
_customer_qty) == 1 ? 'checked' : '').'> @@ -192,28 +206,44 @@ class MailAlerts extends Module
-
+
 
-
'.$this->l('Merchant notification').' +
+ '.$this->l('Merchant notifications').' +
 
_merchant_order) == 1 ? 'checked' : '').'> -   +  
+
 
_merchant_oos) == 1 ? 'checked' : '').'> -   +  
- +
-

'.$this->l('Quantity for which a product is regarded as out of stock').'

+

'.$this->l('Quantity for which a product is considered out of stock').'

- +
 
+ +
+ _merchant_coverage) == 1 ? 'checked' : '').'> +   +
+ +
+ +

'.$this->l('Stock cover, in days. Also, the stock cover of a given product will be calculated based on this number').'

+
+
 
+
 
+
- +
'.$this->l('One e-mail address per line').'
@@ -484,6 +514,66 @@ class MailAlerts extends Module Db::getInstance()->Execute($sql); } + public function hookActionProductCoverage($params) + { + // if not advanced stock management, nothing to do + if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) + return; + + // retrieves informations + $id_product = (int)$params['id_product']; + $id_product_attribute = (int)$params['id_product_attribute']; + $warehouse = $params['warehouse']; + $product = new Product($id_product); + + if (!Validate::isLoadedObject($product)) + return; + + if (!$product->advanced_stock_management) + return; + + // sets warehouse id to get the coverage + if (!Validate::isLoadedObject($warehouse)) + $id_warehouse = 0; + else + $id_warehouse = (int)$warehouse->id; + + // coverage of the product + $warning_coverage = (int)Configuration::getGlobalValue('MA_PRODUCT_COVERAGE'); + + $coverage = StockManagerFactory::getManager()->getProductCoverage($id_product, $id_product_attribute, $warning_coverage, $id_warehouse); + + // if we need to send a notification + if ($product->active == 1 && + ($coverage < $warning_coverage) && !empty($this->_merchant_mails) && + Configuration::getGlobalValue('MA_MERCHANT_COVERAGE')) + { + $id_lang = (int)Context::getContext()->language->id; + $iso = Language::getIsoById($id_lang); + $product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang); + $template_vars = array( + '{current_coverage}' => $coverage, + '{warning_coverage}' => $warning_coverage, + '{product}' => pSQL($product_name)); + + if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.txt') && + file_exists(dirname(__FILE__).'/mails/'.$iso.'/productcoverage.html')) + { + Mail::Send($id_lang, + 'productcoverage', + Mail::l('Stock coverage', $id_lang), + $template_vars, + explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails), + null, + strval(Configuration::get('PS_SHOP_EMAIL')), + strval(Configuration::get('PS_SHOP_NAME')), + null, + null, + dirname(__FILE__).'/mails/'); + } + } + } + public function hookDisplayHeader($params) { $this->context->controller->addCSS($this->_path.'mailalerts.css', 'all'); diff --git a/modules/mailalerts/mails/de/productcoverage.html b/modules/mailalerts/mails/de/productcoverage.html new file mode 100644 index 000000000..a2b4fe47a --- /dev/null +++ b/modules/mailalerts/mails/de/productcoverage.html @@ -0,0 +1,33 @@ + + + + + [{shop_name}] Stock cover + + + + + + + + + + + + + + + + + + +
+ {shop_name} +
 
{product} is almost out of stock.
 
+ The stock cover is now less than the specified minimum of {warning_coverage}.

+ Current stock cover: {current_coverage}

+
 
+ {shop_name} powered with PrestaShop™ +
+ + diff --git a/modules/mailalerts/mails/de/productcoverage.txt b/modules/mailalerts/mails/de/productcoverage.txt new file mode 100644 index 000000000..2c15fb1fb --- /dev/null +++ b/modules/mailalerts/mails/de/productcoverage.txt @@ -0,0 +1,10 @@ +Hi, + +The product {product} is almost out of stock. +The stock cover is now less than the specified minimum of {warning_coverage}. +Current stock cover : {current_coverage} + + + + +{shop_url} powered by PrestaShop™ diff --git a/modules/mailalerts/mails/en/productcoverage.html b/modules/mailalerts/mails/en/productcoverage.html new file mode 100644 index 000000000..a2b4fe47a --- /dev/null +++ b/modules/mailalerts/mails/en/productcoverage.html @@ -0,0 +1,33 @@ + + + + + [{shop_name}] Stock cover + + + + + + + + + + + + + + + + + + +
+ {shop_name} +
 
{product} is almost out of stock.
 
+ The stock cover is now less than the specified minimum of {warning_coverage}.

+ Current stock cover: {current_coverage}

+
 
+ {shop_name} powered with PrestaShop™ +
+ + diff --git a/modules/mailalerts/mails/en/productcoverage.txt b/modules/mailalerts/mails/en/productcoverage.txt new file mode 100644 index 000000000..2c15fb1fb --- /dev/null +++ b/modules/mailalerts/mails/en/productcoverage.txt @@ -0,0 +1,10 @@ +Hi, + +The product {product} is almost out of stock. +The stock cover is now less than the specified minimum of {warning_coverage}. +Current stock cover : {current_coverage} + + + + +{shop_url} powered by PrestaShop™ diff --git a/modules/mailalerts/mails/es/productcoverage.html b/modules/mailalerts/mails/es/productcoverage.html new file mode 100644 index 000000000..a2b4fe47a --- /dev/null +++ b/modules/mailalerts/mails/es/productcoverage.html @@ -0,0 +1,33 @@ + + + + + [{shop_name}] Stock cover + + + + + + + + + + + + + + + + + + +
+ {shop_name} +
 
{product} is almost out of stock.
 
+ The stock cover is now less than the specified minimum of {warning_coverage}.

+ Current stock cover: {current_coverage}

+
 
+ {shop_name} powered with PrestaShop™ +
+ + diff --git a/modules/mailalerts/mails/es/productcoverage.txt b/modules/mailalerts/mails/es/productcoverage.txt new file mode 100644 index 000000000..2c15fb1fb --- /dev/null +++ b/modules/mailalerts/mails/es/productcoverage.txt @@ -0,0 +1,10 @@ +Hi, + +The product {product} is almost out of stock. +The stock cover is now less than the specified minimum of {warning_coverage}. +Current stock cover : {current_coverage} + + + + +{shop_url} powered by PrestaShop™ diff --git a/modules/mailalerts/mails/fr/productcoverage.html b/modules/mailalerts/mails/fr/productcoverage.html new file mode 100644 index 000000000..0c05a2b5f --- /dev/null +++ b/modules/mailalerts/mails/fr/productcoverage.html @@ -0,0 +1,34 @@ + + + + + [{shop_name}] Couverture de stock + + + + + + + + + + + + + + + + + + + + + + + + + + +
{shop_name}
 
{product} est en rupture de stock
 
En effet, la couverture est maintenant inférieure à {warning_coverage}.

Couverture actuelle : {current_coverage}

 
{shop_name} propulsé avec PrestaShop™
+ + diff --git a/modules/mailalerts/mails/fr/productcoverage.txt b/modules/mailalerts/mails/fr/productcoverage.txt new file mode 100644 index 000000000..b8de492ca --- /dev/null +++ b/modules/mailalerts/mails/fr/productcoverage.txt @@ -0,0 +1,8 @@ +Bonjour, + +Le produit {product} est bientôt en rupture de stock. +En effet, la couverture de stock est maintenant inférieur à {warning_coverage}. +Couverture actuelle : {current_coverage} + + +{shop_url} réalisé avec PrestaShop™ diff --git a/modules/mailalerts/mails/it/productcoverage.html b/modules/mailalerts/mails/it/productcoverage.html new file mode 100644 index 000000000..a2b4fe47a --- /dev/null +++ b/modules/mailalerts/mails/it/productcoverage.html @@ -0,0 +1,33 @@ + + + + + [{shop_name}] Stock cover + + + + + + + + + + + + + + + + + + +
+ {shop_name} +
 
{product} is almost out of stock.
 
+ The stock cover is now less than the specified minimum of {warning_coverage}.

+ Current stock cover: {current_coverage}

+
 
+ {shop_name} powered with PrestaShop™ +
+ + diff --git a/modules/mailalerts/mails/it/productcoverage.txt b/modules/mailalerts/mails/it/productcoverage.txt new file mode 100644 index 000000000..2c15fb1fb --- /dev/null +++ b/modules/mailalerts/mails/it/productcoverage.txt @@ -0,0 +1,10 @@ +Hi, + +The product {product} is almost out of stock. +The stock cover is now less than the specified minimum of {warning_coverage}. +Current stock cover : {current_coverage} + + + + +{shop_url} powered by PrestaShop™