[-] 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()
{
$res = true;
$payments = Db::getInstance()->executeS('
$payments = Db::getInstance()->query('
SELECT op.id_order_payment, o.reference
FROM `'._DB_PREFIX_.'order_payment` op
INNER JOIN `'._DB_PREFIX_.'orders` o
ON o.id_order = op.id_order');
if (!is_array($payments))
if (!is_object($payments))
return false;
$errors = array();
// Populate "order_reference"
foreach ($payments as $payment)
while ($payment = Db::getInstance()->nextRow($payments))
{
$res = Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'order_payment`
SET order_reference = \''.$payment['reference'].'\'
WHERE id_order_payment = '.(int)$payment['id_order_payment']);
if (!$res)
$errors[] = Db::getInstance()->getMsgError();
if(isset($payment['id_order_payment']))
{
$res = Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'order_payment`
SET order_reference = \''.$payment['reference'].'\'
WHERE id_order_payment = '.(int)$payment['id_order_payment']);
if (!$res)
$errors[] = Db::getInstance()->getMsgError();
}
}
if (count($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)
$duplicate_lines = Db::getInstance()->executeS('
$duplicate_lines = Db::getInstance()->query('
SELECT GROUP_CONCAT(id_order_payment) as id_order_payments
FROM `'._DB_PREFIX_.'order_payment`
GROUP BY order_reference, date_add
HAVING COUNT(*) > 1');
if (!is_array($duplicate_lines))
if (!is_object($duplicate_lines))
return false;
$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)
$id_order_payment_keep = array_shift($order_payments_array);
@@ -84,6 +86,5 @@ function add_order_reference_in_order_payment()
if (!$res)
return array('errors' => true, 'msg' => Db::getInstance()->getMsgError());
return true;
}