[-] INSTALLER : Fix bug #PSCFV-8605 loop on ressource wether than n array

This commit is contained in:
gRoussac
2013-05-21 16:29:26 +02:00
parent 7576bc18e4
commit f6ccbb0080
@@ -27,47 +27,49 @@
function add_order_reference_in_order_payment() function add_order_reference_in_order_payment()
{ {
$res = true; $res = true;
$payments = Db::getInstance()->executeS(' $payments = Db::getInstance()->query('
SELECT op.id_order_payment, o.reference SELECT op.id_order_payment, o.reference
FROM `'._DB_PREFIX_.'order_payment` op FROM `'._DB_PREFIX_.'order_payment` op
INNER JOIN `'._DB_PREFIX_.'orders` o INNER JOIN `'._DB_PREFIX_.'orders` o
ON o.id_order = op.id_order'); ON o.id_order = op.id_order');
if (!is_array($payments)) if (!is_object($payments))
return false; return false;
$errors = array(); $errors = array();
// Populate "order_reference" // Populate "order_reference"
foreach ($payments as $payment) while ($payment = Db::getInstance()->nextRow($payments))
{ {
$res = Db::getInstance()->execute(' if(isset($payment['id_order_payment']))
UPDATE `'._DB_PREFIX_.'order_payment` {
SET order_reference = \''.$payment['reference'].'\' $res = Db::getInstance()->execute('
WHERE id_order_payment = '.(int)$payment['id_order_payment']); UPDATE `'._DB_PREFIX_.'order_payment`
SET order_reference = \''.$payment['reference'].'\'
if (!$res) WHERE id_order_payment = '.(int)$payment['id_order_payment']);
$errors[] = Db::getInstance()->getMsgError(); if (!$res)
$errors[] = Db::getInstance()->getMsgError();
}
} }
if (count($errors)) if (count($errors))
return array('error' => true, 'msg' => implode('<br/>', $errors)); return array('error' => true, 'msg' => implode('<br/>', $errors));
// Get lines to merge (with multishipping on, durring the payment one line was added by order, only one is necessary by cart) // Get lines to merge (with multishipping on, durring the payment one line was added by order, only one is necessary by cart)
$duplicate_lines = Db::getInstance()->executeS(' $duplicate_lines = Db::getInstance()->query('
SELECT GROUP_CONCAT(id_order_payment) as id_order_payments SELECT GROUP_CONCAT(id_order_payment) as id_order_payments
FROM `'._DB_PREFIX_.'order_payment` FROM `'._DB_PREFIX_.'order_payment`
GROUP BY order_reference, date_add GROUP BY order_reference, date_add
HAVING COUNT(*) > 1'); HAVING COUNT(*) > 1');
if (!is_array($duplicate_lines)) if (!is_object($duplicate_lines))
return false; return false;
$order_payments_to_remove = array(); $order_payments_to_remove = array();
foreach ($duplicate_lines as $order_payments) while ($order_payments = Db::getInstance()->nextRow($duplicate_lines))
{ {
$order_payments_array = explode(',', $order_payments['id_order_payments']); $order_payments_array = array();
if(isset($order_payments['id_order_payments']))
$order_payments_array = explode(',', $order_payments['id_order_payments']);
// Remove the first item (we want to keep one line) // Remove the first item (we want to keep one line)
$id_order_payment_keep = array_shift($order_payments_array); $id_order_payment_keep = array_shift($order_payments_array);
@@ -84,6 +86,5 @@ function add_order_reference_in_order_payment()
if (!$res) if (!$res)
return array('errors' => true, 'msg' => Db::getInstance()->getMsgError()); return array('errors' => true, 'msg' => Db::getInstance()->getMsgError());
return true; return true;
} }