New voucher after refund
This commit is contained in:
parent
c261d04612
commit
facd10a417
134
modules/ant_refund_discount/ant_refund_discount.php
Normal file
134
modules/ant_refund_discount/ant_refund_discount.php
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('_PS_VERSION_')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Ant_Refund_Discount extends Module
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->name = 'ant_refund_discount';
|
||||||
|
$this->tab = 'administration';
|
||||||
|
$this->author = 'Antadis';
|
||||||
|
$this->version = '1.0';
|
||||||
|
$this->need_instance = 0;
|
||||||
|
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->displayName = $this->l('Refund discount');
|
||||||
|
$this->description = $this->l('Re-create discount when an order is refund');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function install()
|
||||||
|
{
|
||||||
|
// Register hooks
|
||||||
|
if(!(parent::install() && $this->registerHook('orderSlip'))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function hookOrderSlip($params)
|
||||||
|
{
|
||||||
|
$orderParams = $params['order'];
|
||||||
|
$productList = $params['productList'];
|
||||||
|
$qtyList = $params['qtyList'];
|
||||||
|
|
||||||
|
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', 'Discount : '.$orderParams->total_discounts."\n");
|
||||||
|
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', print_r($params, 1), FILE_APPEND);
|
||||||
|
|
||||||
|
// If we have no discount
|
||||||
|
if ($orderParams->total_discounts == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Product qty
|
||||||
|
$order = new Order($orderParams->id);
|
||||||
|
$orderProducts = $order->getProductsDetail();
|
||||||
|
|
||||||
|
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', count($orderProducts).' != '.count($productList)."\n", FILE_APPEND);
|
||||||
|
|
||||||
|
// Check product line difference
|
||||||
|
if (count($orderProducts) != count($productList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', print_r($orderProducts, 1), FILE_APPEND);
|
||||||
|
|
||||||
|
// Check product quantity
|
||||||
|
foreach ($orderProducts as $p) {
|
||||||
|
if ($p['product_quantity'] != $qtyList[$p['id_order_detail']]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Discount
|
||||||
|
$discountUse = $order->getDiscounts();
|
||||||
|
if (count($discountUse) > 0) {
|
||||||
|
foreach($discountUse as $d) {
|
||||||
|
$this->copyDiscountAfterRefund($order, $d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', 'FIN', FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function copyDiscountAfterRefund($order, $discount)
|
||||||
|
{
|
||||||
|
$languages = Language::getLanguages();
|
||||||
|
|
||||||
|
$item = new Discount($discount['id_discount']);
|
||||||
|
|
||||||
|
file_put_contents(_PS_ROOT_DIR_.'/log/debug.log', print_r($item, 1), FILE_APPEND);
|
||||||
|
|
||||||
|
// Re Create discount
|
||||||
|
$voucher = new Discount();
|
||||||
|
$voucher->id_discount_type = $item->id_discount_type;
|
||||||
|
foreach ($languages as $language) {
|
||||||
|
$voucher->description[$language['id_lang']] = $item->description[$language['id_lang']];
|
||||||
|
}
|
||||||
|
$voucher->value = (float) $item->value;
|
||||||
|
|
||||||
|
// @todo : Change name
|
||||||
|
$voucher->name = 'V0C'.(int)($order->id_customer).'O'.(int)($order->id);
|
||||||
|
|
||||||
|
$voucher->id_customer = (int)($order->id_customer);
|
||||||
|
$voucher->id_currency = (int)($order->id_currency);
|
||||||
|
$voucher->quantity = 1;
|
||||||
|
$voucher->quantity_per_user = 1;
|
||||||
|
$voucher->cumulable = $item->cumulable;
|
||||||
|
$voucher->cumulable_reduction = $item->cumulable_reduction;
|
||||||
|
$voucher->minimal = (float) $voucher->value;
|
||||||
|
$voucher->active = 1;
|
||||||
|
$voucher->cart_display = $item->cart_display;
|
||||||
|
|
||||||
|
$now = time();
|
||||||
|
$start = new DateTime($item->date_from);
|
||||||
|
$end = new DateTime($item->date_to);
|
||||||
|
$interval = $start->diff($end);
|
||||||
|
$voucher->date_from = date('Y-m-d H:i:s', $now);
|
||||||
|
$voucher->date_to = date('Y-m-d H:i:s', $now + $interval);
|
||||||
|
|
||||||
|
if (!$voucher->validateFieldsLang(false) OR !$voucher->add()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ok discount created, send mail
|
||||||
|
$customer = new Customer($order->id_customer);
|
||||||
|
|
||||||
|
// Vars
|
||||||
|
$params = array(
|
||||||
|
'{firstname}' => $customer->firstname,
|
||||||
|
'{lastname}' => $customer->lastname,
|
||||||
|
'{voucher_num}' => $voucher->name,
|
||||||
|
);
|
||||||
|
|
||||||
|
Mail::Send((int)$order->id_lang, 'voucher_after_refund', Mail::l('New voucher after refund', $order->id_lang),
|
||||||
|
$params, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null, null,
|
||||||
|
_PS_MAIL_DIR_, true);
|
||||||
|
|
||||||
|
return $voucher;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
36
modules/ant_refund_discount/index.php
Executable file
36
modules/ant_refund_discount/index.php
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 2007-2011 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Open Software License (OSL 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/osl-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: 7233 $
|
||||||
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||||
|
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||||
|
|
||||||
|
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||||
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||||
|
header("Pragma: no-cache");
|
||||||
|
|
||||||
|
header("Location: ../");
|
||||||
|
exit;
|
@ -0,0 +1,40 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>Message de {shop_name}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table style="font-family: tahoma,arial,sans-serif; font-size: 12px; color:#000000; width: 550px;">
|
||||||
|
<tr>
|
||||||
|
<td align="left">
|
||||||
|
<a href="{shop_url}" title="{shop_name}"><img alt="{shop_name}" src="{shop_logo}" style="border:none;" ></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">Bonjour <strong>{firstname} {lastname}</strong>,</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">
|
||||||
|
Nous venons de procéder au remboursement de votre commande. Vous aviez utilisé, au moment de passer votre commande, un bon de réduction.
|
||||||
|
<br>Nous vous informons qu'un nouveau bon de réduction vous a été attribué {voucher_num}.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">
|
||||||
|
Cordialement,<br />
|
||||||
|
Le service client
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="font-size: 12px; border-top: 1px solid #cccccc; padding-top: 5px;">
|
||||||
|
{shop_name} - <a href="{shop_url}" style="color: #e26ea2;">{shop_url}</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,7 @@
|
|||||||
|
Bonjour {firstname} {lastname},
|
||||||
|
|
||||||
|
Nous venons de procéder au remboursement de votre commande. Vous aviez utilisé, au moment de passer votre commande, un bon de réduction.
|
||||||
|
Nous vous informons qu'un nouveau bon de réduction vous a été attribué {voucher_num}.
|
||||||
|
|
||||||
|
Cordialement,
|
||||||
|
Le service client
|
@ -0,0 +1,40 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>Message de {shop_name}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table style="font-family: tahoma,arial,sans-serif; font-size: 12px; color:#000000; width: 550px;">
|
||||||
|
<tr>
|
||||||
|
<td align="left">
|
||||||
|
<a href="{shop_url}" title="{shop_name}"><img alt="{shop_name}" src="{shop_logo}" style="border:none;" ></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">Bonjour <strong>{firstname} {lastname}</strong>,</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">
|
||||||
|
Nous venons de procéder au remboursement de votre commande. Vous aviez utilisé, au moment de passer votre commande, un bon de réduction.
|
||||||
|
<br>Nous vous informons qu'un nouveau bon de réduction vous a été attribué {voucher_num}.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">
|
||||||
|
Cordialement,<br />
|
||||||
|
Le service client
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="font-size: 12px; border-top: 1px solid #cccccc; padding-top: 5px;">
|
||||||
|
{shop_name} - <a href="{shop_url}" style="color: #e26ea2;">{shop_url}</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,7 @@
|
|||||||
|
Bonjour {firstname} {lastname},
|
||||||
|
|
||||||
|
Nous venons de procéder au remboursement de votre commande. Vous aviez utilisé, au moment de passer votre commande, un bon de réduction.
|
||||||
|
Nous vous informons qu'un nouveau bon de réduction vous a été attribué {voucher_num}.
|
||||||
|
|
||||||
|
Cordialement,
|
||||||
|
Le service client
|
40
modules/ant_refund_discount/mails/fr/voucher_after_refund.html
Executable file
40
modules/ant_refund_discount/mails/fr/voucher_after_refund.html
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>Message de {shop_name}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table style="font-family: tahoma,arial,sans-serif; font-size: 12px; color: #000000; width: 550px;">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td align="left"><a title="{shop_name}" href="{shop_url}"><img style="border: none;" src="{shop_logo}" alt="{shop_name}" /></a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">Bonjour <strong>{firstname} {lastname}</strong>,</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">Nous venons de procéder au remboursement de votre commande. Vous aviez utilisé, au moment de passer votre commande, un bon de réduction. <br />Nous vous informons qu'un nouveau bon de réduction vous a été attribué {voucher_num}.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="left">Cordialement,<br /> Le service client</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="font-size: 12px; border-top: 1px solid #cccccc; padding-top: 5px;" align="center">{shop_name} - <a style="color: #e26ea2;" href="{shop_url}">{shop_url}</a></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
7
modules/ant_refund_discount/mails/fr/voucher_after_refund.txt
Executable file
7
modules/ant_refund_discount/mails/fr/voucher_after_refund.txt
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
Bonjour {firstname} {lastname},
|
||||||
|
|
||||||
|
Nous venons de procéder au remboursement de votre commande. Vous aviez utilisé, au moment de passer votre commande, un bon de réduction.
|
||||||
|
Nous vous informons qu'un nouveau bon de réduction vous a été attribué {voucher_num}.
|
||||||
|
|
||||||
|
Cordialement,
|
||||||
|
Le service client
|
Loading…
Reference in New Issue
Block a user