privilegedemarque/modules/advsendtoafriend/sendtoafriend_ajax.php
Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

98 lines
3.6 KiB
PHP
Executable File

<?php
/*
* 2007-2014 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-2014 PrestaShop SA
* @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__).'/advsendtoafriend.php');
include_once(dirname(__FILE__).'/../../classes/Product.php');
include_once(dirname(__FILE__).'/../privatesales/models/SaleCore.php');
$module = new AdvSendToAFriend();
if (Tools::getValue('action') == 'sendToMyFriend' && Tools::getValue('secure_key') == $module->secure_key)
{
// Retrocompatibilty with old theme
$friendName = Tools::getValue('name');
$friendMail = Tools::getValue('email');
$id_product = Tools::getValue('id_product');
$id_sale = Tools::getValue('id_sale');
if (!$friendName || !$friendMail || (!$id_product && !$id_sale) )
die(Tools::jsonEncode(0));
/* Email generation */
if ( $id_product ){
// Send dproduct
$product = new Product((int)$id_product, false, $module->context->language->id);
$title = $product->name;
$link = $module->context->link->getProductLink($product);
$mail_tpl = 'send_to_a_friend';
$templateVars = array(
'{product}' => $title,
'{product_link}' => $link
);
$objetMail = Mail::l('J\'aime beaucoup ce produit, et toi, qu\'en penses-tu?', (int)$module->context->cookie->id_lang);
}
else{
// Send sale
$sale = new SaleCore((int)$id_sale, $module->context->language->id);
$title = $sale->title;
$link = $module->context->link->getCategoryLink(new Category((int)$sale->id_category), null, (int)$module->context->cookie->id_lang);
$mail_tpl = 'send_to_a_friend_sale';
$templateVars = array(
'{sale}' => $title,
'{sale_link}' => $link,
'{sale_img}' => $sale->getFileImage('current', (int)$module->context->cookie->id_lang, false)
);
$objetMail = Mail::l('J\'ai beaucoup aimé cette vente, qu\'en penses-tu?', (int)$module->context->cookie->id_lang);
}
$customer = $module->context->cookie->customer_firstname ? $module->context->cookie->customer_firstname.' '.$module->context->cookie->customer_lastname : $module->l('A friend', 'sendtoafriend_ajax');
$templateVars['{customer}'] = $customer;
$templateVars['{name}'] = Tools::safeOutput($friendName);
/* Email sending */
if (false === Mail::Send((int)$module->context->cookie->id_lang,
$mail_tpl,
$objetMail,
$templateVars, $friendMail,
null,
($module->context->cookie->email ? $module->context->cookie->email : null),
($module->context->cookie->customer_firstname ? $module->context->cookie->customer_firstname.' '.$module->context->cookie->customer_lastname : null),
null,
null,
dirname(__FILE__).'/mails/'))
die(Tools::jsonEncode($ret));
die(Tools::jsonEncode(1));
}
die(Tools::jsonEncode(0));