diff --git a/admin-dev/themes/template/orders/view.tpl b/admin-dev/themes/template/orders/view.tpl index 9c1cdf721..2a2f2c5cd 100755 --- a/admin-dev/themes/template/orders/view.tpl +++ b/admin-dev/themes/template/orders/view.tpl @@ -54,39 +54,6 @@ statesShipped.push({$state['id_order_state']}); {/if} {/foreach} - - {literal} - function showWarehouseList() - { - {/literal}{if (count($warehouse_list) > 1)}{literal} - $('#warehouse').show(); - {/literal}{/if}{literal} - } - - function hideWarehouseList() - { - $('#warehouse').hide(); - } - - $(document).ready(function() { - hideWarehouseList(); - $("input.datepicker").datepicker({ - prevText: '', - nextText: '', - dateFormat: 'yy-mm-dd' - }); - $('#id_order_state').change(function() { - if ($.inArray(parseInt($(this).val()), statesShipped) >= 0) - { - showWarehouseList(); - } - else - { - hideWarehouseList(); - } - }); - }); - {/literal} {if ($HOOK_INVOICE)} @@ -130,11 +97,6 @@ {/foreach} - diff --git a/admin-dev/themes/template/products/quantities.tpl b/admin-dev/themes/template/products/quantities.tpl index 43127eecf..200da4841 100644 --- a/admin-dev/themes/template/products/quantities.tpl +++ b/admin-dev/themes/template/products/quantities.tpl @@ -61,7 +61,7 @@ advanced_stock_management == 1 && $stock_management_active == 1}value="on" checked="checked" {/if} {if $stock_management_active == 0}disabled="disabled" {/if} type="checkbox" name="advanced_stock_management" class="advanced_stock_management" id="advanced_stock_management" /> - +

diff --git a/classes/AdminController.php b/classes/AdminController.php index bc8476cd6..21d523633 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -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; diff --git a/classes/Cart.php b/classes/Cart.php index 47319293a..5155c641d 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -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 ? diff --git a/classes/Product.php b/classes/Product.php index 7ddb3e5a4..fd65248c4 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -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')); diff --git a/classes/order/Order.php b/classes/order/Order.php index afd8a38f3..e54638ccd 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -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'] = '--'; diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php index bebcc8373..9306783be 100644 --- a/classes/order/OrderHistory.php +++ b/classes/order/OrderHistory.php @@ -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); } } diff --git a/classes/order/OrderInvoice.php b/classes/order/OrderInvoice.php index 41701ba58..5a582f3af 100644 --- a/classes/order/OrderInvoice.php +++ b/classes/order/OrderInvoice.php @@ -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'] = '--'; } /** diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 9869feca6..060512aa8 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -226,29 +226,24 @@ class AdminOrdersControllerCore extends AdminController $history = new OrderHistory(); $history->id_order = (int)$id_order; $history->id_employee = (int)$this->context->employee->id; - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && !(int)Tools::getValue('id_warehouse')) - $this->_errors[] = Tools::displayError('An error occurred while changing the status.'); - else - { - $history->changeIdOrderState((int)($newOrderStatusId), (int)($id_order), (int)Tools::getValue('id_warehouse')); - $order = new Order((int)$order->id); - $carrier = new Carrier((int)($order->id_carrier), (int)($order->id_lang)); - $templateVars = array(); - if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') AND $order->shipping_number) - $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url)); - else if ($history->id_order_state == Configuration::get('PS_OS_CHEQUE')) - $templateVars = array( - '{cheque_name}' => (Configuration::get('CHEQUE_NAME') ? Configuration::get('CHEQUE_NAME') : ''), - '{cheque_address_html}' => (Configuration::get('CHEQUE_ADDRESS') ? nl2br(Configuration::get('CHEQUE_ADDRESS')) : '')); - elseif ($history->id_order_state == Configuration::get('PS_OS_BANKWIRE')) - $templateVars = array( - '{bankwire_owner}' => (Configuration::get('BANK_WIRE_OWNER') ? Configuration::get('BANK_WIRE_OWNER') : ''), - '{bankwire_details}' => (Configuration::get('BANK_WIRE_DETAILS') ? nl2br(Configuration::get('BANK_WIRE_DETAILS')) : ''), - '{bankwire_address}' => (Configuration::get('BANK_WIRE_ADDRESS') ? nl2br(Configuration::get('BANK_WIRE_ADDRESS')) : '')); - if ($history->addWithemail(true, $templateVars)) - Tools::redirectAdmin(self::$currentIndex.'&id_order='.$id_order.'&vieworder'.'&token='.$this->token); - $this->_errors[] = Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.'); - } + $history->changeIdOrderState((int)($newOrderStatusId), (int)($id_order)); + $order = new Order((int)$order->id); + $carrier = new Carrier((int)($order->id_carrier), (int)($order->id_lang)); + $templateVars = array(); + if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') AND $order->shipping_number) + $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url)); + else if ($history->id_order_state == Configuration::get('PS_OS_CHEQUE')) + $templateVars = array( + '{cheque_name}' => (Configuration::get('CHEQUE_NAME') ? Configuration::get('CHEQUE_NAME') : ''), + '{cheque_address_html}' => (Configuration::get('CHEQUE_ADDRESS') ? nl2br(Configuration::get('CHEQUE_ADDRESS')) : '')); + elseif ($history->id_order_state == Configuration::get('PS_OS_BANKWIRE')) + $templateVars = array( + '{bankwire_owner}' => (Configuration::get('BANK_WIRE_OWNER') ? Configuration::get('BANK_WIRE_OWNER') : ''), + '{bankwire_details}' => (Configuration::get('BANK_WIRE_DETAILS') ? nl2br(Configuration::get('BANK_WIRE_DETAILS')) : ''), + '{bankwire_address}' => (Configuration::get('BANK_WIRE_ADDRESS') ? nl2br(Configuration::get('BANK_WIRE_ADDRESS')) : '')); + if ($history->addWithemail(true, $templateVars)) + Tools::redirectAdmin(self::$currentIndex.'&id_order='.$id_order.'&vieworder'.'&token='.$this->token); + $this->_errors[] = Tools::displayError('An error occurred while changing the status or was unable to send e-mail to the customer.'); } } else @@ -439,7 +434,13 @@ class AdminOrdersControllerCore extends AdminController // @since 1.5.0 : Advanced Stock Management $product_to_inject = new Product($order_detail->product_id, false, $this->context->language->id, $order->id_shop); - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $order_detail->id_warehouse != 0) + + $product = new Product($order_detail->product_id); + + if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') + && $product->advanced_stock_management + && $order_detail->id_warehouse != 0 + ) { $mvts = StockMvt::getNegativeStockMvts( $order_detail->id_order, @@ -989,10 +990,15 @@ class AdminOrdersControllerCore extends AdminController // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) + + $order_details = $order->getOrderDetailList(); + foreach ($order_details as $order_detail) { - $order_details = $order->getOrderDetailList(); - foreach ($order_details as $order_detail) + $product = new Product($order_detail['product_id']); + + if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') + && $product->advanced_stock_management + ) { $warehouses = Warehouse::getWarehousesByProductId($order_detail['product_id'], $order_detail['product_attribute_id']); foreach ($warehouses as $warehouse) @@ -1098,7 +1104,7 @@ class AdminOrdersControllerCore extends AdminController if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) $combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID()); - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) + if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1) $product['warehouse_list'][$attribute['id_product_attribute']] = Warehouse::getProductWarehouseList($product['id_product'], $attribute['id_product_attribute']); else $product['warehouse_list'][$attribute['id_product_attribute']] = array(); @@ -1107,7 +1113,7 @@ class AdminOrdersControllerCore extends AdminController } - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) + if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1) $product['warehouse_list'][0] = Warehouse::getProductWarehouseList($product['id_product']); else $product['warehouse_list'][0] = array(); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 5df62f1f0..5ae58f6c4 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -3747,10 +3747,10 @@ class AdminProductsControllerCore extends AdminController return Tools::jsonEncode(array('error' => 'Undefined value')); if ((int)Tools::getValue('value') != 1 && (int)Tools::getValue('value') != 0) return Tools::jsonEncode(array('error' => 'Uncorrect value')); - $product->advanced_stock_management = (int)Tools::getValue('value'); - $product->save(); - if (StockAvailable::dependsOnStock($product->id) == 1 && (int)Tools::getValue('value') == 0) - StockAvailable::setProductDependsOnStock($product->id, 0); + $product->advanced_stock_management = (int)Tools::getValue('value'); + $product->save(); + if (StockAvailable::dependsOnStock($product->id) == 1 && (int)Tools::getValue('value') == 0) + StockAvailable::setProductDependsOnStock($product->id, 0); break; }