[-] Core: Fix #PSCFV-9652 too much payments for multishipping orders
This commit is contained in:
+10
-3
@@ -1146,13 +1146,14 @@ class OrderCore extends ObjectModel
|
|||||||
if ($use_existing_payment)
|
if ($use_existing_payment)
|
||||||
{
|
{
|
||||||
$id_order_payments = Db::getInstance()->executeS('
|
$id_order_payments = Db::getInstance()->executeS('
|
||||||
SELECT op.id_order_payment
|
SELECT DISTINCT op.id_order_payment
|
||||||
FROM `'._DB_PREFIX_.'order_payment` op
|
FROM `'._DB_PREFIX_.'order_payment` op
|
||||||
INNER JOIN `'._DB_PREFIX_.'orders` o ON (o.reference = op.order_reference)
|
INNER JOIN `'._DB_PREFIX_.'orders` o ON (o.reference = op.order_reference)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'order_invoice_payment` oip ON (oip.id_order_payment = op.id_order_payment)
|
LEFT JOIN `'._DB_PREFIX_.'order_invoice_payment` oip ON (oip.id_order_payment = op.id_order_payment)
|
||||||
WHERE oip.id_order_payment IS NULL AND o.id_order = '.(int)$order_invoice->id_order);
|
WHERE (oip.id_order != '.(int)$order_invoice->id_order.' OR oip.id_order IS NULL) AND o.id_order = '.(int)$order_invoice->id_order);
|
||||||
|
|
||||||
if (count($id_order_payments))
|
if (count($id_order_payments))
|
||||||
|
{
|
||||||
foreach ($id_order_payments as $order_payment)
|
foreach ($id_order_payments as $order_payment)
|
||||||
Db::getInstance()->execute('
|
Db::getInstance()->execute('
|
||||||
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
|
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
|
||||||
@@ -1160,6 +1161,9 @@ class OrderCore extends ObjectModel
|
|||||||
`id_order_invoice` = '.(int)$order_invoice->id.',
|
`id_order_invoice` = '.(int)$order_invoice->id.',
|
||||||
`id_order_payment` = '.(int)$order_payment['id_order_payment'].',
|
`id_order_payment` = '.(int)$order_payment['id_order_payment'].',
|
||||||
`id_order` = '.(int)$order_invoice->id_order);
|
`id_order` = '.(int)$order_invoice->id_order);
|
||||||
|
// Clear cache
|
||||||
|
Cache::clean('order_invoice_paid_*');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update order cart rule
|
// Update order cart rule
|
||||||
@@ -1465,6 +1469,9 @@ class OrderCore extends ObjectModel
|
|||||||
$res = Db::getInstance()->execute('
|
$res = Db::getInstance()->execute('
|
||||||
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
|
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment`
|
||||||
VALUES('.(int)$order_invoice->id.', '.(int)$order_payment->id.', '.(int)$this->id.')');
|
VALUES('.(int)$order_invoice->id.', '.(int)$order_payment->id.', '.(int)$this->id.')');
|
||||||
|
|
||||||
|
// Clear cache
|
||||||
|
Cache::clean('order_invoice_paid_*');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
|
|||||||
@@ -522,14 +522,16 @@ class OrderInvoiceCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public function getTotalPaid()
|
public function getTotalPaid()
|
||||||
{
|
{
|
||||||
if (!array_key_exists($this->id, self::$_total_paid_cache))
|
$cache_id = 'order_invoice_paid_'.(int)$this->id;
|
||||||
|
if (!Cache::isStored($cache_id))
|
||||||
{
|
{
|
||||||
self::$_total_paid_cache[$this->id] = 0;
|
$amount = 0;
|
||||||
$payments = OrderPayment::getByInvoiceId($this->id);
|
$payments = OrderPayment::getByInvoiceId($this->id);
|
||||||
foreach ($payments as $payment)
|
foreach ($payments as $payment)
|
||||||
self::$_total_paid_cache[$this->id] += $payment->amount;
|
$amount += $payment->amount;
|
||||||
|
Cache::store($cache_id, $amount);
|
||||||
}
|
}
|
||||||
return self::$_total_paid_cache[$this->id];
|
return Cache::retrieve($cache_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user