Manage several discount per order
This commit is contained in:
parent
d9f23e7f30
commit
c82df4b134
@ -88,14 +88,19 @@ class Ant_Refund_Discount extends Module
|
|||||||
// Discount
|
// Discount
|
||||||
$discountUse = $order->getDiscounts();
|
$discountUse = $order->getDiscounts();
|
||||||
if (count($discountUse) > 0) {
|
if (count($discountUse) > 0) {
|
||||||
|
$num = 0;
|
||||||
foreach($discountUse as $d) {
|
foreach($discountUse as $d) {
|
||||||
$this->copyDiscountAfterRefund($order, $d);
|
// If several discount on the order
|
||||||
|
if (count($discountUse) > 0) {
|
||||||
|
$num++;
|
||||||
|
}
|
||||||
|
$this->copyDiscountAfterRefund($order, $d, $num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', 'FIN', FILE_APPEND);
|
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', 'FIN', FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function copyDiscountAfterRefund($order, $discount)
|
protected function copyDiscountAfterRefund($order, $discount, $num = 0)
|
||||||
{
|
{
|
||||||
$languages = Language::getLanguages();
|
$languages = Language::getLanguages();
|
||||||
|
|
||||||
@ -103,6 +108,11 @@ class Ant_Refund_Discount extends Module
|
|||||||
|
|
||||||
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', print_r($item, 1), FILE_APPEND);
|
if ($this->debuglog) file_put_contents(_PS_ROOT_DIR_.'/log/ant_refund_discount.log', print_r($item, 1), FILE_APPEND);
|
||||||
|
|
||||||
|
$nameNew = (int)($order->id);
|
||||||
|
if ($num > 0) {
|
||||||
|
$nameNew .= '-'.$num;
|
||||||
|
}
|
||||||
|
|
||||||
// Re Create discount
|
// Re Create discount
|
||||||
$voucher = new Discount();
|
$voucher = new Discount();
|
||||||
$voucher->id_discount_type = $item->id_discount_type;
|
$voucher->id_discount_type = $item->id_discount_type;
|
||||||
@ -110,7 +120,7 @@ class Ant_Refund_Discount extends Module
|
|||||||
$voucher->description[$language['id_lang']] = $item->description[$language['id_lang']];
|
$voucher->description[$language['id_lang']] = $item->description[$language['id_lang']];
|
||||||
}
|
}
|
||||||
$voucher->value = (float) $item->value;
|
$voucher->value = (float) $item->value;
|
||||||
$voucher->name = 'R-'.(int)($order->id);
|
$voucher->name = 'R-'.$nameNew;
|
||||||
$voucher->id_customer = (int)($order->id_customer);
|
$voucher->id_customer = (int)($order->id_customer);
|
||||||
$voucher->id_currency = (int)($order->id_currency);
|
$voucher->id_currency = (int)($order->id_currency);
|
||||||
$voucher->quantity = 1;
|
$voucher->quantity = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user