[-] MO : MailAlerts module upgraded for PrestaShop 1.5

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12688 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
fGaillard
2012-01-25 16:04:31 +00:00
parent 33cf4fab23
commit a15c3ce6eb
20 changed files with 956 additions and 492 deletions
+3
View File
@@ -1189,6 +1189,9 @@ class ProductCore extends ObjectModel
$id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity, $available_date
);
$this->addSupplierReference($supplier_reference, $id_product_attribute);
Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => $id_product_attribute));
return $return;
}
+23
View File
@@ -356,6 +356,14 @@ class StockAvailableCore extends ObjectModel
$stock_available = new StockAvailable($id_stock_available);
$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));
}
@@ -375,12 +383,16 @@ class StockAvailableCore extends ObjectModel
if (is_null($id_shop))
$id_shop = (int)$context->shop->getID(true);
$id_lang = Context::getContext()->language->id;
$depends_on_stock = StockAvailable::dependsOnStock($id_product);
//Try to set available quantitiy if product does not depend on physical stock
if (!$depends_on_stock)
{
$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)
{
@@ -417,8 +429,19 @@ 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));
}
}
/**
@@ -0,0 +1,17 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
function update_mailalerts_add_column_idshop()
{
$id_mailalerts = Db::getInstance()->getValue('SELECT id_module FROM `'._DB_PREFIX_.'module` WHERE name = "mailalerts"');
if($id_mailalerts)
$res = Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'mailalert_customer_oos` ADD COLUMN `id_shop` int(11) NOT NULL default "0" AFTER `id_customer`');
if ($res)
return true;
else
return array('error' => 1, 'msg' => sprintf('unable to create column id_shop (%s)', Db::getInstance ()->getMsgError()));
}
+10 -11
View File
@@ -11,6 +11,15 @@ ALTER TABLE `PREFIX_image_type` DROP `id_theme`;
ALTER TABLE `PREFIX_specific_price_rule_condition` CHANGE `id_specific_price_rule_condition` `id_specific_price_rule_condition` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `PREFIX_specific_price_rule_condition_group` CHANGE `id_specific_price_rule_condition_group` `id_specific_price_rule_condition_group` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT;
UPDATE `PREFIX_supply_order_state_lang`
SET `name` = "order canceled"
WHERE `name` = "order fenced" AND (`id_lang` = 1 OR `id_lang` = 3 OR `id_lang` = 4 OR `id_lang` = 5);
UPDATE `PREFIX_supply_order_state_lang`
SET `name` = "Commande cloturée"
WHERE `name` = "order fenced" AND id_lang = 2;
CREATE TABLE `PREFIX_category_shop` (
`id_category` int(11) NOT NULL,
`id_shop` int(11) NOT NULL,
@@ -18,16 +27,6 @@ CREATE TABLE `PREFIX_category_shop` (
UNIQUE KEY `id_category_shop` (`id_category`,`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
/* PHP:generate_root_category_for_multishop(); */;
CREATE TABLE `PREFIX_module_preference` (
`id_module_preference` int(11) NOT NULL auto_increment,
`id_employee` int(11) NOT NULL,
`module` varchar(255) NOT NULL,
`interest` tinyint(1) default NULL,
`favorite` tinyint(1) default NULL,
PRIMARY KEY (`id_module_preference`),
UNIQUE KEY `employee_module` (`id_employee`, `module`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
/* PHP:update_mailalerts_add_column_idshop(); */;
+238
View File
@@ -0,0 +1,238 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 12476 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class MailAlert extends ObjectModel
{
public $id_customer;
public $customer_email;
public $id_product;
public $id_product_attribute;
public $id_shop;
/**
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'mailalert_customer_oos',
'primary' => 'id_customer',
'fields' => array(
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', '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_attribute' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true)
),
);
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 *
FROM `'._DB_PREFIX_.self::$definition['table'].'`
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));
}
public static function deleteAlert($id_customer, $customer_email, $id_product, $id_product_attribute)
{
$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);
}
/*
* Get objects that will be viewed on "My alerts" page
*/
public static function getMailAlerts($id_customer, $id_lang, Shop $shop = null)
{
if (!Validate::isUnsignedId($id_customer) || !Validate::isUnsignedId($id_lang))
die (Tools::displayError());
if (!$shop)
$shop = Context::getContext()->shop;
$customer = new Customer($id_customer);
$customer_email = $customer->email;
$products = MailAlert::getProducts($customer, $id_lang, $shop);
if ((empty($products) === true) || (!sizeof($products)))
return array();
for ($i = 0; $i < sizeof($products); ++$i)
{
$obj = new Product((int)$products[$i]['id_product'], false, (int)$id_lang);
if (!Validate::isLoadedObject($obj))
continue;
if (isset($products[$i]['id_product_attribute']) &&
Validate::isUnsignedInt($products[$i]['id_product_attribute']))
{
$attributes = self::getProductAttributeCombination($products[$i]['id_product_attribute'], $id_lang);
$products[$i]['attributes_small'] = '';
if ($attributes)
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)
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();
$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);
foreach ($customers as $customer)
{
if ($customer['id_customer'])
{
$customer = new Customer((int)$customer['id_customer']);
$customer_email = $customer->email;
$customer_id = (int)$customer->id;
}
else
{
$customer_id = 0;
$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/');
self::deleteAlert((int)$customer_id, strval($customer_email), (int)$id_product, (int)$id_product_attribute);
}
}
/*
* Generate correctly the address for an email
*/
public static function getFormatedAddress(Address $address, $line_sep, $fields_style = array())
{
return AddressFormat::generateAddress($address, array('avoid' => array()), $line_sep, ' ', $fields_style);
}
/*
* Get products according to alerts
*/
public static function getProducts($customer, $id_lang, Shop $shop)
{
$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`
WHERE p.`active` = 1
AND (ma.`id_customer` = '.(int)$customer->id.'
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);
}
/*
* Get product combinations
*/
public static function getProductAttributeCombination($id_product_attribute, $id_lang)
{
$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`)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
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);
}
/*
* Get customers waiting for alert on the specified product/product attribute
*/
public static function getCustomers($id_product, $id_product_attribute)
{
$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);
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
<module>
<name>mailalerts</name>
<displayName><![CDATA[Mail alerts]]></displayName>
<version><![CDATA[2.2]]></version>
<version><![CDATA[2.3]]></version>
<description><![CDATA[Sends e-mail notifications to customers and merchants.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
+14 -16
View File
@@ -2,12 +2,20 @@
global $_MODULE;
$_MODULE = array();
$_MODULE['<{mailalerts}prestashop>mailalerts-account_d95cf4ab2cbf1dfb63f066b50558b07d'] = 'Mon compte';
$_MODULE['<{mailalerts}prestashop>mailalerts-account_4edfd10d0bb5f51e0fd2327df608b5a8'] = 'Mes alertes';
$_MODULE['<{mailalerts}prestashop>mailalerts-account_deb10517653c255364175796ace3553f'] = 'Produit';
$_MODULE['<{mailalerts}prestashop>mailalerts-account_f2a6c498fb90ee345d997f888fce3b18'] = 'Supprimer';
$_MODULE['<{mailalerts}prestashop>mailalerts-account_074c07016d3e5a9f011aa8e62abe4517'] = 'Vous n\'êtes inscris à aucune alerte.';
$_MODULE['<{mailalerts}prestashop>mailalerts-account_0b3db27bc15f682e92ff250ebb167d4b'] = 'Retour à votre compte';
$_MODULE['<{mailalerts}prestashop>mailalerts-account_8cf04a9734132302f96da8e113e80ce5'] = 'Accueil';
$_MODULE['<{mailalerts}prestashop>mailalerts-account_8bb23c2ae698681ebb650f43acb54dab'] = 'Aucune alerte mail.';
$_MODULE['<{mailalerts}prestashop>mailalerts_fd30254803e8db32521d3390131a44da'] = 'Alertes email';
$_MODULE['<{mailalerts}prestashop>mailalerts_2d51f4a7ab8a12c4f35b507019523b8c'] = 'Envoie des notifications par e-mail aux clients et aux marchands.';
$_MODULE['<{mailalerts}prestashop>mailalerts_8fd3b84964bd6dfec8095f658d200b29'] = 'Etes-vous sûr de vouloir supprimer toutes les notifications clients ?';
$_MODULE['<{mailalerts}prestashop>mailalerts_7cb9a154f101c674c945f88dad5c5e28'] = 'Aucun message';
$_MODULE['<{mailalerts}prestashop>mailalerts_9137796c15dd92e5553c3f29574d0968'] = 'Code de réduction :';
$_MODULE['<{mailalerts}prestashop>mailalerts_4c9120f1a5947445c0e9620254ceb30b'] = 'Nouvelle commande';
$_MODULE['<{mailalerts}prestashop>mailalerts_c1ee76f076a5b97e3b4b0c0e5703246e'] = 'Mise à jour des réglages impossible';
$_MODULE['<{mailalerts}prestashop>mailalerts_ce241f25e003bafeb9fce6857d8f027f'] = 'Merci d\'entrer une (ou plusieurs) addresse(s) email';
$_MODULE['<{mailalerts}prestashop>mailalerts_29aae9c646337554f4de7ae29050c39f'] = 'E-mail invalide : ';
$_MODULE['<{mailalerts}prestashop>mailalerts_7a608706e248c21437882f5d1a8ece3a'] = 'Notification client';
$_MODULE['<{mailalerts}prestashop>mailalerts_ea379dd90c33c1345f40aa0afa6688d8'] = 'Disponibilité du produit';
$_MODULE['<{mailalerts}prestashop>mailalerts_86e8d61297942b00e9937299735df971'] = 'Donne au client la possibilité de recevoir une notification lorsqu\'un produit hors-stock est de nouveau disponible';
@@ -22,20 +30,10 @@ $_MODULE['<{mailalerts}prestashop>mailalerts_65d0578157fd293e96f55f2d9228c07b']
$_MODULE['<{mailalerts}prestashop>mailalerts_4cf0e54bd20f173efae53b6b4d3d8d9a'] = 'Envoyer aux adresses e-mail suivantes :';
$_MODULE['<{mailalerts}prestashop>mailalerts_8c5b6fe38a32f46c355f025a820c804c'] = 'Une adresse email par ligne';
$_MODULE['<{mailalerts}prestashop>mailalerts_f77ed609e48d550f0166dfbafc102710'] = 'ex :';
$_MODULE['<{mailalerts}prestashop>mailalerts_c1ee76f076a5b97e3b4b0c0e5703246e'] = 'Mise à jour des réglages impossible';
$_MODULE['<{mailalerts}prestashop>mailalerts_f4d1ea475eaa85102e2b4e6d95da84bd'] = 'Confirmation';
$_MODULE['<{mailalerts}prestashop>mailalerts_c888438d14855d7d96a2724ee9c306bd'] = 'Configuration mise à jour';
$_MODULE['<{mailalerts}prestashop>mailalerts_ce241f25e003bafeb9fce6857d8f027f'] = 'Merci d\'entrer une (ou plusieurs) addresse(s) email';
$_MODULE['<{mailalerts}prestashop>mailalerts_29aae9c646337554f4de7ae29050c39f'] = 'E-mail invalide : ';
$_MODULE['<{mailalerts}prestashop>mailalerts_7cb9a154f101c674c945f88dad5c5e28'] = 'Aucun message';
$_MODULE['<{mailalerts}prestashop>mailalerts_9137796c15dd92e5553c3f29574d0968'] = 'Code de réduction :';
$_MODULE['<{mailalerts}prestashop>mailalerts_4c9120f1a5947445c0e9620254ceb30b'] = 'Nouvelle commande';
$_MODULE['<{mailalerts}prestashop>my-account_4edfd10d0bb5f51e0fd2327df608b5a8'] = 'Mes alertes';
$_MODULE['<{mailalerts}prestashop>my-account_abca7cba75e5a9ff86b1490f32891f82'] = 'alertes';
$_MODULE['<{mailalerts}prestashop>myalerts_d95cf4ab2cbf1dfb63f066b50558b07d'] = 'Mon compte';
$_MODULE['<{mailalerts}prestashop>myalerts_4edfd10d0bb5f51e0fd2327df608b5a8'] = 'Mes alertes';
$_MODULE['<{mailalerts}prestashop>myalerts_deb10517653c255364175796ace3553f'] = 'Produit';
$_MODULE['<{mailalerts}prestashop>myalerts_f2a6c498fb90ee345d997f888fce3b18'] = 'Supprimer';
$_MODULE['<{mailalerts}prestashop>myalerts_074c07016d3e5a9f011aa8e62abe4517'] = 'Vous n\'avez souscrit à aucune alerte.';
$_MODULE['<{mailalerts}prestashop>myalerts_0b3db27bc15f682e92ff250ebb167d4b'] = 'Retour à votre compte';
$_MODULE['<{mailalerts}prestashop>myalerts_8cf04a9734132302f96da8e113e80ce5'] = 'Accueil';
$_MODULE['<{mailalerts}prestashop>product_67135a14d3ac4f1369633dd006d6efec'] = 'votre@email.com';
$_MODULE['<{mailalerts}prestashop>product_61172eb93737ebf095d3fa02119ce1df'] = 'Demande de notification enregistrée';
$_MODULE['<{mailalerts}prestashop>product_900f8551b29793ecb604a545b2059cc1'] = 'Votre adresse e-mail est invalide';
Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -20,7 +20,7 @@
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @version Release: $Revision: 12432 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
@@ -34,24 +34,24 @@ include_once(dirname(__FILE__).'/mailalerts.php');
$errors = array();
if (Context::getContext()->customer->isLogged())
if ($cookie->isLogged())
{
if (Tools::getValue('action') == 'delete')
{
$id_customer = (int)(Context::getContext()->customer->id);
$id_customer = (int)($cookie->id_customer);
if (!$id_product = (int)(Tools::getValue('id_product')))
$errors[] = Tools::displayError('You must have a product to delete an alert.');
$id_product_attribute = (int)(Tools::getValue('id_product_attribute'));
$customer = new Customer((int)($id_customer));
MailAlerts::deleteAlert((int)($id_customer), 0, (int)($id_product), (int)($id_product_attribute));
MailAlerts::deleteAlert((int)($id_customer), strval($customer->email), (int)($id_product), (int)($id_product_attribute));
}
$smarty->assign('alerts', MailAlerts::getProductsAlerts(Context::getContext()->customer->id, (int)Context::getContext()->language->id));
$this->context->smarty->assign('mailAlerts', MailAlert::getProductsAlerts((int)($cookie->id_customer), (int)($cookie->id_lang)));
}
else
$errors[] = Tools::displayError('You must be logged in to manage your alerts.');
$smarty->assign(array(
'id_customer' => (int)(Context::getContext()->customer->id),
$this->context->smarty->assign(array(
'id_customer' => (int)($cookie->id_customer),
'errors' => $errors
));
@@ -19,13 +19,14 @@
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7310 $
* @version Release: $Revision: 8084 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
{*
<div id="myalerts">
{capture name=path}<a href="{$link->getPageLink('my-account', true)}">{l s='My account' mod='mailalerts'}</a><span class="navigation-pipe">{$navigationPipe}</span>{l s='My alerts' mod='mailalerts'}{/capture}
{capture name=path}<a href="{$link->getPageLink('my-account.php', true)}">{l s='My account' mod='mailalerts'}</a><span class="navigation-pipe">{$navigationPipe}</span>{l s='My alerts' mod='mailalerts'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}
<h2>{l s='My alerts' mod='mailalerts'}</h2>
@@ -33,7 +34,7 @@
{include file="$tpl_dir./errors.tpl"}
{if $id_customer|intval neq 0}
{if $alerts}
{if $mailAlerts}
<div id="block-history" class="block-center">
<table class="std">
<thead>
@@ -43,7 +44,7 @@
</tr>
</thead>
<tbody>
{foreach from=$alerts item=product name=i}
{foreach from=$mailAlerts item=product name=i}
<tr>
<td class="first_item">
<span style="float:left;"><a href="{$product.link|escape:'htmlall':'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.cover, 'small')}" alt="{$product.name|escape:'htmlall':'UTF-8'}" /></a></span>
@@ -67,7 +68,65 @@
{/if}
<ul class="footer_links">
<li><a href="{$link->getPageLink('my-account', true)}"><img src="{$img_dir}icon/my-account.gif" alt="" class="icon" /></a><a href="{$link->getPageLink('my-account', true)}">{l s='Back to Your Account' mod='mailalerts'}</a></li>
<li><a href="{$link->getPageLink('my-account.php', true)}"><img src="{$img_dir}icon/my-account.gif" alt="" class="icon" /></a><a href="{$link->getPageLink('my-account.php', true)}">{l s='Back to Your Account' mod='mailalerts'}</a></li>
<li><a href="{$base_dir}"><img src="{$img_dir}icon/home.gif" alt="" class="icon" /></a><a href="{$base_dir}">{l s='Home' mod='mailalerts'}</a></li>
</ul>
</div>
</div>*}
<script type="text/javascript">
$('document').ready(function()
{
$('img[rel^=ajax_id_mailalert_]').click(function()
{
var idMailAlert = $(this).attr('rel').replace('ajax_id_mailalert_', '');
var parent = $(this).parent().parent();
$.ajax({
url: "{$link->getModuleLink('mailalerts', 'remove')}",
type: "POST",
data: {
'id_product': idMailAlert
},
success: function(result)
{
if (result == '0')
{
parent.fadeOut("normal", function()
{
parent.remove();
});
}
}
});
});
});
</script>
{capture name=path}<a href="{$link->getPageLink('my-account.php', true)}">{l s='My account' mod='mailalerts'}</a><span class="navigation-pipe">{$navigationPipe}</span>{l s='My alerts' mod='mailalerts'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}
<div id="mailalerts_block_account">
<h2>{l s='My alerts' mod='mailalerts'}</h2>
{if $mailAlerts}
<div>
{foreach from=$mailAlerts item=mailAlert}
<div class="mailalert clearfix">
<a href="{$link->getProductLink($mailAlert.id_product, null, null, null, null, $mailAlert.id_shop)}" class="product_img_link"><img src="{$link->getImageLink($mailAlert.link_rewrite, $mailAlert.cover, 'small')}" alt=""/></a>
<h3><a href="{$link->getProductLink($mailAlert.id_product, null, null, null, null, $mailAlert.id_shop)}">{$mailAlert.name}</a></h3>
<div class="product_desc">{$mailAlert.attributes_small|escape:'htmlall':'UTF-8'}</div>
<div class="remove">
<img rel="ajax_id_mailalert_{$mailAlert.id_product}" src="{$img_dir}icon/delete.gif" alt="" class="icon" />
</div>
</div>
{/foreach}
</div>
{else}
<p class="warning">{l s='No mail alerts yet.' mod='mailalerts'}</p>
{/if}
<ul class="footer_links">
<li class="fleft"><a href="{$link->getPageLink('my-account.php', true)}"><img src="{$img_dir}icon/my-account.gif" alt="" class="icon" /></a><a href="{$link->getPageLink('my-account.php', true)}">{l s='Back to Your Account' mod='mailalerts'}</a></li>
</ul>
</div>
@@ -20,25 +20,14 @@
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @version Release: $Revision: 12437 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../init.php');
include(dirname(__FILE__).'/../../modules/mailalerts/mailalerts.php');
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
if (!Context::getContext()->customer->isLogged())
die('0');
$id_customer = (int)(Context::getContext()->customer->id);
if (!$id_product = (int)(Tools::getValue('id_product')))
die ('0');
$id_product_attribute = (int)(Tools::getValue('id_product_attribute'));
$mA = new MailAlerts();
if ($mA->customerHasNotification((int)($id_customer), (int)($id_product), (int)($id_product_attribute)))
die ('1');
die('0');
@@ -1,67 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
if (!$id_product = (int)(Tools::getValue('id_product')))
die ('0');
$id_product_attribute = (int)(Tools::getValue('id_product_attribute'));
if (!Context::getContext()->customer->isLogged())
{
$customer_email = trim(Tools::getValue('customer_email'));
if (empty($customer_email) OR !Validate::isEmail($customer_email))
die ('0');
if ($customer_email == 'your@email.com')
die ('0');
$id_customer = (int)Db::getInstance()->getValue('SELECT id_customer FROM '._DB_PREFIX_.'customer WHERE email=\''.pSQL($customer_email).'\' AND is_guest=0');
// Check if already in DB
if (Db::getInstance()->executeS('
SELECT *
FROM `'._DB_PREFIX_.'mailalert_customer_oos`
WHERE `id_customer` = '.(int)($id_customer).'
AND `customer_email` = \''.pSQL($customer_email).'\'
AND `id_product` = '.(int)($id_product).'
AND `id_product_attribute` = '.(int)($id_product_attribute)))
die('1');
}
else
{
$id_customer = (int)Context::getContext()->customer->id;
$customer_email = 0;
}
if (Db::getInstance()->execute('
REPLACE INTO `'._DB_PREFIX_.'mailalert_customer_oos` (`id_customer`, `customer_email`, `id_product` , `id_product_attribute`)
VALUES ('.(int)($id_customer).', \''.pSQL($customer_email).'\', '.(int)($id_product).', '.(int)($id_product_attribute).')'))
die ('1');
die ('0');
+120
View File
@@ -0,0 +1,120 @@
{*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 11894 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<script type="text/javascript">
$('document').ready(function(){
$('#mailalerts_block_extra_add').click(function(){
$.ajax({
url: "{$link->getModuleLink('mailalerts', 'add')}",
type: "POST",
data: {
"id_product": {$smarty.get.id_product}
},
success: function(result){
if (result == '0')
{
$('#mailalerts_block_extra_add').slideUp(function() {
$('#mailalerts_block_extra_added').slideDown("slow");
});
}
}
});
});
$('#mailalerts_block_extra_remove').click(function(){
$.ajax({
url: "{$link->getModuleLink('mailalerts', 'remove')}",
type: "POST",
data: {
"id_product": {$smarty.get.id_product}
},
success: function(result){
if (result == '0')
{
$('#mailalerts_block_extra_remove').slideUp(function() {
$('#mailalerts_block_extra_removed').slideDown("slow");
});
}
}
});
});
$('#mailalerts_block_extra_added').click(function(){
$.ajax({
url: "{$link->getModuleLink('mailalerts', 'remove')}",
type: "POST",
data: {
"id_product": {$smarty.get.id_product}
},
success: function(result){
if (result == '0')
{
$('#mailalerts_block_extra_added').slideUp(function() {
$('#mailalerts_block_extra_removed').slideDown("slow");
});
}
}
});
});
$('#mailalerts_block_extra_removed').click(function(){
$.ajax({
url: "{$link->getModuleLink('mailalerts', 'add')}",
type: "POST",
data: {
"id_product": {$smarty.get.id_product}
},
success: function(result){
if (result == '0')
{
$('#mailalerts_block_extra_removed').slideUp(function() {
$('#mailalerts_block_extra_added').slideDown("slow");
});
}
}
});
});
})
</script>
{if !$isCustomerMailAlert AND $isLogged}
<li id="mailalerts_block_extra_add" class="add">
{l s='Add this product to my favorites' mod='mailalerts'}
</li>
{/if}
{if $isCustomerMailAlert AND $isLogged}
<li id="mailalerts_block_extra_remove">
{l s='Remove this product from my favorites' mod='mailalerts'}
</li>
{/if}
<li id="mailalerts_block_extra_added">
{l s='Remove this product from my favorites' mod='mailalerts'}
</li>
<li id="mailalerts_block_extra_removed">
{l s='Add this product to my favorites' mod='mailalerts'}
</li>
+47
View File
@@ -0,0 +1,47 @@
#module-mailalerts-mailalerts-account #left_column {display:none}
#module-mailalerts-mailalerts-account #center_column {width:757px}
#mailalerts_block_account .mailalert {
position:relative;
margin-bottom: 14px;
padding: 12px 8px;
border: 1px solid #eee;
border-radius: 3px 3px 3px 3px;
}
.mailalert a.product_img_link {
border: 1px solid #CCCCCC;
display: block;
float: left;
margin-right: 14px;
overflow: hidden;
position: relative;
}
.mailalert h3 {
color: #000000;
font-size: 13px;
padding: 0 0 10px;
}
.mailalert p.product_desc {
line-height: 16px;
overflow: hidden;
padding: 0;
}
.mailalert .remove {
position:absolute;
top:10px;
right:10px
}
.mailalert .remove .icon {cursor:pointer}
/* lnk fiche produit */
#usefull_link_block li#mailalerts_block_extra_remove {
padding-left:20px;
background:url(img/del_alert.gif) no-repeat 0 0;
cursor: pointer;
}
+235 -360
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -20,18 +20,19 @@
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7310 $
* @version Release: $Revision: 12460 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
if (!defined('_CAN_LOAD_FILES_'))
exit;
include_once(dirname(__FILE__).'/MailAlert.php');
class MailAlerts extends Module
{
private $_html = '';
private $_postErrors = array();
private $_merchant_mails;
private $_merchant_order;
@@ -44,30 +45,40 @@ class MailAlerts extends Module
{
$this->name = 'mailalerts';
$this->tab = 'administration';
$this->version = '2.2';
$this->version = '2.3';
$this->author = 'PrestaShop';
parent::__construct();
if ($this->id)
$this->_refreshProperties();
$this->init();
$this->displayName = $this->l('Mail alerts');
$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'));
$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');
}
public function install()
{
if (!parent::install() OR
!$this->registerHook('newOrder') OR
!$this->registerHook('updateQuantity') OR
!$this->registerHook('productOutOfStock') OR
!$this->registerHook('customerAccount') OR
!$this->registerHook('updateProduct') OR
!$this->registerHook('deleteProduct') OR
!$this->registerHook('deleteProductAttribute') OR
!$this->registerHook('updateProductAttribute')
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')
)
return false;
@@ -75,21 +86,20 @@ class MailAlerts extends Module
Configuration::updateValue('MA_MERCHANT_OOS', 1);
Configuration::updateValue('MA_CUSTOMER_QTY', 1);
Configuration::updateValue('MA_MERCHANT_MAILS', Configuration::get('PS_SHOP_EMAIL'));
Configuration::updateValue('MA_LAST_QTIES', Configuration::get('PS_LAST_QTIES'));
Configuration::updateValue('MA_LAST_QTIES', (int)Configuration::get('PS_LAST_QTIES'));
if (!Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'mailalert_customer_oos` (
$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')
)
return false;
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
if (!Db::getInstance()->Execute($sql))
return false;
/* This hook is optional */
$this->registerHook('myAccountBlock');
return true;
}
@@ -100,44 +110,148 @@ class MailAlerts extends Module
Configuration::deleteByName('MA_CUSTOMER_QTY');
Configuration::deleteByName('MA_MERCHANT_MAILS');
Configuration::deleteByName('MA_LAST_QTIES');
if (!Db::getInstance()->execute('DROP TABLE '._DB_PREFIX_.'mailalert_customer_oos'))
return false;
if (!Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.MailAlert::$definition['table']))
return false;
return parent::uninstall();
}
private function _refreshProperties()
public function getContent()
{
$this->_merchant_mails = Configuration::get('MA_MERCHANT_MAILS');
$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->_postProcess();
$this->_html = '<h2>'.$this->displayName.'</h2>';
$this->_html .= $this->_displayForm();
return $this->_html;
}
public function hookNewOrder($params)
private function _postProcess()
{
$errors = array();
if (Tools::isSubmit('submitMACustomer'))
{
if (!Configuration::updateValue('MA_CUSTOMER_QTY', (int)Tools::getValue('mA_customer_qty')))
$errors[] = $this->l('Cannot update settings');
}
else if (Tools::isSubmit('submitMAMerchant'))
{
$emails = strval(Tools::getValue('ma_merchant_mails'));
if (!$emails || empty($emails))
$errors[] = $this->l('Please type one (or more) e-mail address');
else
{
$emails = explode("\n", $emails);
foreach ($emails as $k => $email)
{
$email = trim($email);
if (!empty($email) && !Validate::isEmail($email))
{
$errors[] = $this->l('Invalid e-mail:').' '.$email;
break;
}
else if (!empty($email) && sizeof($email))
$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')))
$errors[] = $this->l('Cannot update settings');
elseif (!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')))
$errors[] = $this->l('Cannot update settings');
}
}
if (sizeof($errors))
echo $this->displayError(implode('<br />', $errors));
$this->init();
}
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>
<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' : '').'>
&nbsp;<label for="mA_customer_qty" class="t">'.$this->l('Gives the customer the option of receiving a notification for an available product if this one is out of stock.').'</label>
</div>
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitMACustomer" class="button" />
</div>
</fieldset>
</form>
<br />
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
<fieldset><legend><img src="'.$this->_path.'logo.gif" />'.$this->l('Merchant notification').'</legend>
<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>
</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>
</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" />
<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>
<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>
</div>
<div style="float:left;">
'.$this->l('One e-mail address per line').'<br />
'.$this->l('e.g.,').' bob@example.com
</div>
</div>
<div style="clear:both;">&nbsp;</div>
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitMAMerchant" class="button" />
</div>
</fieldset>
</form>';
}
public function hookActionValidateOrder($params)
{
if (!$this->_merchant_order OR empty($this->_merchant_mails))
return;
// Getting differents vars
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$id_lang = (int)Context::getContext()->language->id;
$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'];
$customer = $params['customer'];
$delivery = new Address((int)($order->id_address_delivery));
$invoice = new Address((int)($order->id_address_invoice));
$order_date_text = Tools::displayDate($order->date_add, (int)($id_lang));
$carrier = new Carrier((int)($order->id_carrier));
$delivery = new Address((int)$order->id_address_delivery);
$invoice = new Address((int)$order->id_address_invoice);
$order_date_text = Tools::displayDate($order->date_add, (int)$id_lang);
$carrier = new Carrier((int)$order->id_carrier);
$message = $order->getFirstMessage();
if (!$message OR empty($message))
if (!$message || empty($message))
$message = $this->l('No message');
$itemsTable = '';
$products = $params['order']->getProducts();
$customizedDatas = Product::getAllCustomizedDatas(intval($params['cart']->id));
$customizedDatas = Product::getAllCustomizedDatas((int)$params['cart']->id);
Product::addCustomizationPrice($products, $customizedDatas);
foreach ($products AS $key => $product)
foreach ($products as $key => $product)
{
$unit_price = $product['product_price_wt'];
$price = $product['total_price'];
@@ -148,12 +262,12 @@ class MailAlerts extends Module
foreach ($customizedDatas[$product['product_id']][$product['product_attribute_id']] AS $customization)
{
if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD]))
foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] AS $text)
if (isset($customization['datas'][_CUSTOMIZE_TEXTFIELD_]))
foreach ($customization['datas'][_CUSTOMIZE_TEXTFIELD_] as $text)
$customizationText .= $text['name'].':'.' '.$text['value'].'<br />';
if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
$customizationText .= sizeof($customization['datas'][Product::CUSTOMIZE_FILE]) .' '. Tools::displayError('image(s)').'<br />';
if (isset($customization['datas'][_CUSTOMIZE_FILE_]))
$customizationText .= sizeof($customization['datas'][_CUSTOMIZE_FILE_]) .' '. Tools::displayError('image(s)').'<br />';
$customizationText .= '---<br />';
}
@@ -170,34 +284,32 @@ class MailAlerts extends Module
<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)
foreach ($params['order']->getCartRules() as $discount)
{
$itemsTable .=
'<tr style="background-color:#EBECEE;">
<td colspan="4" style="padding:0.6em 0.4em; text-align:right;">'.$this->l('Voucher code:').' '.$discount['code'].'</td>
<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>
</tr>';
}
if ($delivery->id_state)
$delivery_state = new State((int)($delivery->id_state));
$delivery_state = new State((int)$delivery->id_state);
if ($invoice->id_state)
$invoice_state = new State((int)($invoice->id_state));
$invoice_state = new State((int)$invoice->id_state);
// Filling-in vars for email
$template = 'new_order';
$subject = $this->l('New order', (int)$id_lang).' - '.sprintf('%06d', $order->id);
$subject = $this->l('New order', $id_lang).' - '.sprintf('%06d', $order->id);
$templateVars = array(
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{email}' => $customer->email,
'{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"),
'{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"),
'{delivery_block_html}' => $this->_getFormatedAddress($delivery, "<br />",
array(
'{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"),
'{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"),
'{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}' => $this->_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,
@@ -236,346 +348,109 @@ class MailAlerts extends Module
'{currency}' => $currency->sign,
'{message}' => $message
);
$iso = Language::getIsoById((int)($id_lang));
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.txt') AND file_exists(dirname(__FILE__).'/mails/'.$iso.'/'.$template.'.html'))
Mail::Send((int)$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/');
$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/');
}
/*
** Generate correctly the address for an email
*/
private function _getFormatedAddress(Address $the_address, $line_sep, $fields_style = array())
{
return AddressFormat::generateAddress($the_address, array('avoid' => array()), $line_sep, ' ', $fields_style);
}
public function hookProductOutOfStock($params)
public function hookActionProductOutOfStock($params)
{
if (!$this->_customer_qty)
return ;
$id_product = (int)($params['product']->id);
$id_product_attribute = 0;
$id_product = (int)$params['product']->id;
$id_customer = (int)Context::getContext()->customer->id;
if (!$this->context->customer->isLogged())
$this->smarty->assign('email', 1);
else
{
$id_customer = (int)($params['cookie']->id_customer);
if ($this->customerHasNotification($id_customer, $id_product, $id_product_attribute))
return ;
}
$this->smarty->assign(array(
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute));
if (!(int)Context::getContext()->customer->isLogged())
$this->context->smarty->assign('email', 1);
else if (MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute))
return ;
$this->context->smarty->assign(array(
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute));
return $this->display(__FILE__, 'product.tpl');
}
public function customerHasNotification($id_customer, $id_product, $id_product_attribute)
public function hookActionUpdateQuantity($params)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'._DB_PREFIX_.'mailalert_customer_oos`
WHERE `id_customer` = '.(int)($id_customer).'
AND `id_product` = '.(int)($id_product).'
AND `id_product_attribute` = '.(int)($id_product_attribute));
return sizeof($result);
}
$product = $params['product'];
$id_shop = (int)Context::getContext()->shop->id;
$id_lang = (int)Context::getContext()->language->id;
public function hookUpdateQuantity($params)
{
if (is_object($params['product']))
$params['product'] = get_object_vars($params['product']);
if (is_array($params['product']['name']))
$params['product']['name'] = $params['product']['name'][(int)Configuration::get('PS_LANG_DEFAULT')];
if (isset($params['product']['id_product']))
$params['product']['id'] = (int)$params['product']['id_product'];
$qty = (int)$params['product']['quantity'];
if ($qty <= (int)(Configuration::get('MA_LAST_QTIES')) AND !(!$this->_merchant_oos OR empty($this->_merchant_mails)) AND Configuration::get('PS_STOCK_MANAGEMENT'))
if ((int)$product->quantity <= (int)Configuration::get('MA_LAST_QTIES') &&
!(!$this->_merchant_oos || empty($this->_merchant_mails)) && StockAvailable::dependsOnStock($product->id))
{
$templateVars = array(
'{qty}' => $qty,
'{last_qty}' => (int)(Configuration::get('MA_LAST_QTIES')),
'{product}' => strval($params['product']['name']).(isset($params['product']['attributes_small']) ? ' '.$params['product']['attributes_small'] : ''));
$iso = $this->context->language->iso_code;
if ($params['product']['active'] == 1)
{
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.txt') AND file_exists(dirname(__FILE__).'/mails/'.$iso.'/productoutofstock.html'))
Mail::Send((int)Configuration::get('PS_LANG_DEFAULT'), 'productoutofstock', Mail::l('Product out of stock', (int)Configuration::get('PS_LANG_DEFAULT')), $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/');
$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 AND $params['product']['quantity'] > 0)
$this->sendCustomerAlert((int)$params['product']['id'], 0);
if ($this->_customer_qty && $product->quantity > 0)
MailAlert::sendCustomerAlert((int)$product->id, (int)$params['attribute_id']);
}
public function hookUpdateProduct($params)
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 AND $params['product']->getStock() > 0)
$this->sendCustomerAlert((int)$params['product']->id, 0);
if ($this->_customer_qty && $product->quantity > 0)
MailAlert::sendCustomerAlert((int)$params['product']->id, 0);
}
public function hookUpdateProductAttribute($params)
public function hookActionProductAttributeUpdate($params)
{
$sql = 'SELECT id_product, quantity
FROM '._DB_PREFIX_.'stock_available
WHERE id_product_attribute = '.(int)$params['id_product_attribute']
.StockAvailable::addSqlShopRestriction();
$sql = 'SELECT `id_product`, `quantity`
FROM `'._DB_PREFIX_.'stock_available`
WHERE `id_product_attribute` = '.(int)$params['id_product_attribute'];
$result = Db::getInstance()->getRow($sql);
if ($this->_customer_qty AND $result['quantity'] > 0)
$this->sendCustomerAlert((int)$result['id_product'], (int)$params['id_product_attribute']);
if ($this->_customer_qty && $result['quantity'] > 0)
MailAlert::sendCustomerAlert((int)$result['id_product'], (int)$params['id_product_attribute']);
}
public function sendCustomerAlert($id_product, $id_product_attribute)
{
$customers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT id_customer, customer_email
FROM `'._DB_PREFIX_.'mailalert_customer_oos`
WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute);
$product = new Product((int)$id_product, false, $this->context->language->id);
$templateVars = array(
'{product}' => (is_array($product->name) ? $product->name[(int)Configuration::get('PS_LANG_DEFAULT')] : $product->name),
'{product_link}' => $this->context->link->getProductLink($product)
);
foreach ($customers AS $cust)
{
if ($cust['id_customer'])
{
$customer = new Customer((int)$cust['id_customer']);
$customer_email = $customer->email;
$customer_id = (int)$customer->id;
}
else
{
$customer_email = $cust['customer_email'];
$customer_id = 0;
}
$iso = $this->context->language->iso_code;
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.txt') AND file_exists(dirname(__FILE__).'/mails/'.$iso.'/customer_qty.html'))
Mail::Send((int)Configuration::get('PS_LANG_DEFAULT'), 'customer_qty', Mail::l('Product available', (int)Configuration::get('PS_LANG_DEFAULT')), $templateVars, strval($customer_email), NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/');
if ($customer_id)
$customer_email = 0;
self::deleteAlert((int)$customer_id, strval($customer_email), (int)$id_product, (int)$id_product_attribute);
}
}
public function hookCustomerAccount($params)
public function hookDisplayCustomerAccount($params)
{
return $this->_customer_qty ? $this->display(__FILE__, 'my-account.tpl') : NULL;
}
public function hookMyAccountBlock($params)
public function hookDisplayMyAccountBlock($params)
{
return $this->hookCustomerAccount($params);
return $this->hookDisplayCustomerAccount($params);
}
public function getContent()
public function hookActionProductDelete($params)
{
$this->_html = '<h2>'.$this->displayName.'</h2>';
$this->_postProcess();
$this->_displayForm();
return $this->_html;
$sql = 'DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
WHERE `id_product` = '.(int)$params['product']->id;
Db::getInstance()->Execute($sql);
}
private function _displayForm()
{
$tab = Tools::getValue('tab');
$token = Tools::getValue('token');
$this->_html .= '
<form action="'.AdminController::$currentIndex.'&token='.$token.'&configure=mailalerts" method="post">
<fieldset class="width3"><legend><img src="'.$this->_path.'logo.gif" />'.$this->l('Customer notification').'</legend>
<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' : '').'>
&nbsp;<label for="mA_customer_qty" class="t">'.$this->l('Gives the customer the option of receiving a notification for an available product if this one is out of stock.').'</label>
</div>
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitMACustomer" class="button" />
</div>
</fieldset>
</form>
<br />
<form action="'.AdminController::$currentIndex.'&token='.$token.'&configure=mailalerts" method="post">
<fieldset class="width3"><legend><img src="'.$this->_path.'logo.gif" />'.$this->l('Merchant notification').'</legend>
<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>
</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>
</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" />
<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>
<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>
</div>
<div style="float:left;">
'.$this->l('One e-mail address per line').'<br />
'.$this->l('e.g.,').' bob@example.com
</div>
</div>
<div style="clear:both;">&nbsp;</div>
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitMAMerchant" class="button" />
</div>
</fieldset>
</form>';
}
private function _postProcess()
{
if (Tools::isSubmit('submitMACustomer'))
{
if (!Configuration::updateValue('MA_CUSTOMER_QTY', (int)(Tools::getValue('mA_customer_qty'))))
$this->_html .= '<div class="alert error">'.$this->l('Cannot update settings').'</div>';
else
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
}
elseif (Tools::isSubmit('submitMAMerchant'))
{
$emails = strval(Tools::getValue('ma_merchant_mails'));
if (!$emails OR empty($emails))
$this->_html .= '<div class="alert error">'.$this->l('Please type one (or more) e-mail address').'</div>';
else
{
$emails = explode("\n", $emails);
foreach ($emails AS $k => $email)
{
$email = trim($email);
if (!empty($email) AND !Validate::isEmail($email))
return ($this->_html .= '<div class="alert error">'.$this->l('Invalid e-mail:').' '.$email.'</div>');
if (!empty($email) AND sizeof($email))
$emails[$k] = $email;
else
unset($emails[$k]);
}
$emails = implode(self::__MA_MAIL_DELIMITOR__, $emails);
if (!Configuration::updateValue('MA_MERCHANT_MAILS', strval($emails)))
$this->_html .= '<div class="alert error">'.$this->l('Cannot update settings').'</div>';
elseif (!Configuration::updateValue('MA_MERCHANT_ORDER', (int)(Tools::getValue('mA_merchand_order'))))
$this->_html .= '<div class="alert error">'.$this->l('Cannot update settings').'</div>';
elseif (!Configuration::updateValue('MA_MERCHANT_OOS', (int)(Tools::getValue('mA_merchand_oos'))))
$this->_html .= '<div class="alert error">'.$this->l('Cannot update settings').'</div>';
elseif (!Configuration::updateValue('MA_LAST_QTIES', (int)(Tools::getValue('MA_LAST_QTIES'))))
$this->_html .= '<div class="alert error">'.$this->l('Cannot update settings').'</div>';
else
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
}
}
$this->_refreshProperties();
}
public static function getProductsAlerts($id_customer, $id_lang)
{
if (!Validate::isUnsignedId($id_customer) OR
!Validate::isUnsignedId($id_lang)
)
die (Tools::displayError());
$sql = 'SELECT ma.`id_product`, IFNULL(stock.quantity, 0) as product_quantity, pl.`name`, ma.`id_product_attribute`
FROM `'._DB_PREFIX_.'mailalert_customer_oos` 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` AND pl.`id_lang` = '.$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('pl').'
'.Product::sqlStock('p', 0).'
WHERE p.`active` = 1
ma.`id_customer` = '.$id_customer;
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if (empty($products) === true OR !sizeof($products))
return array();
for ($i = 0; $i < sizeof($products); ++$i)
{
$obj = new Product($products[$i]['id_product'], false, (int)($id_lang));
if (!Validate::isLoadedObject($obj))
continue;
if (isset($products[$i]['id_product_attribute']) AND
Validate::isUnsignedInt($products[$i]['id_product_attribute']))
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
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`)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pac.`id_product_attribute` = pa.`id_product_attribute`)
WHERE pac.`id_product_attribute` = '.(int)($products[$i]['id_product_attribute']));
$products[$i]['attributes_small'] = '';
if ($result)
foreach ($result AS $k => $row)
$products[$i]['attributes_small'] .= $row['attribute_name'].', ';
$products[$i]['attributes_small'] = rtrim($products[$i]['attributes_small'], ', ');
// cover
$attrgrps = $obj->getAttributesGroups($id_lang);
foreach ($attrgrps AS $attrgrp)
if ($attrgrp['id_product_attribute'] == $products[$i]['id_product_attribute'] AND $images = Product::_getAttributeImageAssociations((int)($attrgrp['id_product_attribute'])))
{
$products[$i]['cover'] = $obj->id.'-'.array_pop($images);
break;
}
}
if (!isset($products[$i]['cover']) OR !$products[$i]['cover'])
{
$images = $obj->getImages($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 deleteAlert($id_customer, $customer_email, $id_product, $id_product_attribute)
{
return Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'mailalert_customer_oos`
WHERE `id_customer` = '.(int)($id_customer).'
AND `customer_email` = \''.pSQL($customer_email).'\'
AND `id_product` = '.(int)($id_product).'
AND `id_product_attribute` = '.(int)($id_product_attribute));
}
public function hookDeleteProduct($params)
{
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'mailalert_customer_oos` WHERE `id_product` = '.(int)$params['product']->id);
}
public function hookDeleteProductAttribute($params)
public function hookActionAttributeDelete($params)
{
if ($params['deleteAllAttributes'])
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'mailalert_customer_oos`
WHERE `id_product` = '.(int)$params['id_product']);
$sql = 'DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
WHERE `id_product` = '.(int)$params['id_product'];
else
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'mailalert_customer_oos`
WHERE `id_product_attribute` = '.(int)$params['id_product_attribute'].'
AND `id_product` = '.(int)$params['id_product']);
$sql = 'DELETE FROM `'._DB_PREFIX_.MailAlert::$definition['table'].'`
WHERE `id_product_attribute` = '.(int)$params['id_product_attribute'].'
AND `id_product` = '.(int)$params['id_product'];
Db::getInstance()->Execute($sql);
}
public function hookDisplayHeader($params)
{
$this->context->controller->addCSS($this->_path.'mailalerts.css', 'all');
}
}
+160
View File
@@ -0,0 +1,160 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 11894 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class ModulemailalertsController extends ModuleController
{
/**
* @var int
*/
public $id_product;
public function init()
{
parent::init();
require_once(dirname(__FILE__).'/MailAlert.php');
$this->id_product = (int)Tools::getValue('id_product');
}
public function postProcess()
{
if ($this->process == 'remove')
$this->processRemove();
else if ($this->process == 'add')
$this->processAdd();
else if ($this->process == 'check')
$this->processCheck();
}
/**
* Remove a favorite product
*/
public function processRemove()
{
// check if product exists
$product = new Product($this->id_product);
if (!Validate::isLoadedObject($product))
die('0');
$mailAlert = MailAlert::getMailAlert((int)Context::getContext()->customer->id, (int)$product->id);
if ($mailAlert && $mailAlert->delete())
die('0');
die(1);
}
/**
* Add a favorite product
*/
public function processAdd()
{
if (Context::getContext()->customer->isLogged())
{
$id_customer = (int)Context::getContext()->customer->id;
$customer = new Customer($id_customer);
$customer_email = strval($customer->email);
}
else
{
$customer_email = strval(Tools::getValue('customer_email'));
$customer = Context::getContext()->customer->getByEmail($customer_email);
$id_customer = (isset($customer->id) && ($customer->id != null)) ? (int)$customer->id : null;
}
$id_product = (int)Tools::getValue('id_product');
$id_product_attribute = (int)Tools::getValue('id_product_attribute');
$id_shop = (int)Context::getContext()->shop->id;
$product = new Product($id_product, null, null, $id_shop, Context::getContext());
$mailAlert = MailAlert::customerHasNotification($id_customer, $id_product, $id_product_attribute, $id_shop);
if ($mailAlert)
die('2');
else if (!Validate::isLoadedObject($product))
die('0');
$mailAlert = new MailAlert();
$mailAlert->id_customer = (int)$id_customer;
$mailAlert->customer_email = strval($customer_email);
$mailAlert->id_product = (int)$id_product;
$mailAlert->id_product_attribute = (int)$id_product_attribute;
$mailAlert->id_shop = (int)$id_shop;
if ($mailAlert->add() !== false)
die('1');
die('0');
}
/**
* Add a favorite product
*/
public function processCheck()
{
if (!(int)$this->context->customer->logged)
die('0');
$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))
die ('1');
die('0');
}
public function initContent()
{
parent::initContent();
if ($this->process == 'account')
$this->assignAccount();
}
/**
* Prepare account page
*/
public function assignAccount()
{
if (!Context::getContext()->customer->isLogged())
Tools::redirect('index.php?controller=auth&redirect=module&module=mailalerts&action=account');
if (Context::getContext()->customer->id)
{
$this->context->smarty->assign('id_customer', Context::getContext()->customer->id);
$this->context->smarty->assign('mailAlerts', MailAlert::getMailAlerts((int)Context::getContext()->customer->id, (int)Context::getContext()->language->id));
$this->setTemplate('mailalerts-account.tpl');
}
}
}
+6 -6
View File
@@ -19,14 +19,14 @@
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @version Release: $Revision: 11894 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
<!-- MODULE MailAlerts -->
<li>
<a href="{$base_dir_ssl}modules/mailalerts/myalerts.php" title="{l s='My alerts' mod='mailalerts'}"><img src="{$module_template_dir}logo.gif" alt="{l s='alerts' mod='mailalerts'}" class="icon" /></a>
<a href="{$base_dir_ssl}modules/mailalerts/myalerts.php" title="{l s='My alerts' mod='mailalerts'}">{l s='My alerts' mod='mailalerts'}</a>
<li class="mailalerts">
<a href="{$link->getModuleLink('mailalerts', 'account')}" title="{l s='My alerts' mod='mailalerts'}">
<img src="{$module_template_dir}img/icon-alert.png" class="icon" />
{l s='My alerts' mod='mailalerts'}
</a>
</li>
<!-- END : MODULE MailAlerts -->
+7 -4
View File
@@ -19,7 +19,7 @@
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 6844 $
* @version Release: $Revision: 8234 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}
@@ -35,7 +35,7 @@ function clearText() {
function oosHookJsCodeMailAlert() {
$.ajax({
type: 'POST',
url: '{/literal}{$base_dir}{literal}modules/mailalerts/mailalerts-ajax_check.php',
url: "{/literal}{$link->getModuleLink('mailalerts', 'check')}{literal}",
data: 'id_product={/literal}{$id_product}{literal}&id_product_attribute='+$('#idCombination').val(),
success: function (msg) {
if (msg == '0') {
@@ -53,7 +53,7 @@ function oosHookJsCodeMailAlert() {
function addNotification() {
$.ajax({
type: 'POST',
url: '{/literal}{$base_dir}{literal}modules/mailalerts/mailalerts-ajax_add.php',
url: "{/literal}{$link->getModuleLink('mailalerts', 'add')}{literal}",
data: 'id_product={/literal}{$id_product}{literal}&id_product_attribute='+$('#idCombination').val()+'&customer_email='+$('#oos_customer_email').val()+'',
success: function (msg) {
if (msg == '1') {
@@ -62,7 +62,10 @@ function addNotification() {
$('#oos_customer_email_result').html("{/literal}{l s='Request notification registered' mod='mailalerts'}{literal}");
$('#oos_customer_email_result').css('color', 'green').show();
}
else {
else if (msg == '2' ) {
$('#oos_customer_email_result').html("{/literal}{l s='You already have an alert for this product' mod='mailalerts'}{literal}");
$('#oos_customer_email_result').css('color', 'red').show();
} else {
$('#oos_customer_email_result').html("{/literal}{l s='Your e-mail address is invalid' mod='mailalerts'}{literal}");
$('#oos_customer_email_result').css('color', 'red').show();
}