Refund based on product_quantity_refunded and transaction

This commit is contained in:
Michael RICOIS 2018-01-04 14:49:08 +01:00
parent 06bf95e914
commit d4afb73dba

View File

@ -554,14 +554,32 @@ if($slipNb > 0) {
if ($optVerbose) {
echo date('Y-m-d H:i:s')." - Order slip with no detail"."\n";
}
$order_details = Db::getInstance()->ExecuteS('
SELECT d.*, p.`wholesale_price`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = d.`product_id`)
WHERE d.id_order='.(int) $slip['id_order']);
// In case details is not present, we suppose we have all products refund
foreach ($order_details as $k => $details) {
$order_details[$k]['product_quantity_refunded'] = $order_details[$k]['product_quantity'];
// Paybox refund
if (strtolower($order['payment']) == 'paybox') {
$refund_details = Db::getInstance()->executeS('
SELECT r.`id_order_detail`
FROM `'._DB_PREFIX_.'refund_transaction` r
WHERE r.`id_order` = '. (int) $slip['id_order']
);
$realrefund = array_values($refund_details);
// Clean order_details
foreach ($order_details as $k => $od) {
if (!in_array($od['id_order_detail'], $realrefund)) {
unset($order_details[$k]);
}
}
}
// No case, product mark refunded
else {
$order_details = Db::getInstance()->ExecuteS('
SELECT d.*, p.`wholesale_price`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = d.`product_id`)
WHERE d.`product_quantity_refunded` > 0 AND d.`id_order`='.(int) $slip['id_order']
);
foreach ($order_details as $k => $details) {
$order_details[$k]['product_quantity_refunded'] = $order_details[$k]['product_quantity'];
}
}
}