// 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
This commit is contained in:
bMancone
2012-03-05 18:52:25 +00:00
parent 92a3249e8b
commit b361e985c0
13 changed files with 325 additions and 11 deletions
+10
View File
@@ -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;
}
+1 -1
View File
@@ -2,7 +2,7 @@
<module>
<name>mailalerts</name>
<displayName><![CDATA[Mail alerts]]></displayName>
<version><![CDATA[2.3]]></version>
<version><![CDATA[2.4]]></version>
<description><![CDATA[Sends e-mail notifications to customers and merchants.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
+100 -10
View File
@@ -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 '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
<fieldset><legend><img src="'.$this->_path.'logo.gif" />'.$this->l('Customer notification').'</legend>
<fieldset><legend><img src="'.$this->_path.'logo.gif" />'.$this->l('Customer notifications').'</legend>
<div style="clear:both;">&nbsp;</div>
<label>'.$this->l('Product availability:').' </label>
<div class="margin-form">
<input type="checkbox" value="1" id="mA_customer_qty" name="mA_customer_qty" '.(Tools::getValue('mA_customer_qty', $this->_customer_qty) == 1 ? 'checked' : '').'>
@@ -192,28 +206,44 @@ class MailAlerts extends Module
</div>
</fieldset>
</form>
<br />
<div style="clear:both;">&nbsp;</div>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
<fieldset><legend><img src="'.$this->_path.'logo.gif" />'.$this->l('Merchant notification').'</legend>
<fieldset>
<legend><img src="'.$this->_path.'logo.gif" />'.$this->l('Merchant notifications').'</legend>
<div style="clear:both;">&nbsp;</div>
<label>'.$this->l('New order:').' </label>
<div class="margin-form">
<input type="checkbox" value="1" id="mA_merchand_order" name="mA_merchand_order" '.(Tools::getValue('mA_merchand_order', $this->_merchant_order) == 1 ? 'checked' : '').'>
&nbsp;<label for="mA_merchand_order" class="t">'.$this->l('Receive a notification if a new order is made').'</label>
&nbsp;<label for="mA_merchand_order" class="t">'.$this->l('Receive a notification when an order is placed').'</label>
</div>
<div style="clear:both;">&nbsp;</div>
<label>'.$this->l('Out of stock:').' </label>
<div class="margin-form">
<input type="checkbox" value="1" id="mA_merchand_oos" name="mA_merchand_oos" '.(Tools::getValue('mA_merchand_oos', $this->_merchant_oos) == 1 ? 'checked' : '').'>
&nbsp;<label for="mA_merchand_oos" class="t">'.$this->l('Receive a notification if the quantity of a product is below the alert threshold').'</label>
&nbsp;<label for="mA_merchand_oos" class="t">'.$this->l('Receive a notification if the available quantity of a product is below the following threshold').'</label>
</div>
<label>'.$this->l('Alert threshold:').'</label>
<label>'.$this->l('Threshold:').'</label>
<div class="margin-form">
<input type="text" name="MA_LAST_QTIES" value="'.(Tools::getValue('MA_LAST_QTIES') != null ? (int)Tools::getValue('MA_LAST_QTIES') : Configuration::get('MA_LAST_QTIES')).'" size="3" />
<p>'.$this->l('Quantity for which a product is regarded as out of stock').'</p>
<p>'.$this->l('Quantity for which a product is considered out of stock').'</p>
</div>
<label>'.$this->l('Send to these e-mail addresses:').' </label>
<div style="clear:both;">&nbsp;</div>
<label>'.$this->l('Coverage warning:').' </label>
<div class="margin-form">
<input type="checkbox" value="1" id="mA_merchant_coverage" name="mA_merchant_coverage" '.(Tools::getValue('mA_merchant_coverage', $this->_merchant_coverage) == 1 ? 'checked' : '').'>
&nbsp;<label for="mA_merchant_coverage" class="t">'.$this->l('Receive a notification if the stock coverage of a product is below the following coverage').'</label>
</div>
<label>'.$this->l('Coverage:').'</label>
<div class="margin-form">
<input type="text" name="MA_PRODUCT_COVERAGE" value="'.(Tools::getValue('MA_PRODUCT_COVERAGE') != null ? (int)Tools::getValue('MA_PRODUCT_COVERAGE') : Configuration::getGlobalValue('MA_PRODUCT_COVERAGE')).'" size="3" />
<p>'.$this->l('Stock cover, in days. Also, the stock cover of a given product will be calculated based on this number').'</p>
</div>
<div style="clear:both;">&nbsp;</div>
<div style="clear:both;">&nbsp;</div>
<label>'.$this->l('E-mail addresses:').' </label>
<div class="margin-form">
<div style="float:left; margin-right:10px;">
<textarea name="ma_merchant_mails" rows="10" cols="30">'.Tools::getValue('ma_merchant_mails', str_replace(self::__MA_MAIL_DELIMITOR__, "\n", $this->_merchant_mails)).'</textarea>
<textarea name="ma_merchant_mails" rows="10" cols="40">'.Tools::getValue('ma_merchant_mails', str_replace(self::__MA_MAIL_DELIMITOR__, "\n", $this->_merchant_mails)).'</textarea>
</div>
<div style="float:left;">
'.$this->l('One e-mail address per line').'<br />
@@ -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');
@@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>[{shop_name}] Stock cover</title>
</head>
<body>
<table style="font-family:Verdana,sans-serif; font-size:11px; color:#374953; width: 550px;">
<tr>
<td align="left">
<a href="{shop_url}" title="{shop_name}"><img alt="{shop_name}" src="{shop_logo}" style="border:none;" ></a>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left" style="background-color:#DB3484; color:#FFF; font-size: 12px; font-weight:bold; padding: 0.5em 1em;">{product} is almost out of stock.</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
The stock cover is now less than the specified minimum of <strong>{warning_coverage}</strong>.<br /><br />
<strong>Current stock cover: <span style="color:#DB3484;">{current_coverage}</span></strong><br /><br />
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="center" style="font-size:10px; border-top: 1px solid #D9DADE;">
<a href="{shop_url}" style="color:#DB3484; font-weight:bold; text-decoration:none;">{shop_name}</a> powered with <a href="http://www.prestashop.com/" style="text-decoration:none; color:#374953;">PrestaShop™</a>
</td>
</tr>
</table>
</body>
</html>
@@ -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™
@@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>[{shop_name}] Stock cover</title>
</head>
<body>
<table style="font-family:Verdana,sans-serif; font-size:11px; color:#374953; width: 550px;">
<tr>
<td align="left">
<a href="{shop_url}" title="{shop_name}"><img alt="{shop_name}" src="{shop_logo}" style="border:none;" ></a>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left" style="background-color:#DB3484; color:#FFF; font-size: 12px; font-weight:bold; padding: 0.5em 1em;">{product} is almost out of stock.</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
The stock cover is now less than the specified minimum of <strong>{warning_coverage}</strong>.<br /><br />
<strong>Current stock cover: <span style="color:#DB3484;">{current_coverage}</span></strong><br /><br />
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="center" style="font-size:10px; border-top: 1px solid #D9DADE;">
<a href="{shop_url}" style="color:#DB3484; font-weight:bold; text-decoration:none;">{shop_name}</a> powered with <a href="http://www.prestashop.com/" style="text-decoration:none; color:#374953;">PrestaShop™</a>
</td>
</tr>
</table>
</body>
</html>
@@ -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™
@@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>[{shop_name}] Stock cover</title>
</head>
<body>
<table style="font-family:Verdana,sans-serif; font-size:11px; color:#374953; width: 550px;">
<tr>
<td align="left">
<a href="{shop_url}" title="{shop_name}"><img alt="{shop_name}" src="{shop_logo}" style="border:none;" ></a>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left" style="background-color:#DB3484; color:#FFF; font-size: 12px; font-weight:bold; padding: 0.5em 1em;">{product} is almost out of stock.</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
The stock cover is now less than the specified minimum of <strong>{warning_coverage}</strong>.<br /><br />
<strong>Current stock cover: <span style="color:#DB3484;">{current_coverage}</span></strong><br /><br />
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="center" style="font-size:10px; border-top: 1px solid #D9DADE;">
<a href="{shop_url}" style="color:#DB3484; font-weight:bold; text-decoration:none;">{shop_name}</a> powered with <a href="http://www.prestashop.com/" style="text-decoration:none; color:#374953;">PrestaShop™</a>
</td>
</tr>
</table>
</body>
</html>
@@ -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™
@@ -0,0 +1,34 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>[{shop_name}] Couverture de stock</title>
</head>
<body>
<table style="font-family: Verdana,sans-serif; font-size: 11px; color: #374953; width: 550px;">
<tbody>
<tr>
<td align="left"><a title="{shop_name}" href="{shop_url}"><img style="border: none;" src="{shop_logo}" alt="{shop_name}" /></a></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td style="background-color: #db3484; color: #fff; font-size: 12px; font-weight: bold; padding: 0.5em 1em;" align="left">{product} est en rupture de stock</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left">En effet, la couverture est maintenant inf&eacute;rieure &agrave; <strong>{warning_coverage}</strong>.<br /><br /> <strong>Couverture actuelle : <span style="color: #db3484;">{current_coverage}</span></strong><br /><br /></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td style="font-size: 10px; border-top: 1px solid #D9DADE;" align="center"><a style="color: #db3484; font-weight: bold; text-decoration: none;" href="{shop_url}">{shop_name}</a> propuls&eacute; avec <a style="text-decoration: none; color: #374953;" href="http://www.prestashop.com/">PrestaShop&trade;</a></td>
</tr>
</tbody>
</table>
</body>
</html>
@@ -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™
@@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>[{shop_name}] Stock cover</title>
</head>
<body>
<table style="font-family:Verdana,sans-serif; font-size:11px; color:#374953; width: 550px;">
<tr>
<td align="left">
<a href="{shop_url}" title="{shop_name}"><img alt="{shop_name}" src="{shop_logo}" style="border:none;" ></a>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left" style="background-color:#DB3484; color:#FFF; font-size: 12px; font-weight:bold; padding: 0.5em 1em;">{product} is almost out of stock.</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
The stock cover is now less than the specified minimum of <strong>{warning_coverage}</strong>.<br /><br />
<strong>Current stock cover: <span style="color:#DB3484;">{current_coverage}</span></strong><br /><br />
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="center" style="font-size:10px; border-top: 1px solid #D9DADE;">
<a href="{shop_url}" style="color:#DB3484; font-weight:bold; text-decoration:none;">{shop_name}</a> powered with <a href="http://www.prestashop.com/" style="text-decoration:none; color:#374953;">PrestaShop™</a>
</td>
</tr>
</table>
</body>
</html>
@@ -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™