[-] Core: Fix PSCFV-3092
This commit is contained in:
@@ -646,7 +646,7 @@ abstract class PaymentModuleCore extends Module
|
|||||||
if (StockAvailable::dependsOnStock($product['product_id']))
|
if (StockAvailable::dependsOnStock($product['product_id']))
|
||||||
{
|
{
|
||||||
// synchronizes
|
// synchronizes
|
||||||
StockAvailable::synchronize($product['product_id']);
|
StockAvailable::synchronize($product['product_id'], $order->id_shop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ class OrderHistoryCore extends ObjectModel
|
|||||||
// @since 1.5.0 - Stock Management
|
// @since 1.5.0 - Stock Management
|
||||||
if (!Pack::isPack($product['product_id']) &&
|
if (!Pack::isPack($product['product_id']) &&
|
||||||
($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) &&
|
($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) &&
|
||||||
!StockAvailable::dependsOnStock($product['id_product']))
|
!StockAvailable::dependsOnStock($product['id_product'], (int)$order->id_shop))
|
||||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
|
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
|
||||||
}
|
}
|
||||||
// if becoming unlogable => removes sale
|
// if becoming unlogable => removes sale
|
||||||
else if (!$new_os->logable && $old_os->logable)
|
elseif (!$new_os->logable && $old_os->logable)
|
||||||
{
|
{
|
||||||
ProductSale::removeProductSale($product['product_id'], $product['product_quantity']);
|
ProductSale::removeProductSale($product['product_id'], $product['product_quantity']);
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ class OrderHistoryCore extends ObjectModel
|
|||||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
|
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
|
||||||
}
|
}
|
||||||
// if waiting for payment => payment error/canceled
|
// if waiting for payment => payment error/canceled
|
||||||
else if (!$new_os->logable && !$old_os->logable &&
|
elseif (!$new_os->logable && !$old_os->logable &&
|
||||||
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
|
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
|
||||||
!StockAvailable::dependsOnStock($product['id_product']))
|
!StockAvailable::dependsOnStock($product['id_product']))
|
||||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
|
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
|
||||||
@@ -153,7 +153,7 @@ class OrderHistoryCore extends ObjectModel
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
// @since.1.5.0 : if the order was shipped, and is not anymore, we need to restock products
|
// @since.1.5.0 : if the order was shipped, and is not anymore, we need to restock products
|
||||||
else if ($new_os->shipped == 0 && $old_os->shipped == 1 &&
|
elseif ($new_os->shipped == 0 && $old_os->shipped == 1 &&
|
||||||
Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') &&
|
Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') &&
|
||||||
Warehouse::exists($product['id_warehouse']) &&
|
Warehouse::exists($product['id_warehouse']) &&
|
||||||
$manager != null &&
|
$manager != null &&
|
||||||
|
|||||||
@@ -112,11 +112,18 @@ class StockAvailableCore extends ObjectModel
|
|||||||
*
|
*
|
||||||
* @param int $id_product
|
* @param int $id_product
|
||||||
*/
|
*/
|
||||||
public static function synchronize($id_product)
|
public static function synchronize($id_product, $order_id_shop = null)
|
||||||
{
|
{
|
||||||
// gets warehouse ids grouped by shops
|
// gets warehouse ids grouped by shops
|
||||||
$ids_warehouse = Warehouse::getWarehousesGroupedByShops();
|
$ids_warehouse = Warehouse::getWarehousesGroupedByShops();
|
||||||
|
if ($order_id_shop !== null)
|
||||||
|
{
|
||||||
|
$order_warehouses = array();
|
||||||
|
$wh = Warehouse::getWarehouses(false, (int)$order_id_shop);
|
||||||
|
foreach ($wh as $warehouse)
|
||||||
|
$order_warehouses[] = $warehouse['id_warehouse'];
|
||||||
|
}
|
||||||
|
|
||||||
// gets all product attributes ids
|
// gets all product attributes ids
|
||||||
$ids_product_attribute = array();
|
$ids_product_attribute = array();
|
||||||
foreach (Product::getProductAttributesIds($id_product) as $id_product_attribute)
|
foreach (Product::getProductAttributesIds($id_product) as $id_product_attribute)
|
||||||
@@ -143,6 +150,9 @@ class StockAvailableCore extends ObjectModel
|
|||||||
foreach ($allowed_warehouse_for_product as $warehouse)
|
foreach ($allowed_warehouse_for_product as $warehouse)
|
||||||
$allowed_warehouse_for_product_clean[] = (int)$warehouse['id_warehouse'];
|
$allowed_warehouse_for_product_clean[] = (int)$warehouse['id_warehouse'];
|
||||||
$allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses);
|
$allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses);
|
||||||
|
if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses)))
|
||||||
|
continue;
|
||||||
|
|
||||||
$product_quantity = $manager->getProductRealQuantities($id_product, null, $allowed_warehouse_for_product_clean, true);
|
$product_quantity = $manager->getProductRealQuantities($id_product, null, $allowed_warehouse_for_product_clean, true);
|
||||||
}
|
}
|
||||||
// else this product has attributes, hence loops on $ids_product_attribute
|
// else this product has attributes, hence loops on $ids_product_attribute
|
||||||
@@ -156,6 +166,9 @@ class StockAvailableCore extends ObjectModel
|
|||||||
foreach ($allowed_warehouse_for_combination as $warehouse)
|
foreach ($allowed_warehouse_for_combination as $warehouse)
|
||||||
$allowed_warehouse_for_combination_clean[] = (int)$warehouse['id_warehouse'];
|
$allowed_warehouse_for_combination_clean[] = (int)$warehouse['id_warehouse'];
|
||||||
$allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses);
|
$allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses);
|
||||||
|
if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses)))
|
||||||
|
continue;
|
||||||
|
|
||||||
$quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $allowed_warehouse_for_combination_clean, true);
|
$quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $allowed_warehouse_for_combination_clean, true);
|
||||||
|
|
||||||
$query = new DbQuery();
|
$query = new DbQuery();
|
||||||
|
|||||||
@@ -304,7 +304,10 @@ class WarehouseCore extends ObjectModel
|
|||||||
if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||||
$shop_group = Shop::getContextShopGroup();
|
$shop_group = Shop::getContextShopGroup();
|
||||||
else
|
else
|
||||||
|
{
|
||||||
$shop_group = Context::getContext()->shop->getGroup();
|
$shop_group = Context::getContext()->shop->getGroup();
|
||||||
|
$id_shop = (int)Context::getContext()->shop->id;
|
||||||
|
}
|
||||||
$share_stock = $shop_group->share_stock;
|
$share_stock = $shop_group->share_stock;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -316,7 +319,7 @@ class WarehouseCore extends ObjectModel
|
|||||||
if ($share_stock)
|
if ($share_stock)
|
||||||
$ids_shop = Shop::getShops(true, (int)$shop_group->id, true);
|
$ids_shop = Shop::getShops(true, (int)$shop_group->id, true);
|
||||||
else
|
else
|
||||||
$ids_shop = array((int)Context::getContext()->shop->id);
|
$ids_shop = array((int)$id_shop);
|
||||||
|
|
||||||
$query = new DbQuery();
|
$query = new DbQuery();
|
||||||
$query->select('wpl.id_warehouse, CONCAT(w.reference, " - ", w.name) as name');
|
$query->select('wpl.id_warehouse, CONCAT(w.reference, " - ", w.name) as name');
|
||||||
|
|||||||
Reference in New Issue
Block a user