[-] Project : #PSCFV-2633 #PSCFV-2622 - Fix problems with multishipping and order payment & invoice
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@15797 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1310,8 +1310,7 @@ CREATE TABLE `PREFIX_page_viewed` (
|
||||
|
||||
CREATE TABLE `PREFIX_order_payment` (
|
||||
`id_order_payment` INT NOT NULL auto_increment,
|
||||
`id_order_invoice` INT UNSIGNED NULL,
|
||||
`id_order` INT UNSIGNED NULL,
|
||||
`order_reference` VARCHAR(9),
|
||||
`id_currency` INT UNSIGNED NOT NULL,
|
||||
`amount` DECIMAL(10,2) NOT NULL,
|
||||
`payment_method` varchar(255) NOT NULL,
|
||||
@@ -1323,7 +1322,7 @@ CREATE TABLE `PREFIX_order_payment` (
|
||||
`card_holder` VARCHAR(254) NULL,
|
||||
`date_add` DATETIME NOT NULL,
|
||||
PRIMARY KEY (`id_order_payment`),
|
||||
KEY `id_order` (`id_order`)
|
||||
KEY `order_reference`(`order_reference`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `PREFIX_product` (
|
||||
@@ -2408,3 +2407,14 @@ CREATE TABLE `PREFIX_module_preference` (
|
||||
PRIMARY KEY (`id_carrier`, `id_tax_rules_group`, `id_shop`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
CREATE TABLE `PREFIX_order_invoice_payment` (
|
||||
`id_order_invoice` int(11) unsigned NOT NULL,
|
||||
`id_order_payment` int(11) unsigned NOT NULL,
|
||||
`id_order` int(11) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_order_invoice`,`id_order_payment`),
|
||||
KEY `order_payment` (`id_order_payment`),
|
||||
KEY `id_order` (`id_order`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2012 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2012 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
function add_order_reference_in_order_payment()
|
||||
{
|
||||
$payments = Db::getInstance()->executeS('
|
||||
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))
|
||||
return false;
|
||||
|
||||
$errors = array();
|
||||
|
||||
|
||||
// Populate "order_reference"
|
||||
foreach ($payments as $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('
|
||||
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))
|
||||
return false;
|
||||
|
||||
$order_payments_to_remove = array();
|
||||
foreach ($duplicate_lines as $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);
|
||||
|
||||
$res = Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'order_invoice_payment`
|
||||
SET id_order_payement = '.(int)$id_order_payment_keep.'
|
||||
WHERE id_order_payment IN ('.implode(',', $order_payments_array).')');
|
||||
|
||||
$order_payments_to_remove = array_merge($order_payments_to_remove, $order_payments_array);
|
||||
}
|
||||
// Remove the duplicate lines (because of the multishipping)
|
||||
if (count($order_payments_to_remove))
|
||||
$res = Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'order_payment` WHERE id_order_payment IN ('.implode(',', $order_payments_to_remove).')');
|
||||
|
||||
if (!$res)
|
||||
return array('errors' => true, 'msg' => Db::getInstance()->getMsgError());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -5,3 +5,33 @@ DROP TABLE `PREFIX_discount_type`;
|
||||
DROP TABLE `PREFIX_discount_type_lang`;
|
||||
|
||||
/* PHP:add_missing_image_key(); */;
|
||||
|
||||
-- Update order_payment structure for multishipping
|
||||
|
||||
-- Step 1: Add the table ps_order_invoice_payment and populate it
|
||||
CREATE TABLE `PREFIX_order_invoice_payment` (
|
||||
`id_order_invoice` int(11) unsigned NOT NULL,
|
||||
`id_order_payment` int(11) unsigned NOT NULL,
|
||||
`id_order` int(11) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_order_invoice`,`id_order_payment`),
|
||||
KEY `order_payment` (`id_order_payment`),
|
||||
KEY `id_order` (`id_order`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
INSERT INTO `PREFIX_order_invoice_payment`
|
||||
(SELECT id_order_invoice, id_order_payment, id_order FROM `PREFIX_order_payment` WHERE id_order_invoice > 0);
|
||||
|
||||
-- Step 2: Add the collumn id_order_reference
|
||||
ALTER TABLE `PREFIX_order_payment`
|
||||
ADD COLUMN `order_reference` VARCHAR(9) AFTER `id_order`,
|
||||
ADD INDEX `order_reference`(`order_reference`);
|
||||
|
||||
|
||||
-- Step 3: Fill in id_order_reference and merge duplicate lines
|
||||
/* PHP:add_order_reference_in_order_payment(); */;
|
||||
|
||||
-- Step 4: Drop collumn id_order
|
||||
ALTER TABLE `PREFIX_order_payment`
|
||||
DROP COLUMN `id_order`,
|
||||
DROP COLUMN `id_order_invoice`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user