// Manage SQL upgrade for stock management + bug fix
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
function set_product_suppliers()
|
function set_product_suppliers()
|
||||||
{
|
{
|
||||||
//Get all products with positive quantity
|
//Get all products with positive quantity
|
||||||
$resource = Db::getInstance()->query('
|
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->query('
|
||||||
SELECT id_supplier, id_product, supplier_reference, wholesale_price
|
SELECT id_supplier, id_product, supplier_reference, wholesale_price
|
||||||
FROM `'._DB_PREFIX_.'product`
|
FROM `'._DB_PREFIX_.'product`
|
||||||
WHERE `id_supplier` > 0
|
WHERE `id_supplier` > 0
|
||||||
@@ -19,7 +19,7 @@ function set_product_suppliers()
|
|||||||
');
|
');
|
||||||
|
|
||||||
//Try to get product attribues
|
//Try to get product attribues
|
||||||
$attributes = Db::getInstance()->ExecuteS('
|
$attributes = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
SELECT id_product_attribute, supplier_reference, wholesale_price
|
SELECT id_product_attribute, supplier_reference, wholesale_price
|
||||||
FROM `'._DB_PREFIX_.'product_attribute`
|
FROM `'._DB_PREFIX_.'product_attribute`
|
||||||
WHERE `id_product` = '.(int)$row['id_product']
|
WHERE `id_product` = '.(int)$row['id_product']
|
||||||
@@ -28,9 +28,6 @@ function set_product_suppliers()
|
|||||||
//Add each attribute to stock_available
|
//Add each attribute to stock_available
|
||||||
foreach ($attributes as $attribute)
|
foreach ($attributes as $attribute)
|
||||||
{
|
{
|
||||||
// add to global quantity
|
|
||||||
$quantity += $attribute['quantity'];
|
|
||||||
|
|
||||||
// set supplier for attribute
|
// set supplier for attribute
|
||||||
Db::getInstance()->execute('
|
Db::getInstance()->execute('
|
||||||
INSERT INTO `'._DB_PREFIX_.'product_supplier`
|
INSERT INTO `'._DB_PREFIX_.'product_supplier`
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
function set_stock_available()
|
function set_stock_available()
|
||||||
{
|
{
|
||||||
//Get all products with positive quantity
|
//Get all products with positive quantity
|
||||||
$resource = Db::getInstance()->query('
|
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->query('
|
||||||
SELECT quantity, id_product, out_of_stock
|
SELECT quantity, id_product, out_of_stock
|
||||||
FROM `'._DB_PREFIX_.'product`
|
FROM `'._DB_PREFIX_.'product`
|
||||||
WHERE `active` = 1
|
WHERE `active` = 1
|
||||||
@@ -13,7 +13,7 @@ function set_stock_available()
|
|||||||
$quantity = 0;
|
$quantity = 0;
|
||||||
|
|
||||||
//Try to get product attribues
|
//Try to get product attribues
|
||||||
$attributes = Db::getInstance()->ExecuteS('
|
$attributes = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
SELECT quantity, id_product_attribute
|
SELECT quantity, id_product_attribute
|
||||||
FROM `'._DB_PREFIX_.'product_attribute`
|
FROM `'._DB_PREFIX_.'product_attribute`
|
||||||
WHERE `id_product` = '.(int)$row['id_product']
|
WHERE `id_product` = '.(int)$row['id_product']
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ function update_stock_mvt_reason()
|
|||||||
{
|
{
|
||||||
//Get all stock mvts reasons already presents in the solution (from 1.4.x)
|
//Get all stock mvts reasons already presents in the solution (from 1.4.x)
|
||||||
//Remove standard movements to keep only custom movement
|
//Remove standard movements to keep only custom movement
|
||||||
$mvts = Db::getInstance()->ExecuteS('
|
$mvts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
SELECT smr.*
|
SELECT smr.*
|
||||||
FROM `'._DB_PREFIX_.'stock_mvt_reason`
|
FROM `'._DB_PREFIX_.'stock_mvt_reason`
|
||||||
WHERE `id` > 5
|
WHERE `id` > 5
|
||||||
@@ -12,7 +12,7 @@ function update_stock_mvt_reason()
|
|||||||
|
|
||||||
//Get all stock mvts reasons language traduction already presents in the solution (from 1.4.x)
|
//Get all stock mvts reasons language traduction already presents in the solution (from 1.4.x)
|
||||||
//Remove standard movements to keep only custom movement
|
//Remove standard movements to keep only custom movement
|
||||||
$mvts_lang = Db::getInstance()->ExecuteS('
|
$mvts_lang = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
SELECT smrl.*
|
SELECT smrl.*
|
||||||
FROM `'._DB_PREFIX_.'stock_movement_reason_lang`
|
FROM `'._DB_PREFIX_.'stock_movement_reason_lang`
|
||||||
WHERE `id_stock_mvt_reason` > 5
|
WHERE `id_stock_mvt_reason` > 5
|
||||||
|
|||||||
@@ -274,6 +274,9 @@ ALTER TABLE `PREFIX_supplier` ADD COLUMN `id_address` int(10) unsigned NOT NULL
|
|||||||
|
|
||||||
ALTER TABLE `PREFIX_address` ADD COLUMN `id_warehouse` int(10) unsigned NOT NULL default '0' AFTER `id_supplier`;
|
ALTER TABLE `PREFIX_address` ADD COLUMN `id_warehouse` int(10) unsigned NOT NULL default '0' AFTER `id_supplier`;
|
||||||
|
|
||||||
|
ALTER TABLE `PREFIX_order_detail` ADD COLUMN `id_warehouse` int(10) unsigned NOT NULL default '0' AFTER `id_order_invoice`;
|
||||||
|
|
||||||
|
|
||||||
/* Update records after alter tables */
|
/* Update records after alter tables */
|
||||||
/* PHP:update_stock_mvt_reasons(); */;
|
/* PHP:update_stock_mvt_reasons(); */;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user