// StockManager : bugs fix + improvement of StockManager utilisation in fucntion of global configuration

This commit is contained in:
dSevere
2011-12-02 15:23:01 +00:00
parent 5259d4e64e
commit 6fddfce5e7
6 changed files with 53 additions and 41 deletions
+36 -25
View File
@@ -1359,6 +1359,8 @@ class CartCore extends ObjectModel
$warehouse_count_by_address = array();
$warehouse_carrier_list = array();
$stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
foreach ($product_list as &$product)
{
if ((int)$product['id_address_delivery'] == 0)
@@ -1369,32 +1371,41 @@ class CartCore extends ObjectModel
$product['warehouse_list'] = array();
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
// Does the product is in stock ?
// If yes, get only warehouse where the product is in stock
$warehouse_in_stock = array();
$manager = StockManagerFactory::getManager();
foreach ($warehouse_list as $key => $warehouse)
if ($stock_management_active)
{
$product_real_quantities = $manager->getProductRealQuantities(
$product['id_product'],
$product['id_product_attribute'],
array($warehouse['id_warehouse']),
true
);
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
// Does the product is in stock ?
// If yes, get only warehouse where the product is in stock
$warehouse_in_stock = array();
$manager = StockManagerFactory::getManager();
if ($product_real_quantities > 0)
$warehouse_in_stock[] = $warehouse;
}
foreach ($warehouse_list as $key => $warehouse)
{
$product_real_quantities = $manager->getProductRealQuantities(
$product['id_product'],
$product['id_product_attribute'],
array($warehouse['id_warehouse']),
true
);
if (!empty($warehouse_in_stock))
{
$warehouse = $warehouse_in_stock;
$product['in_stock'] = true;
if ($product_real_quantities > 0)
$warehouse_in_stock[] = $warehouse;
}
if (!empty($warehouse_in_stock))
{
$warehouse_list = $warehouse_in_stock;
$product['in_stock'] = true;
}
else
$product['in_stock'] = false;
}
else
$product['in_stock'] = false;
{
//simulate default warehouse
$warehouse_list = array(0);
$product['in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']) > 0;
}
foreach ($warehouse_list as $warehouse)
{
@@ -1901,7 +1912,7 @@ class CartCore extends ObjectModel
/**
* Return shipping total of a specific carriers for the cart
*
* @param int $id_carrier
* @param int $id_carrier
* @param array $delivery_option Array of the delivery option for each address
* @param booleal $useTax
* @param Country $default_country
@@ -1914,8 +1925,8 @@ class CartCore extends ObjectModel
$total_shipping = 0;
$delivery_option_list = $this->getDeliveryOptionList();
foreach ($delivery_option as $id_address => $key)
{
if (!isset($delivery_option_list[$id_address]) || !isset($delivery_option_list[$id_address][$key]))
@@ -1931,7 +1942,7 @@ class CartCore extends ObjectModel
return $total_shipping;
}
/**
* Return shipping total
+10 -7
View File
@@ -654,13 +654,16 @@ class ProductCore extends ObjectModel
* - physical stock for this product
* - supply order(s) for this product
*/
$stock_manager = StockManagerFactory::getManager();
$physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0);
$real_quantity = $stock_manager->getProductRealQuantities($this->id, 0);
if ($physical_quantity > 0)
return false;
if ($real_quantity > $physical_quantity)
return false;
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
{
$stock_manager = StockManagerFactory::getManager();
$physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0);
$real_quantity = $stock_manager->getProductRealQuantities($this->id, 0);
if ($physical_quantity > 0)
return false;
if ($real_quantity > $physical_quantity)
return false;
}
/*
* @since 1.5.0
+4 -1
View File
@@ -94,7 +94,10 @@ class OrderHistoryCore extends ObjectModel
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && !$isValidated AND $newOS->logable AND isset($oldOrderStatus) AND $oldOrderStatus AND $oldOrderStatus->id == Configuration::get('PS_OS_ERROR'))
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], (int)$product['cart_quantity']);
else if ($newOS->shipped == 1 && $oldOrderStatus->shipped == 0) // The product is removed from the physical stock. $id_warehouse is needed
// If order is shipped for the first time and
// if we use advanced stock management system, decrement stock preperly.
// The product is removed from the physical stock. $id_warehouse is needed
else if ($newOS->shipped == 1 && $oldOrderStatus->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
{
$manager = StockManagerFactory::getManager();
$warehouse = new Warehouse($id_warehouse);
+2 -2
View File
@@ -207,10 +207,10 @@ class StockManagerCore implements StockManagerInterface
// Special case of a pack
if (Pack::isPack($id_product))
{
$products_pack = Pack::getItems((int)$product['id_product'], (int)Configuration::get('PS_LANG_DEFAULT'));
$products_pack = Pack::getItems($id_product, (int)Configuration::get('PS_LANG_DEFAULT'));
foreach ($products_pack as $product_pack)
{
$pack_id_product_attribute = Product::getDefaultAttribute($tab_product_pack['id_product'], 1); //@TODO is there a better way to retrieve the product attribute assciated to the pack ?
$pack_id_product_attribute = Product::getDefaultAttribute($id_product_attribute, 1); //@TODO is there a better way to retrieve the product attribute assciated to the pack ?
$this->removeProduct($product_pack->id, $pack_id_product_attribute, $product_pack->pack_quantity * $quantity, $warehouse, $id_order);
}
}
@@ -2648,17 +2648,12 @@ class AdminProductsControllerCore extends AdminController
$this->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
$this->addJS(_PS_JS_DIR_.'tinymce.inc.js');
$currency = $this->context->currency;
$data->assign('languages',$languages);
$this->object = $product;
$this->display = 'edit';
$content = '';
$has_attribute = $product->hasAttributes();
// @FIXME Stock, need to use StockManagerFactory
$qty = 0;
$cover = Product::getCover($product->id);
$this->_applyTaxToEcotax($product);
+1 -1
View File
@@ -327,7 +327,7 @@ class MailAlerts extends Module
$sql = 'SELECT id_product, quantity
FROM '._DB_PREFIX_.'stock_available
WHERE id_product_attribute = '.(int)$params['id_product_attribute']
.Context::getContext()->shop->addSqlRestriction();
.StockAvailable::addSqlShopRestriction();
$result = Db::getInstance()->getRow($sql);
if ($this->_customer_qty AND $result['quantity'] > 0)