[*] MO : SendToAFriend - 1.5 Supported / Pop-in instead of form

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8288 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone
2011-08-31 15:33:06 +00:00
parent 25ac858966
commit 9aab069851
9 changed files with 323 additions and 220 deletions
+29 -81
View File
@@ -30,110 +30,58 @@ if (!defined('_PS_VERSION_'))
class sendToAFriend extends Module
{
private $_html = '';
private $_postErrors = array();
function __construct($dontTranslate = false)
{
$this->name = 'sendtoafriend';
$this->version = '1.1';
$this->version = '1.2';
$this->author = 'PrestaShop';
$this->tab = 'front_office_features';
$this->need_instance = 0;
$this->secure_key = Tools::encrypt($this->name);
parent::__construct();
if(!$dontTranslate)
{
$this->displayName = $this->l('Send to a Friend module');
$this->description = $this->l('Allows customers to send a product link to a friend.');
}
$this->displayName = $this->l('Send to a Friend module');
$this->description = $this->l('Allows customers to send a product link to a friend.');
}
}
function install()
public function install()
{
return (parent::install() AND $this->registerHook('extraLeft'));
return (parent::install() AND $this->registerHook('extraLeft')
AND $this->registerHook('header'));
}
function hookExtraLeft($params)
public function uninstall()
{
$this->context->smarty->assign('this_path', $this->_path);
return $this->display(__FILE__, 'product_page.tpl');
return (parent::uninstall() AND $this->unregisterHook('header') AND $this->unregisterHook('extraLeft'));
}
public function displayPageForm()
public function hookExtraLeft($params)
{
if (!$this->active)
Tools::display404Error();
/* Product informations */
$product = new Product((int)Tools::getValue('id_product'), false, $this->context->language->id);
$productLink = $this->context->link->getProductLink($product);
$image = Product::getCover((int)($_GET['id_product']));
include(dirname(__FILE__).'/../../header.php');
echo $this->displayFrontForm();
include(dirname(__FILE__).'/../../footer.php');
}
public function displayFrontForm()
{
$error = false;
$confirm = false;
if (isset($_POST['submitAddtoafriend']))
{
/* Product informations */
$product = new Product((int)Tools::getValue('id_product'), false, $this->context->language->id);
$productLink = $this->context->link->getProductLink($product);
/* Fields verifications */
if (empty($_POST['email']) OR empty($_POST['name']))
$error = $this->l('You must fill in all fields.');
elseif (empty($_POST['email']) OR !Validate::isEmail($_POST['email']))
$error = $this->l('The e-mail given is invalid.');
elseif (!Validate::isName($_POST['name']))
$error = $this->l('The name given is invalid.');
elseif (!isset($_GET['id_product']) OR !is_numeric($_GET['id_product']))
$error = $this->l('An error occurred during the process.');
else
{
/* Email generation */
$subject = ($cookie->customer_firstname ? $cookie->customer_firstname.' '.$cookie->customer_lastname : $this->l('A friend')).' '.$this->l('sent you a link to').' '.$product->name;
$templateVars = array(
'{product}' => $product->name,
'{product_link}' => $productLink,
'{customer}' => ($cookie->customer_firstname ? $cookie->customer_firstname.' '.$cookie->customer_lastname : $this->l('A friend')),
'{name}' => Tools::safeOutput($_POST['name'])
);
/* Email sending */
if (!Mail::Send((int)$cookie->id_lang, 'send_to_a_friend', Mail::l('A friend sent you a link to').' '.$product->name, $templateVars, $_POST['email'], NULL, ($cookie->email ? $cookie->email : NULL), ($cookie->customer_firstname ? $cookie->customer_firstname.' '.$cookie->customer_lastname : NULL), NULL, NULL, dirname(__FILE__).'/mails/'))
$error = $this->l('An error occurred during the process.');
else
Tools::redirect(_MODULE_DIR_.'/'.$this->name.'/sendtoafriend-form.php?id_product='.(int)$product->id.'&submited');
}
}
else
{
/* Product informations */
$product = new Product((int)Tools::getValue('id_product'), false, $this->context->language->id);
$productLink = $this->context->link->getProductLink($product);
}
/* Image */
$images = $product->getImages((int)$cookie->id_lang);
foreach ($images AS $k => $image)
if ($image['cover'])
{
$cover['id_image'] = (int)$product->id.'-'.(int)$image['id_image'];
$cover['legend'] = $image['legend'];
}
if (!isset($cover))
$cover = array('id_image' => $this->context->language->iso_code.'-default', 'legend' => 'No picture');
$this->context->smarty->assign(array(
'cover' => $cover,
'errors' => $error,
'confirm' => $confirm,
'product' => $product,
'productLink' => $productLink
Context::getContext()->smarty->assign(array(
'stf_id_product' => (int)Tools::getValue('id_product'),
'stf_product_link' => $productLink,
'stf_product_cover' => (int)Tools::getValue('id_product').'-'.(int)$image['id_image'],
'stf_secure_key' => $this->secure_key,
));
return $this->display(__FILE__, 'sendtoafriend.tpl');
return $this->display(__FILE__, 'sendtoafriend-extra.tpl');
}
}
public function hookHeader($params)
{
$this->context->controller->addCSS($this->_path.'sendtoafriend.css', 'all');
}
}