[-] CORE : Fix bug #PSCFV-8705 stocks update for when no current state

This commit is contained in:
gRoussac committed 2013-04-22 12:09:35 +02:00
1 parent 31e7c6a08e
commit 4bf41c590b
1 file changed
+93 -92
+93 -92
View File
@@ -160,108 +160,109 @@ class OrderHistoryCore extends ObjectModel
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$manager = StockManagerFactory::getManager(); $manager = StockManagerFactory::getManager();
// foreach products of the order // foreach products of the order
foreach ($order->getProductsDetail() as $product) if (Validate::isLoadedObject($old_os))
{ foreach ($order->getProductsDetail() as $product)
// if becoming logable => adds sale
if ($new_os->logable && !$old_os->logable)
{ {
ProductSale::addProductSale($product['product_id'], $product['product_quantity']); // if becoming logable => adds sale
// @since 1.5.0 - Stock Management if ($new_os->logable && !$old_os->logable)
if (!Pack::isPack($product['product_id']) &&
($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) &&
!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);
}
// if becoming unlogable => removes sale
elseif (!$new_os->logable && $old_os->logable)
{
ProductSale::removeProductSale($product['product_id'], $product['product_quantity']);
// @since 1.5.0 - Stock Management
if (!Pack::isPack($product['product_id']) &&
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
}
// if waiting for payment => payment error/canceled
elseif (!$new_os->logable && !$old_os->logable &&
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
// @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management :
// decrements the physical stock using $id_warehouse
if ($new_os->shipped == 1 && $old_os->shipped == 0 &&
Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') &&
Warehouse::exists($product['id_warehouse']) &&
$manager != null &&
((int)$product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id'])))
{
// gets the warehouse
$warehouse = new Warehouse($product['id_warehouse']);
// decrements the stock (if it's a pack, the StockManager does what is needed)
$manager->removeProduct(
$product['product_id'],
$product['product_attribute_id'],
$warehouse,
$product['product_quantity'],
Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'),
true,
(int)$order->id
);
}
// @since.1.5.0 : if the order was shipped, and is not anymore, we need to restock products
elseif ($new_os->shipped == 0 && $old_os->shipped == 1 &&
Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') &&
Warehouse::exists($product['id_warehouse']) &&
$manager != null &&
((int)$product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id'])))
{
// if the product is a pack, we restock every products in the pack using the last negative stock mvts
if (Pack::isPack($product['product_id']))
{ {
$pack_products = Pack::getItems($product['product_id'], Configuration::get('PS_LANG_DEFAULT', null, null, $order->id_shop)); ProductSale::addProductSale($product['product_id'], $product['product_quantity']);
foreach ($pack_products as $pack_product) // @since 1.5.0 - Stock Management
if (!Pack::isPack($product['product_id']) &&
($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) &&
!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);
}
// if becoming unlogable => removes sale
elseif (!$new_os->logable && $old_os->logable)
{
ProductSale::removeProductSale($product['product_id'], $product['product_quantity']);
// @since 1.5.0 - Stock Management
if (!Pack::isPack($product['product_id']) &&
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
}
// if waiting for payment => payment error/canceled
elseif (!$new_os->logable && !$old_os->logable &&
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
// @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management :
// decrements the physical stock using $id_warehouse
if ($new_os->shipped == 1 && $old_os->shipped == 0 &&
Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') &&
Warehouse::exists($product['id_warehouse']) &&
$manager != null &&
((int)$product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id'])))
{
// gets the warehouse
$warehouse = new Warehouse($product['id_warehouse']);
// decrements the stock (if it's a pack, the StockManager does what is needed)
$manager->removeProduct(
$product['product_id'],
$product['product_attribute_id'],
$warehouse,
$product['product_quantity'],
Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'),
true,
(int)$order->id
);
}
// @since.1.5.0 : if the order was shipped, and is not anymore, we need to restock products
elseif ($new_os->shipped == 0 && $old_os->shipped == 1 &&
Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') &&
Warehouse::exists($product['id_warehouse']) &&
$manager != null &&
((int)$product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id'])))
{
// if the product is a pack, we restock every products in the pack using the last negative stock mvts
if (Pack::isPack($product['product_id']))
{ {
if ($pack_product->advanced_stock_management == 1) $pack_products = Pack::getItems($product['product_id'], Configuration::get('PS_LANG_DEFAULT', null, null, $order->id_shop));
foreach ($pack_products as $pack_product)
{ {
$mvts = StockMvt::getNegativeStockMvts($order->id, $pack_product->id, 0, $pack_product->pack_quantity * $product['product_quantity']); if ($pack_product->advanced_stock_management == 1)
foreach ($mvts as $mvt)
{ {
$manager->addProduct( $mvts = StockMvt::getNegativeStockMvts($order->id, $pack_product->id, 0, $pack_product->pack_quantity * $product['product_quantity']);
$pack_product->id, foreach ($mvts as $mvt)
0, {
new Warehouse($mvt['id_warehouse']), $manager->addProduct(
$mvt['physical_quantity'], $pack_product->id,
null, 0,
$mvt['price_te'], new Warehouse($mvt['id_warehouse']),
true $mvt['physical_quantity'],
); null,
$mvt['price_te'],
true
);
}
if (!StockAvailable::dependsOnStock($product['id_product']))
StockAvailable::updateQuantity($pack_product->id, 0, (int)$pack_product->pack_quantity * $product['product_quantity'], $order->id_shop);
} }
if (!StockAvailable::dependsOnStock($product['id_product'])) }
StockAvailable::updateQuantity($pack_product->id, 0, (int)$pack_product->pack_quantity * $product['product_quantity'], $order->id_shop); }
// else, it's not a pack, re-stock using the last negative stock mvts
else
{
$mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['product_quantity']);
foreach ($mvts as $mvt)
{
$manager->addProduct(
$product['product_id'],
$product['product_attribute_id'],
new Warehouse($mvt['id_warehouse']),
$mvt['physical_quantity'],
null,
$mvt['price_te'],
true
);
} }
} }
} }
// else, it's not a pack, re-stock using the last negative stock mvts
else
{
$mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['product_quantity']);
foreach ($mvts as $mvt)
{
$manager->addProduct(
$product['product_id'],
$product['product_attribute_id'],
new Warehouse($mvt['id_warehouse']),
$mvt['physical_quantity'],
null,
$mvt['price_te'],
true
);
}
}
} }
}
} }
$this->id_order_state = (int)$new_order_state; $this->id_order_state = (int)$new_order_state;