Merge branch 'ticket/r15319-multi-voucher'

This commit is contained in:
Michael RICOIS 2018-01-15 10:18:00 +01:00
commit 9afceeca10

View File

@ -88,14 +88,19 @@ class Ant_Refund_Discount extends Module
// Discount
$discountUse = $order->getDiscounts();
if (count($discountUse) > 0) {
$num = 0;
foreach($discountUse as $d) {
$this->copyDiscountAfterRefund($order, $d);
// If several discount on the order
if (count($discountUse) > 1) {
$num++;
}
$this->copyDiscountAfterRefund($order, $d, $num);
}
}
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();
@ -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);
$nameNew = (int)($order->id);
if ($num > 0) {
$nameNew .= '-'.$num;
}
// Re Create discount
$voucher = new Discount();
$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->value = (float) $item->value;
$voucher->name = 'R-'.(int)($order->id);
$voucher->name = 'R-'.$nameNew;
$voucher->id_customer = (int)($order->id_customer);
$voucher->id_currency = (int)($order->id_currency);
$voucher->quantity = 1;