// 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_count_by_address = array();
$warehouse_carrier_list = array(); $warehouse_carrier_list = array();
$stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
foreach ($product_list as &$product) foreach ($product_list as &$product)
{ {
if ((int)$product['id_address_delivery'] == 0) if ((int)$product['id_address_delivery'] == 0)
@@ -1369,32 +1371,41 @@ class CartCore extends ObjectModel
$product['warehouse_list'] = array(); $product['warehouse_list'] = array();
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']); if ($stock_management_active)
// 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)
{ {
$product_real_quantities = $manager->getProductRealQuantities( $warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
$product['id_product'], // Does the product is in stock ?
$product['id_product_attribute'], // If yes, get only warehouse where the product is in stock
array($warehouse['id_warehouse']), $warehouse_in_stock = array();
true $manager = StockManagerFactory::getManager();
);
if ($product_real_quantities > 0) foreach ($warehouse_list as $key => $warehouse)
$warehouse_in_stock[] = $warehouse; {
} $product_real_quantities = $manager->getProductRealQuantities(
$product['id_product'],
$product['id_product_attribute'],
array($warehouse['id_warehouse']),
true
);
if (!empty($warehouse_in_stock)) if ($product_real_quantities > 0)
{ $warehouse_in_stock[] = $warehouse;
$warehouse = $warehouse_in_stock; }
$product['in_stock'] = true;
if (!empty($warehouse_in_stock))
{
$warehouse_list = $warehouse_in_stock;
$product['in_stock'] = true;
}
else
$product['in_stock'] = false;
} }
else 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) foreach ($warehouse_list as $warehouse)
{ {
@@ -1901,7 +1912,7 @@ class CartCore extends ObjectModel
/** /**
* Return shipping total of a specific carriers for the cart * 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 array $delivery_option Array of the delivery option for each address
* @param booleal $useTax * @param booleal $useTax
* @param Country $default_country * @param Country $default_country
@@ -1914,8 +1925,8 @@ class CartCore extends ObjectModel
$total_shipping = 0; $total_shipping = 0;
$delivery_option_list = $this->getDeliveryOptionList(); $delivery_option_list = $this->getDeliveryOptionList();
foreach ($delivery_option as $id_address => $key) foreach ($delivery_option as $id_address => $key)
{ {
if (!isset($delivery_option_list[$id_address]) || !isset($delivery_option_list[$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 $total_shipping;
} }
/** /**
* Return shipping total * Return shipping total
+10 -7
View File
@@ -654,13 +654,16 @@ class ProductCore extends ObjectModel
* - physical stock for this product * - physical stock for this product
* - supply order(s) for this product * - supply order(s) for this product
*/ */
$stock_manager = StockManagerFactory::getManager(); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
$physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0); {
$real_quantity = $stock_manager->getProductRealQuantities($this->id, 0); $stock_manager = StockManagerFactory::getManager();
if ($physical_quantity > 0) $physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0);
return false; $real_quantity = $stock_manager->getProductRealQuantities($this->id, 0);
if ($real_quantity > $physical_quantity) if ($physical_quantity > 0)
return false; return false;
if ($real_quantity > $physical_quantity)
return false;
}
/* /*
* @since 1.5.0 * @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')) 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']); 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(); $manager = StockManagerFactory::getManager();
$warehouse = new Warehouse($id_warehouse); $warehouse = new Warehouse($id_warehouse);
+2 -2
View File
@@ -207,10 +207,10 @@ class StockManagerCore implements StockManagerInterface
// Special case of a pack // Special case of a pack
if (Pack::isPack($id_product)) 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) 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); $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_.'tiny_mce/tiny_mce.js');
$this->addJS(_PS_JS_DIR_.'tinymce.inc.js'); $this->addJS(_PS_JS_DIR_.'tinymce.inc.js');
$currency = $this->context->currency; $currency = $this->context->currency;
$data->assign('languages',$languages); $data->assign('languages',$languages);
$this->object = $product; $this->object = $product;
$this->display = 'edit'; $this->display = 'edit';
$content = ''; $content = '';
$has_attribute = $product->hasAttributes(); $has_attribute = $product->hasAttributes();
// @FIXME Stock, need to use StockManagerFactory
$qty = 0;
$cover = Product::getCover($product->id); $cover = Product::getCover($product->id);
$this->_applyTaxToEcotax($product); $this->_applyTaxToEcotax($product);
+1 -1
View File
@@ -327,7 +327,7 @@ class MailAlerts extends Module
$sql = 'SELECT id_product, quantity $sql = 'SELECT id_product, quantity
FROM '._DB_PREFIX_.'stock_available FROM '._DB_PREFIX_.'stock_available
WHERE id_product_attribute = '.(int)$params['id_product_attribute'] WHERE id_product_attribute = '.(int)$params['id_product_attribute']
.Context::getContext()->shop->addSqlRestriction(); .StockAvailable::addSqlShopRestriction();
$result = Db::getInstance()->getRow($sql); $result = Db::getInstance()->getRow($sql);
if ($this->_customer_qty AND $result['quantity'] > 0) if ($this->_customer_qty AND $result['quantity'] > 0)