// Updated mailalerts module

This commit is contained in:
bMancone
2012-03-01 13:32:16 +00:00
parent 06fb8925e9
commit 1ff1f00dab
8 changed files with 206 additions and 157 deletions
+23 -25
View File
@@ -179,7 +179,7 @@ class ProductCore extends ObjectModel
/** @var string ENUM('both', 'catalog', 'search', 'none') front office visibility */
public $visibility;
/** @var string Object creation date */
public $date_add;
@@ -405,7 +405,7 @@ class ProductCore extends ObjectModel
*/
if ($this->id)
$this->id_tax_rules_group = $this->getIdTaxRulesGroup($context);
if ($full && $this->id)
{
$this->isFullyLoaded = $full;
@@ -933,7 +933,7 @@ class ProductCore extends ObjectModel
$front = true;
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
$front = false;
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way))
die (Tools::displayError());
if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add')
@@ -953,7 +953,7 @@ class ProductCore extends ObjectModel
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
AND ptrgs.id_shop='.(int)$context->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
@@ -982,7 +982,7 @@ class ProductCore extends ObjectModel
$front = true;
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
$front = false;
$sql = 'SELECT p.`id_product`, pl.`name`
FROM `'._DB_PREFIX_.'product` p
'.Shop::addSqlAssociation('product', 'p', false).'
@@ -1243,8 +1243,6 @@ class ProductCore extends ObjectModel
);
$this->addSupplierReference($supplier_reference, $id_product_attribute);
Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => $id_product_attribute));
return $return;
}
@@ -1790,7 +1788,7 @@ class ProductCore extends ObjectModel
{
if (!$context)
$context = Context::getContext();
$front = true;
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
$front = false;
@@ -1859,7 +1857,7 @@ class ProductCore extends ObjectModel
);
$sql->leftJoin('image', 'i', 'i.`id_product` = p.`id_product` AND i.`cover` = 1');
$sql->leftJoin('image_lang', 'il', 'i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang);
$sql->leftJoin('product_tax_rules_group_shop', 'ptrgs',
$sql->leftJoin('product_tax_rules_group_shop', 'ptrgs',
'p.`id_product` = ptrgs.`id_product` AND ptrgs.`id_shop` ='.(int)$context->shop->id);
$sql->leftJoin('tax_rule', 'tr', '
ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
@@ -1948,7 +1946,7 @@ class ProductCore extends ObjectModel
$front = true;
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
$front = false;
$current_date = date('Y-m-d H:i:s');
$ids_product = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context);
@@ -1984,7 +1982,7 @@ class ProductCore extends ObjectModel
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
AND ptrgs.id_shop='.(int)$context->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
@@ -2030,7 +2028,7 @@ class ProductCore extends ObjectModel
$front = true;
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
$front = false;
$groups = FrontController::getCurrentCustomerGroups();
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
@@ -2076,7 +2074,7 @@ class ProductCore extends ObjectModel
)
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
AND ptrgs.id_shop='.(int)$context->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
@@ -2979,7 +2977,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (p.`id_manufacturer`= m.`id_manufacturer`)
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
AND ptrgs.id_shop='.(int)$context->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)$context->country->id.'
@@ -4085,23 +4083,23 @@ class ProductCore extends ObjectModel
AND l.`active` = 1
');
}
public static function duplicateTaxRulesGroup($id_old_product, $id_new_product)
{
return Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'product_tax_rules_group_shop (`id_product`, `id_tax_rules_group`, `id_shop`)
(SELECT '.(int)$id_new_product.', `id_tax_rules_group`, `id_shop`
(SELECT '.(int)$id_new_product.', `id_tax_rules_group`, `id_shop`
FROM '._DB_PREFIX_.'product_tax_rules_group_shop WHERE `id_product`='.(int)$id_old_product.')');
}
public function deleteTaxRulesGroup($all_shops = false)
{
$shop = '';
if (!$all_shops)
$shop = ' AND `id_shop`='.(int)Context::getContext()->shop->id;
return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_tax_rules_group_shop
return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_tax_rules_group_shop
WHERE id_product='.(int)$this->id.$shop);
}
}
public function setTaxRulesGroup($id_tax_rules_group, $all_shops = false)
{
if (!Validate::isInt($id_tax_rules_group))
@@ -4110,7 +4108,7 @@ class ProductCore extends ObjectModel
if (Shop::getContext() != Shop::CONTEXT_SHOP)
$all_shops = true;
if ($all_shops)
{
$values = '';
@@ -4122,23 +4120,23 @@ class ProductCore extends ObjectModel
$values = '('.(int)$this->id.','.(int)$id_tax_rules_group.','.(int)Context::getContext()->shop->id.')';
return Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'product_tax_rules_group_shop (`id_product`, `id_tax_rules_group`, `id_shop`) VALUES '.rtrim($values, ','));
}
public function getIdTaxRulesGroup(Context $context = null)
{
return Product::getIdTaxRulesGroupByIdProduct((int)$this->id, $context);
}
public static function getIdTaxRulesGroupByIdProduct($id_product, Context $context = null)
{
if (!$context)
$context = Context::getContext();
if (!Cache::isStored((int)$id_product.'_'.(int)$context->shop->id))
Cache::store((int)$id_product.'_'.(int)$context->shop->id,
Cache::store((int)$id_product.'_'.(int)$context->shop->id,
Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_tax_rules_group`
FROM `'._DB_PREFIX_.'product_tax_rules_group_shop`
WHERE `id_product` = '.(int)$id_product.' AND id_shop='.(int)Context::getContext()->shop->id));
return Cache::retrieve((int)$id_product.'_'.(int)$context->shop->id);
}
+22 -20
View File
@@ -149,6 +149,14 @@ class StockAvailableCore extends ObjectModel
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
$product_quantity += $quantity;
Hook::exec('actionUpdateQuantity',
array(
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute,
'quantity' => $quantity
)
);
}
// updates
@@ -357,13 +365,13 @@ class StockAvailableCore extends ObjectModel
$stock_available->quantity = $stock_available->quantity + $delta_quantity;
$stock_available->update();
$id_lang = Context::getContext()->language->id;
$product = new Product($id_product, true, $id_lang, $id_shop, Context::getContext());
if ($id_product_attribute != 0)
Hook::exec('actionUpdateQuantity', array('product' => $product, 'attribute_id' => $id_product_attribute));
else
Hook::exec('actionProductUpdate', array('product' => $product));
Hook::exec('actionUpdateQuantity',
array(
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute,
'quantity' => $stock_available->quantity
)
);
}
@@ -391,9 +399,6 @@ class StockAvailableCore extends ObjectModel
{
$id_stock_available = (int)StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
$product = new Product($id_product, true, $id_lang, $id_shop, $context);
Hook::exec('actionUpdateQuantity', array('product' => $product, 'attribute_id' => $id_product_attribute));
if ($id_stock_available)
{
$stock_available = new StockAvailable($id_stock_available);
@@ -429,19 +434,16 @@ class StockAvailableCore extends ObjectModel
}
$stock_available->add();
}
}
else
{
$product = new Product($id_product, true, $id_lang, $id_shop, $context);
if ($id_product_attribute != 0)
Hook::exec('actionUpdateQuantity', array('product' => $product, 'attribute_id' => $id_product_attribute));
else
Hook::exec('actionProductUpdate', array('product' => $product));
Hook::exec('actionUpdateQuantity',
array(
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute,
'quantity' => $stock_available->quantity
)
);
}
}
/**
+1
View File
@@ -231,6 +231,7 @@ class StockMvtCore extends ObjectModel
$query->orderBy('date_add DESC');
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
if ($res != false)
return $res['0'];
return false;
@@ -1540,7 +1540,6 @@ class AdminProductsControllerCore extends AdminController
$this->errors[] = Tools::displayError('An error occurred while adding tags.');
elseif (empty($this->errors))
{
Hook::exec('actionProductUpdate', array('product' => $object));
if (in_array($object->visibility, array('both', 'search')))
Search::indexation(false, $object->id);
@@ -147,6 +147,7 @@ class AdminStockManagementControllerCore extends AdminController
$last_sm_quantity = 0;
$last_sm_quantity_is_usable = -1;
$last_sm = StockMvt::getLastPositiveStockMvt($id_product, $id_product_attribute);
if ($last_sm != false)
{
$last_sm_currency = new Currency((int)$last_sm['id_currency']);
@@ -1033,6 +1034,9 @@ class AdminStockManagementControllerCore extends AdminController
'is_post' => 1,
);
if ($this->display == 'addstock')
$_POST['id_product'] = (int)$id_product;
if ($this->display == 'transferstock')
{
$helper->fields_value['id_warehouse_from'] = Tools::getValue('id_warehouse_from', '');
+40 -23
View File
@@ -54,34 +54,34 @@ class MailAlert extends ObjectModel
public static function customerHasNotification($id_customer, $id_product, $id_product_attribute, $id_shop = null)
{
if ($id_shop == null)
$id_shop = Context::getContext()->shop->id;
$customer = new Customer($id_customer);
$customer_email = $customer->email;
$sql = 'SELECT *
$sql = '
SELECT *
FROM `'._DB_PREFIX_.self::$definition['table'].'`
WHERE (`id_customer` = '.(int)$id_customer.'
OR `customer_email` = \''.pSQL($customer_email).'\')
AND `id_product` = '.(int)$id_product.'
WHERE (`id_customer` = '.(int)$id_customer.' OR `customer_email` = \''.pSQL($customer_email).'\')
AND `id_product` = '.(int)$id_product.'
AND `id_product_attribute` = '.(int)$id_product_attribute.'
AND `id_shop` = '.(int)$id_shop;
return sizeof(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)
{
$sql = 'DELETE FROM `'._DB_PREFIX_.self::$definition['table'].'`
$sql = '
DELETE FROM `'._DB_PREFIX_.self::$definition['table'].'`
WHERE '.(($id_customer > 0) ? '(`customer_email` = \''.pSQL($customer_email).'\'
OR `id_customer` = '.(int)$id_customer.')' :
'`customer_email` = \''.pSQL($customer_email).'\'').
' AND `id_product` = '.(int)$id_product.'
AND `id_product_attribute` = '.(int)$id_product_attribute;
return Db::getInstance()->Execute($sql);
return Db::getInstance()->execute($sql);
}
/*
@@ -98,11 +98,12 @@ class MailAlert extends ObjectModel
$customer = new Customer($id_customer);
$customer_email = $customer->email;
$products = MailAlert::getProducts($customer, $id_lang);
$products_number = count($products);
if ((empty($products) === true) || (!sizeof($products)))
if (empty($products) === true || !$products_number)
return array();
for ($i = 0; $i < sizeof($products); ++$i)
for ($i = 0; $i < $products_number; ++$i)
{
$obj = new Product((int)$products[$i]['id_product'], false, (int)$id_lang);
if (!Validate::isLoadedObject($obj))
@@ -113,40 +114,52 @@ class MailAlert extends ObjectModel
{
$attributes = self::getProductAttributeCombination($products[$i]['id_product_attribute'], $id_lang);
$products[$i]['attributes_small'] = '';
if ($attributes)
foreach ($attributes AS $k => $row)
{
foreach ($attributes as $k => $row)
$products[$i]['attributes_small'] .= $row['attribute_name'].', ';
}
$products[$i]['attributes_small'] = rtrim($products[$i]['attributes_small'], ', ');
$products[$i]['id_shop'] = $shop->id;
/* Get cover */
$attrgrps = $obj->getAttributesGroups((int)($id_lang));
foreach ($attrgrps AS $attrgrp)
$attrgrps = $obj->getAttributesGroups((int)$id_lang);
foreach ($attrgrps as $attrgrp)
{
if ($attrgrp['id_product_attribute'] == (int)$products[$i]['id_product_attribute']
&& $images = Product::_getAttributeImageAssociations((int)$attrgrp['id_product_attribute']))
{
$products[$i]['cover'] = $obj->id.'-'.array_pop($images);
break;
}
}
}
if (!isset($products[$i]['cover']) || !$products[$i]['cover'])
{
$images = $obj->getImages((int)$id_lang);
foreach ($images as $k => $image)
{
if ($image['cover'])
{
$products[$i]['cover'] = $obj->id.'-'.$image['id_image'];
break;
}
}
}
if (!isset($products[$i]['cover']))
$products[$i]['cover'] = Language::getIsoById($id_lang).'-default';
$products[$i]['link'] = $obj->getLink();
$products[$i]['link_rewrite'] = $obj->link_rewrite;
}
return ($products);
}
public static function sendCustomerAlert($id_product, $id_product_attribute)
{
$link = new Link();
@@ -157,7 +170,7 @@ class MailAlert extends ObjectModel
'{product}' => (is_array($product->name) ? $product->name[$id_lang] : $product->name),
'{product_link}' => $link->getProductLink($product)
);
$customers = self::getCustomers($id_product, $id_product_attribute);
foreach ($customers as $customer)
{
@@ -173,13 +186,13 @@ class MailAlert extends ObjectModel
$customer_email = $customer['customer_email'];
}
$iso = Language::getIsoById($id_lang);
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.txt') &&
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/');
Hook::exec('actionModuleMailAlertSendCustomer', array('product' => (is_array($product->name) ? $product->name[$id_lang] : $product->name), 'link' => $link->getProductLink($product)));
self::deleteAlert((int)$customer_id, strval($customer_email), (int)$id_product, (int)$id_product_attribute);
}
}
@@ -197,7 +210,8 @@ class MailAlert extends ObjectModel
*/
public static function getProducts($customer, $id_lang)
{
$sql = 'SELECT ma.`id_product`, p.`quantity` AS product_quantity, pl.`name`, ma.`id_product_attribute`
$sql = '
SELECT ma.`id_product`, p.`quantity` AS product_quantity, pl.`name`, ma.`id_product_attribute`
FROM `'._DB_PREFIX_.self::$definition['table'].'` ma
JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = ma.`id_product`
JOIN `'._DB_PREFIX_.'product_lang` pl ON pl.`id_product` = ma.`id_product`
@@ -206,7 +220,7 @@ class MailAlert extends ObjectModel
OR ma.`customer_email` = \''.pSQL($customer->email).'\')
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestriction(false, 'ma');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
/*
@@ -214,7 +228,8 @@ class MailAlert extends ObjectModel
*/
public static function getProductAttributeCombination($id_product_attribute, $id_lang)
{
$sql = 'SELECT al.`name` AS attribute_name
$sql = '
SELECT al.`name` AS attribute_name
FROM `'._DB_PREFIX_.'product_attribute_combination` pac
LEFT JOIN `'._DB_PREFIX_.'attribute` a ON (a.`id_attribute` = pac.`id_attribute`)
LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`)
@@ -223,7 +238,7 @@ class MailAlert extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
WHERE pac.`id_product_attribute` = '.(int)$id_product_attribute;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
/*
@@ -231,10 +246,12 @@ class MailAlert extends ObjectModel
*/
public static function getCustomers($id_product, $id_product_attribute)
{
$sql = 'SELECT id_customer, customer_email
$sql = '
SELECT id_customer, customer_email
FROM `'._DB_PREFIX_.self::$definition['table'].'`
WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
}
}
+115 -87
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2012 PrestaShop
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -49,7 +49,7 @@ class MailAlerts extends Module
$this->author = 'PrestaShop';
parent::__construct();
if ($this->id)
$this->init();
@@ -57,7 +57,7 @@ class MailAlerts extends Module
$this->description = $this->l('Sends e-mail notifications to customers and merchants.');
$this->confirmUninstall = $this->l('Are you sure you want to delete all customer notifications?');
}
private function init()
{
$this->_merchant_mails = strval(Configuration::get('MA_MERCHANT_MAILS'));
@@ -68,18 +68,16 @@ class MailAlerts extends Module
public function install()
{
if (!parent::install()
|| !$this->registerHook('actionValidateOrder')
|| !$this->registerHook('actionUpdateQuantity')
|| !$this->registerHook('actionProductOutOfStock')
|| !$this->registerHook('displayCustomerAccount')
|| !$this->registerHook('displayMyAccountBlock')
|| !$this->registerHook('actionProductUpdate')
|| !$this->registerHook('actionProductDelete')
|| !$this->registerHook('actionProductAttributeDelete')
|| !$this->registerHook('actionProductAttributeUpdate')
|| !$this->registerHook('displayHeader')
)
if (!parent::install() ||
!$this->registerHook('actionValidateOrder') ||
!$this->registerHook('actionUpdateQuantity') ||
!$this->registerHook('actionProductOutOfStock') ||
!$this->registerHook('displayCustomerAccount') ||
!$this->registerHook('displayMyAccountBlock') ||
!$this->registerHook('actionProductDelete') ||
!$this->registerHook('actionProductAttributeDelete') ||
!$this->registerHook('actionProductAttributeUpdate') ||
!$this->registerHook('displayHeader'))
return false;
Configuration::updateValue('MA_MERCHANT_ORDER', 1);
@@ -88,16 +86,17 @@ class MailAlerts extends Module
Configuration::updateValue('MA_MERCHANT_MAILS', Configuration::get('PS_SHOP_EMAIL'));
Configuration::updateValue('MA_LAST_QTIES', (int)Configuration::get('PS_LAST_QTIES'));
$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.MailAlert::$definition['table'].'` (
`id_customer` int(10) unsigned NOT NULL,
`customer_email` varchar(128) NOT NULL,
`id_product` int(10) unsigned NOT NULL,
`id_product_attribute` int(10) unsigned NOT NULL,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_customer`,`customer_email`,`id_product`,`id_product_attribute`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.MailAlert::$definition['table'].'`
(
`id_customer` int(10) unsigned NOT NULL,
`customer_email` varchar(128) NOT NULL,
`id_product` int(10) unsigned NOT NULL,
`id_product_attribute` int(10) unsigned NOT NULL,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_customer`,`customer_email`,`id_product`,`id_product_attribute`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
if (!Db::getInstance()->Execute($sql))
if (!Db::getInstance()->execute($sql))
return false;
return true;
@@ -111,7 +110,7 @@ class MailAlerts extends Module
Configuration::deleteByName('MA_MERCHANT_MAILS');
Configuration::deleteByName('MA_LAST_QTIES');
if (!Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.MailAlert::$definition['table']))
if (!Db::getInstance()->execute('DROP TABLE '._DB_PREFIX_.MailAlert::$definition['table']))
return false;
return parent::uninstall();
@@ -153,24 +152,26 @@ class MailAlerts extends Module
$errors[] = $this->l('Invalid e-mail:').' '.$email;
break;
}
else if (!empty($email) && sizeof($email))
else if (!empty($email) && count($email) > 0)
$emails[$k] = $email;
else
unset($emails[$k]);
}
$emails = implode(self::__MA_MAIL_DELIMITOR__, $emails);
if (!Configuration::updateValue('MA_MERCHANT_MAILS', strval($emails)))
$errors[] = $this->l('Cannot update settings');
elseif (!Configuration::updateValue('MA_MERCHANT_ORDER', (int)Tools::getValue('mA_merchand_order')))
else if (!Configuration::updateValue('MA_MERCHANT_ORDER', (int)Tools::getValue('mA_merchand_order')))
$errors[] = $this->l('Cannot update settings');
elseif (!Configuration::updateValue('MA_MERCHANT_OOS', (int)Tools::getValue('mA_merchand_oos')))
else if (!Configuration::updateValue('MA_MERCHANT_OOS', (int)Tools::getValue('mA_merchand_oos')))
$errors[] = $this->l('Cannot update settings');
elseif (!Configuration::updateValue('MA_LAST_QTIES', (int)Tools::getValue('MA_LAST_QTIES')))
else if (!Configuration::updateValue('MA_LAST_QTIES', (int)Tools::getValue('MA_LAST_QTIES')))
$errors[] = $this->l('Cannot update settings');
}
}
if (sizeof($errors))
if (count($errors) > 0)
echo $this->displayError(implode('<br />', $errors));
$this->init();
@@ -205,7 +206,7 @@ class MailAlerts extends Module
</div>
<label>'.$this->l('Alert 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" />
<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>
</div>
<label>'.$this->l('Send to these e-mail addresses:').' </label>
@@ -228,7 +229,7 @@ class MailAlerts extends Module
public function hookActionValidateOrder($params)
{
if (!$this->_merchant_order OR empty($this->_merchant_mails))
if (!$this->_merchant_order || empty($this->_merchant_mails))
return;
// Getting differents vars
@@ -246,47 +247,51 @@ class MailAlerts extends Module
if (!$message || empty($message))
$message = $this->l('No message');
$itemsTable = '';
$items_table = '';
$products = $params['order']->getProducts();
$customizedDatas = Product::getAllCustomizedDatas((int)$params['cart']->id);
Product::addCustomizationPrice($products, $customizedDatas);
$customized_datas = Product::getAllCustomizedDatas((int)$params['cart']->id);
Product::addCustomizationPrice($products, $customized_datas);
foreach ($products as $key => $product)
{
$unit_price = $product['product_price_wt'];
$price = $product['total_price'];
$customizationText = '';
if (isset($customizedDatas[$product['product_id']][$product['product_attribute_id']]))
$customization_text = '';
if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']]))
{
foreach ($customizedDatas[$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_]))
foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text)
$customizationText .= $text['name'].':'.' '.$text['value'].'<br />';
$customization_text .= $text['name'].': '.$text['value'].'<br />';
if (isset($customization['datas'][_CUSTOMIZE_FILE_]))
$customizationText .= sizeof($customization['datas'][_CUSTOMIZE_FILE_]) .' '. Tools::displayError('image(s)').'<br />';
$customization_text .= count($customization['datas'][_CUSTOMIZE_FILE_]).' '.Tools::displayError('image(s)').'<br />';
$customizationText .= '---<br />';
$customization_text .= '---<br />';
}
$customizationText = rtrim($customizationText, '---<br />');
$customization_text = rtrim($customization_text, '---<br />');
}
$itemsTable .=
$items_table .=
'<tr style="background-color:'.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
<td style="padding:0.6em 0.4em;">'.$product['product_reference'].'</td>
<td style="padding:0.6em 0.4em;"><strong>'.$product['product_name'].(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '').(!empty($customizationText) ? '<br />'.$customizationText : '').'</strong></td>
<td style="padding:0.6em 0.4em;">
<strong>'
.$product['product_name'].(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '').(!empty($customization_text) ? '<br />'.$customization_text : '').
'</strong>
</td>
<td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td>
<td style="padding:0.6em 0.4em; text-align:center;">'.(int)($product['product_quantity']).'</td>
<td style="padding:0.6em 0.4em; text-align:center;">'.(int)$product['product_quantity'].'</td>
<td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false).'</td>
</tr>';
}
foreach ($params['order']->getCartRules() as $discount)
{
$itemsTable .=
$items_table .=
'<tr style="background-color:#EBECEE;">
<td colspan="4" style="padding:0.6em 0.4em; text-align:right;">'.$this->l('Voucher code:').' '.$discount['name'].'</td>
<td style="padding:0.6em 0.4em; text-align:right;">-'.Tools::displayPrice($discount['value'], $currency, false).'</td>
@@ -300,16 +305,16 @@ class MailAlerts extends Module
// Filling-in vars for email
$template = 'new_order';
$subject = $this->l('New order', $id_lang).' - '.sprintf('%06d', $order->id);
$templateVars = array(
$template_vars = array(
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{email}' => $customer->email,
'{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\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:#DB3484; font-weight:bold;">%s</span>',
'lastname' => '<span style="color:#DB3484; 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:#DB3484; font-weight:bold;">%s</span>',
'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')),
'{delivery_company}' => $delivery->company,
@@ -334,12 +339,12 @@ class MailAlerts extends Module
'{invoice_state}' => $invoice->id_state ? $invoice_state->name : '',
'{invoice_phone}' => $invoice->phone,
'{invoice_other}' => $invoice->other,
'{order_name}' => sprintf("%06d", $order->id),
'{order_name}' => sprintf('%06d', $order->id),
'{shop_name}' => Configuration::get('PS_SHOP_NAME'),
'{date}' => $order_date_text,
'{carrier}' => (($carrier->name == '0') ? Configuration::get('PS_SHOP_NAME') : $carrier->name),
'{payment}' => Tools::substr($order->payment, 0, 32),
'{items}' => $itemsTable,
'{items}' => $items_table,
'{total_paid}' => Tools::displayPrice($order->total_paid, $currency),
'{total_products}' => Tools::displayPrice($order->getTotalProductsWithTaxes(), $currency),
'{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency),
@@ -351,24 +356,35 @@ class MailAlerts extends Module
$iso = Language::getIsoById($id_lang);
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.txt') && file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.html'))
Mail::Send($id_lang, $template, $subject, $templateVars, explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails), NULL, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], NULL, NULL, dirname(__FILE__).'/mails/');
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.txt') &&
file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.html'))
Mail::Send($id_lang,
$template,
$subject,
$template_vars,
explode(self::__MA_MAIL_DELIMITOR__, $this->_merchant_mails),
null,
$configuration['PS_SHOP_EMAIL'],
$configuration['PS_SHOP_NAME'],
null,
null,
dirname(__FILE__).'/mails/');
}
public function hookActionProductOutOfStock($params)
{
if (!$this->_customer_qty)
return ;
return;
$id_product_attribute = 0;
$id_product = (int)$params['product']->id;
$id_product_attribute = 0;
$id_customer = (int)Context::getContext()->customer->id;
if (!(int)Context::getContext()->customer->isLogged())
$this->context->smarty->assign('email', 1);
else if (MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute))
return ;
return;
$this->context->smarty->assign(array(
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute));
@@ -378,37 +394,46 @@ class MailAlerts extends Module
public function hookActionUpdateQuantity($params)
{
$product = $params['product'];
$id_product = (int)$params['id_product'];
$id_product_attribute = (int)$params['id_product_attribute'];
$quantity = (int)$params['quantity'];
$id_shop = (int)Context::getContext()->shop->id;
$id_lang = (int)Context::getContext()->language->id;
$product = new Product($id_product, true, $id_lang, $id_shop, Context::getContext());
$ma_last_qties = (int)Configuration::get('MA_LAST_QTIES');
if ((int)$product->quantity <= (int)Configuration::get('MA_LAST_QTIES') &&
!(!$this->_merchant_oos || empty($this->_merchant_mails)) && StockAvailable::dependsOnStock($product->id))
if ($product->active == 1 && (int)$quantity <= $ma_last_qties && !(!$this->_merchant_oos || empty($this->_merchant_mails)))
{
$templateVars = array('{qty}' => (int)$product->quantity,
'{last_qty}' => (int)Configuration::get('MA_LAST_QTIES'),
'{product}' => strval((int)$product->name).(isset($product->attributes_small) ? ' '.$product->attributes_small : ''));
$iso = Language::getIsoById($id_lang);
if ($product->active == 1)
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.txt') && file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.html'))
Mail::Send($id_lang, 'productoutofstock', Mail::l('Product out of stock', $id_lang), $templateVars, 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/');
}
if ($this->_customer_qty && $product->quantity > 0)
MailAlert::sendCustomerAlert((int)$product->id, (int)$params['attribute_id']);
}
$product_name = Product::getProductName($id_product, $id_product_attribute, $id_lang);
$template_vars = array(
'{qty}' => $quantity,
'{last_qty}' => $ma_last_qties,
'{product}' => pSQL($product_name));
public function hookActionProductUpdate($params)
{
/* We specify 0 as an id_product_attribute because this hook is called when the main product is updated */
if ($this->_customer_qty && $product->quantity > 0)
MailAlert::sendCustomerAlert((int)$params['product']->id, 0);
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.txt') &&
file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.html'))
Mail::Send($id_lang,
'productoutofstock',
Mail::l('Product out of stock', $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/');
}
if ($this->_customer_qty && $quantity > 0)
MailAlert::sendCustomerAlert((int)$product->id, (int)$params['attribute_id']);
}
public function hookActionProductAttributeUpdate($params)
{
$sql = 'SELECT `id_product`, `quantity`
$sql = '
SELECT `id_product`, `quantity`
FROM `'._DB_PREFIX_.'stock_available`
WHERE `id_product_attribute` = '.(int)$params['id_product_attribute'];
@@ -417,32 +442,35 @@ class MailAlerts extends Module
if ($this->_customer_qty && $result['quantity'] > 0)
MailAlert::sendCustomerAlert((int)$result['id_product'], (int)$params['id_product_attribute']);
}
public function hookDisplayCustomerAccount($params)
{
return $this->_customer_qty ? $this->display(__FILE__, 'my-account.tpl') : NULL;
return $this->_customer_qty ? $this->display(__FILE__, 'my-account.tpl') : null;
}
public function hookDisplayMyAccountBlock($params)
{
return $this->hookDisplayCustomerAccount($params);
}
public function hookActionProductDelete($params)
{
$sql = 'DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
$sql = '
DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
WHERE `id_product` = '.(int)$params['product']->id;
Db::getInstance()->Execute($sql);
}
public function hookActionAttributeDelete($params)
{
if ($params['deleteAllAttributes'])
$sql = 'DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
$sql = '
DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
WHERE `id_product` = '.(int)$params['id_product'];
else
$sql = 'DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
$sql = '
DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
WHERE `id_product_attribute` = '.(int)$params['id_product_attribute'].'
AND `id_product` = '.(int)$params['id_product'];
@@ -19,7 +19,7 @@
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 8234 $
* @version Release: $Revision$
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}