// Removing some id_warehouse
// Adding some checks with advanced_stock_management product attribute git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11375 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1231,7 +1231,10 @@ class AdminControllerCore extends Controller
|
||||
{
|
||||
if (Tab::checkTabRights($tab['id_tab']) === true)
|
||||
{
|
||||
if ($tab['name'] == 'Stock' && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 0)
|
||||
if ($tab['name'] == 'Stock'
|
||||
&& Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') == 0
|
||||
&& (int)$product['advanced_stock_management'] == 1
|
||||
)
|
||||
{
|
||||
unset($tabs[$index]);
|
||||
continue;
|
||||
|
||||
+3
-2
@@ -380,7 +380,8 @@ class CartCore extends ObjectModel
|
||||
p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`, p.`price`, p.`weight`,
|
||||
stock.`quantity` quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`active`, p.`date_add`,
|
||||
p.`date_upd`, t.`id_tax`, tl.`name` AS tax, t.`rate`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
|
||||
CONCAT(cp.`id_product`, cp.`id_product_attribute`, cp.`id_address_delivery`) AS unique_id, cp.id_address_delivery, p.`wholesale_price`');
|
||||
CONCAT(cp.`id_product`, cp.`id_product_attribute`, cp.`id_address_delivery`) AS unique_id, cp.id_address_delivery, p.`wholesale_price`,
|
||||
p.advanced_stock_management');
|
||||
|
||||
// Build FROM
|
||||
$sql->from('cart_product', 'cp');
|
||||
@@ -1358,7 +1359,7 @@ class CartCore extends ObjectModel
|
||||
|
||||
$product['warehouse_list'] = array();
|
||||
|
||||
if ($stock_management_active)
|
||||
if ($stock_management_active && (int)$product['advanced_stock_management'] == 1)
|
||||
{
|
||||
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
|
||||
// Does the product is in stock ?
|
||||
|
||||
+1
-1
@@ -3060,7 +3060,7 @@ class ProductCore extends ObjectModel
|
||||
$context = Context::getContext();
|
||||
|
||||
$sql = new DbQuery();
|
||||
$sql->select('p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`');
|
||||
$sql->select('p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`, p.advanced_stock_management');
|
||||
$sql->from('category_product', 'cp');
|
||||
$sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
|
||||
$sql->join($context->shop->addSqlAssociation('product', 'p'));
|
||||
|
||||
@@ -448,6 +448,8 @@ class OrderCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'order_detail` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON p.id_product = od.product_id
|
||||
WHERE od.`id_order` = '.(int)($this->id));
|
||||
}
|
||||
|
||||
@@ -606,7 +608,9 @@ class OrderCore extends ObjectModel
|
||||
*/
|
||||
protected function setProductCurrentStock(&$product)
|
||||
{
|
||||
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['id_warehouse'] > 0)
|
||||
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
|
||||
&& (int)$product['advanced_stock_management'] == 1
|
||||
&& (int)$product['id_warehouse'] > 0)
|
||||
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], (int)$product['id_warehouse'], true);
|
||||
else
|
||||
$product['current_stock'] = '--';
|
||||
|
||||
@@ -65,7 +65,7 @@ class OrderHistoryCore extends ObjectModel
|
||||
),
|
||||
);
|
||||
|
||||
public function changeIdOrderState($new_order_state, $id_order, $id_warehouse = null)
|
||||
public function changeIdOrderState($new_order_state, $id_order)
|
||||
{
|
||||
if ($new_order_state != NULL)
|
||||
{
|
||||
@@ -75,58 +75,71 @@ class OrderHistoryCore extends ObjectModel
|
||||
/* Best sellers */
|
||||
$newOS = new OrderState((int)($new_order_state), $order->id_lang);
|
||||
$oldOrderStatus = OrderHistory::getLastOrderState((int)$id_order);
|
||||
$cart = Cart::getCartByOrderId($id_order);
|
||||
$isValidated = $this->isValidated();
|
||||
if (Validate::isLoadedObject($cart))
|
||||
foreach ($cart->getProducts() as $product)
|
||||
if (Validate::isLoadedObject($order))
|
||||
foreach ($order->getProductsDetail() as $product)
|
||||
{
|
||||
/* If becoming logable => adding sale */
|
||||
if ($newOS->logable AND (!$oldOrderStatus OR !$oldOrderStatus->logable))
|
||||
{
|
||||
ProductSale::addProductSale($product['id_product'], $product['cart_quantity']);
|
||||
ProductSale::addProductSale($product['product_id'], $product['product_quantity']);
|
||||
}
|
||||
/* If becoming unlogable => removing sale */
|
||||
else if (!$newOS->logable AND ($oldOrderStatus AND $oldOrderStatus->logable))
|
||||
{
|
||||
ProductSale::removeProductSale($product['id_product'], $product['cart_quantity']);
|
||||
ProductSale::removeProductSale($product['product_id'], $product['product_quantity']);
|
||||
// @since 1.5.0
|
||||
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], (int)$product['cart_quantity'], $order->id_shop);
|
||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
|
||||
}
|
||||
|
||||
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'], $order->id_shop);
|
||||
if ((!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') || (int)$product['advanced_stock_management'] != 1)
|
||||
&& !$isValidated
|
||||
&& $newOS->logable
|
||||
&& isset($oldOrderStatus)
|
||||
&& $oldOrderStatus
|
||||
&& $oldOrderStatus->id == Configuration::get('PS_OS_ERROR')
|
||||
)
|
||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
|
||||
// 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
|
||||
// @TODO Checks $id_warehouse
|
||||
else if ($newOS->shipped == 1 && $oldOrderStatus->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
|
||||
else if ($newOS->shipped == 1
|
||||
&& $oldOrderStatus->shipped == 0
|
||||
&& Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
|
||||
&& (int)$product['advanced_stock_management'] == 1
|
||||
)
|
||||
{
|
||||
$manager = StockManagerFactory::getManager();
|
||||
$warehouse = new Warehouse($id_warehouse);
|
||||
$warehouse = new Warehouse($product['id_warehouse']);
|
||||
|
||||
$manager->removeProduct(
|
||||
$product['id_product'],
|
||||
$product['id_product_attribute'],
|
||||
$warehouse,
|
||||
$product['cart_quantity'],
|
||||
Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'),
|
||||
true,
|
||||
(int)$id_order
|
||||
$product['product_id'],
|
||||
$product['product_attribute_id'],
|
||||
$warehouse,
|
||||
$product['product_quantity'],
|
||||
Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'),
|
||||
true,
|
||||
(int)$id_order
|
||||
);
|
||||
|
||||
if (StockAvailable::dependsOnStock($product['id_product'], $order->id_shop))
|
||||
StockAvailable::synchronize($product['id_product']);
|
||||
if (StockAvailable::dependsOnStock($product['product_id'], $order->id_shop))
|
||||
StockAvailable::synchronize($product['product_id']);
|
||||
else
|
||||
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity'], $order->id_shop);
|
||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
|
||||
}
|
||||
else if ($newOS->shipped == 0 && $oldOrderStatus->shipped == 1 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
|
||||
else if ($newOS->shipped == 0
|
||||
&& $oldOrderStatus->shipped == 1
|
||||
&& Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
|
||||
&& (int)$product['advanced_stock_management'] == 1
|
||||
)
|
||||
{
|
||||
$manager = StockManagerFactory::getManager();
|
||||
$mvts = StockMvt::getNegativeStockMvts($order->id, $product['id_product'], $product['id_product_attribute'], $product['cart_quantity']);
|
||||
$mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['cart_quantity']);
|
||||
foreach ($mvts as $mvt)
|
||||
{
|
||||
$manager->addProduct(
|
||||
$product['id_product'],
|
||||
$product['product_id'],
|
||||
$product['id_product_attribute'],
|
||||
new Warehouse($mvt['id_warehouse']),
|
||||
$mvt['physical_quantity'],
|
||||
@@ -136,10 +149,10 @@ class OrderHistoryCore extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
if (StockAvailable::dependsOnStock($product['id_product'], $order->id_shop))
|
||||
StockAvailable::synchronize($product['id_product']);
|
||||
if (StockAvailable::dependsOnStock($product['product_id'], $order->id_shop))
|
||||
StockAvailable::synchronize($product['product_id']);
|
||||
else
|
||||
StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], (int)$product['cart_quantity'], $order->id_shop);
|
||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['physical_quantity'], $order->id_shop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ class OrderInvoiceCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'order_detail` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON p.id_product = od.product_id
|
||||
WHERE od.`id_order` = '.(int)$this->id_order.'
|
||||
AND od.`id_order_invoice` = '.(int)$this->id);
|
||||
}
|
||||
@@ -173,7 +175,12 @@ class OrderInvoiceCore extends ObjectModel
|
||||
*/
|
||||
protected function setProductCurrentStock(&$product)
|
||||
{
|
||||
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
|
||||
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
|
||||
&& (int)$product['advanced_stock_management'] == 1
|
||||
&& (int)$product['id_warehouse'] > 0)
|
||||
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
|
||||
else
|
||||
$product['current_stock'] = '--';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user