Merge branch 'ticket/r15319-multi-voucher' into develop

This commit is contained in:
Michael RICOIS 2018-01-08 17:08:07 +01:00
commit 2b4033a51d
2 changed files with 75 additions and 61 deletions

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;

View File

@ -33,7 +33,8 @@ class AdminLabelGenerate extends AdminTab
if (file_exists(_PS_MODULE_DIR_.'labelgenerate/img/rack/rack.pdf')) {
$this->displaySucess('Rack générés : <a class="btn btn-primary btn-xs" target="_blank" href="/modules/labelgenerate/img/rack/rack.pdf">Télécharger le PDF rack</a>');
}
} elseif ($current_sale && Tools::getValue('generateRef')) {
}
elseif ($current_sale && Tools::getValue('generateRef')) {
$sale = new Sale((int)$current_sale);
$big_label = Tools::getValue('big_label');
@ -96,7 +97,8 @@ class AdminLabelGenerate extends AdminTab
}
}
}
} elseif ($current_sale && Tools::getValue('deleteEAN')) {
}
elseif ($current_sale && Tools::getValue('deleteEAN')) {
$sale = new Sale((int)$current_sale);
if(!Validate::isLoadedObject($sale)) {
@ -160,7 +162,7 @@ class AdminLabelGenerate extends AdminTab
$barcode = new GenerateBarcode();
$barcode->id_sale = $sale->id;
$barcode->createFolder($barcode->id_sale);
$count = 0;
foreach ($products as $key => $id_product) {
$product = new Product($id_product, FALSE, (int) $cookie->id_lang);
$attributes = array();
@ -180,8 +182,7 @@ class AdminLabelGenerate extends AdminTab
foreach ($result_quantities as $od) {
$quantity += ((int)$od['product_quantity'] - (int)$od['product_quantity_reinjected']);
}
if($quantity>0){
$count++;
if ($quantity > 0){
if (empty($combination['ean13'])) {
$ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference);
Db::getInstance()->execute('
@ -214,7 +215,6 @@ class AdminLabelGenerate extends AdminTab
$quantity += ((int)$od['product_quantity'] - (int)$od['product_quantity_reinjected']);
}
if ($quantity > 0) {
$count++;
if (empty($product->ean13)) {
$ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference);
Db::getInstance()->execute('
@ -259,7 +259,7 @@ class AdminLabelGenerate extends AdminTab
$sale = new Sale((int)$current_sale);
$big_label = Tools::getValue('big_label');
if(!Validate::isLoadedObject($sale)) {
if (!Validate::isLoadedObject($sale)) {
throw new Exception('This sale doesnt exist');
} else {
$products = $sale->getProducts();
@ -382,64 +382,68 @@ class AdminLabelGenerate extends AdminTab
// Product with attributes
if ($combinations) {
foreach ($combinations as $key => $combination) {
$result_quantities = Db::getInstance()->executeS('
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`)
WHERE od.`product_id` = ' . (int)$combination['id_product'] .'
AND od.`product_attribute_id`= ' . (int)$combination['id_product_attribute'].'
AND o.`valid` != 0'
);
$quantity = 0;
foreach ($result_quantities as $od) {
$quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']);
}
if ($quantity > 0) {
$ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference);
$barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference);
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'product_attribute`
SET `ean13` = '. $ean_generate . '
WHERE `id_product` = ' . (int)$product->id .'
AND `id_product_attribute` = ' . (int)$combination['id_product_attribute']
);
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'order_detail`
SET `product_ean13` = "'. pSQL($ean_generate) .'"
WHERE `product_id` = '. (int)$product->id .'
AND `product_attribute_id` = '. (int)$combination['id_product_attribute']
if (empty($combination['ean13'])) {
$result_quantities = Db::getInstance()->executeS('
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`)
WHERE od.`product_id` = ' . (int)$combination['id_product'] .'
AND od.`product_attribute_id`= ' . (int)$combination['id_product_attribute'].'
AND o.`valid` != 0'
);
$quantity = 0;
foreach ($result_quantities as $od) {
$quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']);
}
if ($quantity > 0) {
$ean_generate = $barcode->generateBarcode($combination['id_product'], $combination['id_product_attribute'],$product->reference);
$barcode->assocProduct($combination['id_product'], $combination['id_product_attribute'], $quantity, $product->reference);
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'product_attribute`
SET `ean13` = '. $ean_generate . '
WHERE `id_product` = ' . (int)$product->id .'
AND `id_product_attribute` = ' . (int)$combination['id_product_attribute']
);
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'order_detail`
SET `product_ean13` = "'. pSQL($ean_generate) .'"
WHERE `product_id` = '. (int)$product->id .'
AND `product_attribute_id` = '. (int)$combination['id_product_attribute']
);
}
}
}
}
// Product without attributes
else {
$result_quantities = Db::getInstance()->executeS('
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`)
WHERE od.`product_id` = ' . (int)$product->id . ' AND `product_attribute_id` = 0 AND o.`valid` != 0'
);
$quantity = 0;
foreach ($result_quantities as $od) {
$quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']);
}
if ($quantity > 0) {
$ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference);
$barcode->assocProduct($product->id, NULL, $quantity, $product->reference);
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'product`
SET `ean13` = '. $ean_generate . '
WHERE `id_product` = ' . (int)$product->id
if (empty($product->ean13)) {
$result_quantities = Db::getInstance()->executeS('
SELECT od.`product_quantity`,od.`product_quantity_reinjected`
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'orders o ON (o.`id_order` = od.`id_order`)
WHERE od.`product_id` = ' . (int)$product->id . ' AND `product_attribute_id` = 0 AND o.`valid` != 0'
);
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'order_detail`
SET `product_ean13` = "'. pSQL($ean_generate) .'"
WHERE `product_id` = '. (int)$product->id .'
AND `product_attribute_id` = 0
');
$quantity = 0;
foreach ($result_quantities as $od) {
$quantity += ($od['product_quantity'] - $od['product_quantity_reinjected']);
}
if ($quantity > 0) {
$ean_generate = $barcode->generateBarcode($product->id, NULL, $product->reference);
$barcode->assocProduct($product->id, NULL, $quantity, $product->reference);
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'product`
SET `ean13` = '. $ean_generate . '
WHERE `id_product` = ' . (int)$product->id
);
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'order_detail`
SET `product_ean13` = "'. pSQL($ean_generate) .'"
WHERE `product_id` = '. (int)$product->id .'
AND `product_attribute_id` = 0
');
}
}
}
}