From 9aab069851355ba47130a29a4f22c84f99bbbe7d Mon Sep 17 00:00:00 2001 From: bMancone Date: Wed, 31 Aug 2011 15:33:06 +0000 Subject: [PATCH] [*] 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 --- modules/sendtoafriend/config.xml | 2 +- modules/sendtoafriend/fr.php | 24 ++-- modules/sendtoafriend/product_page.tpl | 27 ----- modules/sendtoafriend/sendtoafriend-extra.tpl | 104 +++++++++++++++++ modules/sendtoafriend/sendtoafriend-form.php | 33 ------ modules/sendtoafriend/sendtoafriend.css | 99 ++++++++++++++++ modules/sendtoafriend/sendtoafriend.php | 110 +++++------------- modules/sendtoafriend/sendtoafriend.tpl | 64 ---------- modules/sendtoafriend/sendtoafriend_ajax.php | 80 +++++++++++++ 9 files changed, 323 insertions(+), 220 deletions(-) delete mode 100644 modules/sendtoafriend/product_page.tpl create mode 100644 modules/sendtoafriend/sendtoafriend-extra.tpl delete mode 100644 modules/sendtoafriend/sendtoafriend-form.php create mode 100644 modules/sendtoafriend/sendtoafriend.css delete mode 100644 modules/sendtoafriend/sendtoafriend.tpl create mode 100644 modules/sendtoafriend/sendtoafriend_ajax.php diff --git a/modules/sendtoafriend/config.xml b/modules/sendtoafriend/config.xml index e74dd4f73..fef8ca0a7 100755 --- a/modules/sendtoafriend/config.xml +++ b/modules/sendtoafriend/config.xml @@ -2,7 +2,7 @@ sendtoafriend - + diff --git a/modules/sendtoafriend/fr.php b/modules/sendtoafriend/fr.php index 7bcd79a91..fe5dce21d 100644 --- a/modules/sendtoafriend/fr.php +++ b/modules/sendtoafriend/fr.php @@ -2,19 +2,15 @@ global $_MODULE; $_MODULE = array(); -$_MODULE['<{sendtoafriend}prestashop>product_page_2107f6398c37b4b9ee1e1b5afb5d3b2a'] = 'Envoyer à un ami'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend-extra_2107f6398c37b4b9ee1e1b5afb5d3b2a'] = 'Envoyer à un ami'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend-extra_5d6103b662f41b07e10687f03aca8fdc'] = 'Destinataire'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend-extra_bb6aa0be8236a10e6d3b315ebd5f2547'] = 'Nom de votre ami'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend-extra_099bc8914b5be9e522a29e48cb3c01c4'] = 'Adresse email de votre ami'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend-extra_ea4788705e6873b424c65e91c2846b19'] = 'Annuler'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend-extra_e81c4e4f2b7b93b481e13a8553c2ae1b'] = 'ou'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend-extra_94966d90747b97d1f0f206c98a8b1ac3'] = 'Envoyer'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend-extra_70397c4b252a5168c5ec003931cea215'] = 'Champs requis'; $_MODULE['<{sendtoafriend}prestashop>sendtoafriend_2074615eb70699e55b1f9289c6c77c25'] = 'Module envoyer à un ami'; $_MODULE['<{sendtoafriend}prestashop>sendtoafriend_3234e2609dd694d8763c390fe97eba04'] = 'Permet à vos clients d\'envoyer des liens à leurs amis'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_666f6333e43c215212b916fef3d94af0'] = 'Vous devez remplir tous les champs.'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_ed95f7e7c4691956e0d6f2cd0136d483'] = 'L\'email de votre ami est invalide.'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_0e2a8a9d9c363a1ed93e7822eb3fc0ca'] = 'Le nom de votre ami est invalide.'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_98db77c121d8acdba66ec89626ae896c'] = 'Une erreur est survenue durant le processus.'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_22c4733a9ceb239bf825a0cecd1cfaec'] = 'Un ami'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_ffa719e6b8863717a9e86579249c7d9b'] = 'vous a envoyé un lien pour'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_2107f6398c37b4b9ee1e1b5afb5d3b2a'] = 'Envoyer à un ami'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_20589174124c25654cac3736e737d2a3'] = 'Envoyer cette page à un ami susceptible d\'être intéressé par le produit ci-dessous'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_b31afdfa73c89b567778f15180c2dd6c'] = 'Votre email a bien été envoyé'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_19d305aea0ccec77d23362111ebdb6b4'] = 'Nom de votre ami :'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_7ae8a9a7a5d8fa40d4515fc52f16bb2e'] = 'Email de votre ami :'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_2541d938b0a58946090d7abdde0d3890'] = 'Envoyer'; -$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_68728c1897e5936032fe21ffb6b10c2e'] = 'Retour à la fiche produit'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_ajax_22c4733a9ceb239bf825a0cecd1cfaec'] = 'Un ami'; +$_MODULE['<{sendtoafriend}prestashop>sendtoafriend_ajax_ffa719e6b8863717a9e86579249c7d9b'] = 'vous à envoyé un lien vers'; diff --git a/modules/sendtoafriend/product_page.tpl b/modules/sendtoafriend/product_page.tpl deleted file mode 100644 index b0912a22b..000000000 --- a/modules/sendtoafriend/product_page.tpl +++ /dev/null @@ -1,27 +0,0 @@ -{* -* 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 -* @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 -*} - -
  • {l s='Send to a friend' mod='sendtoafriend'}
  • diff --git a/modules/sendtoafriend/sendtoafriend-extra.tpl b/modules/sendtoafriend/sendtoafriend-extra.tpl new file mode 100644 index 000000000..700ea9a16 --- /dev/null +++ b/modules/sendtoafriend/sendtoafriend-extra.tpl @@ -0,0 +1,104 @@ +{* +* 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 +* @copyright 2007-2011 PrestaShop SA +* @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 +*} + +
  • + {l s='Send to a friend' mod='sendtoafriend'} +
  • + +
    +
    +

    {l s='Send to a friend' mod='sendtoafriend'}

    +
    + {$product->name|escape:html:'UTF-8'} +
    +

    {$product->name}

    + {$product->description_short} +
    +
    + +
    +

    {l s='Recipient' mod='sendtoafriend'} :

    +
    +
    +

    + + +

    +

    + + +

    +

    +

    + + {l s='Cancel' mod='sendtoafriend'} {l s='or' mod='sendtoafriend'}  + +

    +

    * {l s='Required fields' mod='sendtoafriend'}

    +
    +
    +
    +
    \ No newline at end of file diff --git a/modules/sendtoafriend/sendtoafriend-form.php b/modules/sendtoafriend/sendtoafriend-form.php deleted file mode 100644 index 636ff180e..000000000 --- a/modules/sendtoafriend/sendtoafriend-form.php +++ /dev/null @@ -1,33 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7040 $ -* @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'); -require_once(dirname(__FILE__).'/sendtoafriend.php'); - -$sendtoafriend = new sendToAFriend($dontTranslate = true); -echo $sendtoafriend->displayPageForm(); - diff --git a/modules/sendtoafriend/sendtoafriend.css b/modules/sendtoafriend/sendtoafriend.css new file mode 100644 index 000000000..13bad9571 --- /dev/null +++ b/modules/sendtoafriend/sendtoafriend.css @@ -0,0 +1,99 @@ +#fancybox-wrap {width:585px !important} +#fancybox-content { + width:585px !important; + border-width:0 !important +} + +#send_friend_form { + width:585px; + color: #333; + text-align: left; + background-color: #fff +} +#send_friend_form .title { + padding:10px; + font-size: 13px; + color: #fff; + text-transform: uppercase; + background: #333 +} + +#send_friend_form .product {padding:15px} +#send_friend_form .product img { + float:left; + border: 1px solid #ccc; +} +#send_friend_form .product .product_desc { + float:left; + margin-left:15px; + width:300px; + line-height:18px; + color:#666 +} +#send_friend_form .product .product_desc .product_name { + padding-bottom:5px; + font-size:13px; + color:#000 +} + +.send_friend_form_content { + padding:15px; + background:#f8f8f8 +} +.send_friend_form_content .intro_form { + padding-bottom: 10px; + font-weight: bold; + font-size: 12px +} + + +#send_friend_form .form_container { + clear:both; + margin-top:20px +} +#send_friend_form p.text { + margin-bottom:0; + padding-bottom:0 +} +#send_friend_form p.text label, #send_friend_form p.textarea label { + display: block; + margin:12px 0 4px 0; + font-weight: bold; + font-size: 12px; +} +#send_friend_form p.text input { + padding: 0 5px; + height: 28px; + width: 540px; + border: 1px solid #ccc; + background: url(../img/bg_input.png) repeat-x scroll 0 0 #fff; +} + +#send_friend_form .submit { + padding:0; + font-size:13px; + text-align:right +} +#send_friend_form button { + cursor: pointer; + cursor: pointer; + display: inline-block; + padding: 4px 7px 3px 7px; + border: 1px solid #CC9900; + border-radius: 3px 3px 3px 3px; + font-weight: bold; + color: #000; + background: url(../img/bg_bt.gif) repeat-x scroll 0 0 #F4B61B +} +#send_friend_form .submit .txt_required { + float:left; + font-size:12px; + font-style:italic; + color:#666 +} +#send_friend_form_error { + color:red; + font-size:13px; + text-align:left; + display:hidden; +} \ No newline at end of file diff --git a/modules/sendtoafriend/sendtoafriend.php b/modules/sendtoafriend/sendtoafriend.php index 18b31f58c..2900c8c23 100644 --- a/modules/sendtoafriend/sendtoafriend.php +++ b/modules/sendtoafriend/sendtoafriend.php @@ -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'); + } +} \ No newline at end of file diff --git a/modules/sendtoafriend/sendtoafriend.tpl b/modules/sendtoafriend/sendtoafriend.tpl deleted file mode 100644 index 2392cd69b..000000000 --- a/modules/sendtoafriend/sendtoafriend.tpl +++ /dev/null @@ -1,64 +0,0 @@ -{* -* 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 -* @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 -*} - -{capture name=path}{l s='Send to a friend' mod='sendtoafriend'}{/capture} -{include file="$tpl_dir./breadcrumb.tpl"} - -

    {l s='Send to a friend' mod='sendtoafriend'}

    - -

    {l s='Send this page to a friend who might be interested in the item below.' mod='sendtoafriend'}.

    -{include file="$tpl_dir./errors.tpl"} - -{if isset($smarty.get.submited)} -

    {l s='Your email has been sent successfully' mod='sendtoafriend'}

    -{else} -
    -
    -

    -
    - {$product->name} -

    - -

    - - -

    -

    - - -

    - -

    - -

    -
    -
    -{/if} - - - diff --git a/modules/sendtoafriend/sendtoafriend_ajax.php b/modules/sendtoafriend/sendtoafriend_ajax.php new file mode 100644 index 000000000..d8f2b8a61 --- /dev/null +++ b/modules/sendtoafriend/sendtoafriend_ajax.php @@ -0,0 +1,80 @@ + +* @copyright 2007-2011 PrestaShop SA +* @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 +*/ + +require_once(dirname(__FILE__).'/../../config/config.inc.php'); +require_once(dirname(__FILE__).'/../../init.php'); +include_once(dirname(__FILE__).'/sendtoafriend.php'); +include_once(dirname(__FILE__).'/../../classes/Product.php'); + +$module = new SendToAFriend(); + +if (Tools::getValue('action') == 'sendToMyFriend' AND + Tools::getValue('secure_key') == $module->secure_key + AND Context::getContext()->cookie->id_customer) +{ + $friendInfos = Tools::jsonDecode(Tools::getValue('friend')); + $friendName = ""; + $friendMail = ""; + $id_product = null; + foreach ($friendInfos as $entry) + { + if ($entry->key == "friend_name") + $friendName = $entry->value; + elseif ($entry->key == "friend_email") + $friendMail = $entry->value; + elseif ($entry->key == "id_product") + $id_product = $entry->value; + } + if (!$friendName OR !$friendMail OR !$id_product) + die('0'); + + /* Email generation */ + $product = new Product((int)$id_product, false, Context::getContext()->language->id); + $productLink = Context::getContext()->link->getProductLink($product); + $subject = (Context::getContext()->cookie->customer_firstname ? Context::getContext()->cookie->customer_firstname.' '.Context::getContext()->cookie->customer_lastname : $module->l('A friend')).' '.$module->l('sent you a link to').' '.$product->name; + $templateVars = array( + '{product}' => $product->name, + '{product_link}' => $productLink, + '{customer}' => (Context::getContext()->cookie->customer_firstname ? Context::getContext()->cookie->customer_firstname.' '.Context::getContext()->cookie->customer_lastname : $module->l('A friend')), + '{name}' => Tools::safeOutput($friendName) + ); + + /* Email sending */ + if (!Mail::Send((int)Context::getContext()->cookie->id_lang, + 'send_to_a_friend', + Mail::l('A friend sent you a link to').' '.$product->name, + $templateVars, $friendMail, + NULL, + (Context::getContext()->cookie->email ? Context::getContext()->cookie->email : NULL), + (Context::getContext()->cookie->customer_firstname ? Context::getContext()->cookie->customer_firstname.' '.Context::getContext()->cookie->customer_lastname : NULL), + NULL, + NULL, + dirname(__FILE__).'/mails/')) + die('0'); + die('1'); +} +die('1');