diff --git a/admin-dev/themes/template/supplier_orders/form.tpl b/admin-dev/themes/template/supplier_orders/form.tpl index b51f33e0d..1c60410ae 100644 --- a/admin-dev/themes/template/supplier_orders/form.tpl +++ b/admin-dev/themes/template/supplier_orders/form.tpl @@ -35,7 +35,7 @@
Supplier Order Management - Ad an manage products of the current supplier Order + Add an manage products of the current supplier Order

{l s='To add a product to the order, begin typing the first letters of the product name, then select the product from the drop-down list:'}

@@ -95,7 +95,7 @@ - + {l s='Remove this product from the order'} @@ -133,10 +133,10 @@ ''+product_infos.ean13+''+ ''+product_infos.name+''+ ''+ - ''+ + ''+ ''+ ''+ - ''+ + ''+ '{l s='+ '' ); @@ -158,14 +158,18 @@ $(function() { // add click event on just created delete item link $('a.removeProductFromSupplierOrderLink').live('click', function() { + var id = $(this).attr('id'); var product_id = id.split('|')[1]; //find the position of the product id in product_id array var position = product_ids.indexOf(product_id); - + console.log(product_ids); + console.log(product_id); + console.log(position); if (position != -1) { + console.log('test3'); //remove the id from the array product_ids.splice(position, 1); diff --git a/controllers/admin/AdminStockCoverController.php b/controllers/admin/AdminStockCoverController.php index 0dfed0d18..48210d51d 100644 --- a/controllers/admin/AdminStockCoverController.php +++ b/controllers/admin/AdminStockCoverController.php @@ -143,7 +143,7 @@ class AdminStockCoverControllerCore extends AdminController $this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations, s.physical_quantity as stock'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product) INNER JOIN `'._DB_PREFIX_.'stock` s ON (s.id_product = a.id_product)'; - $this->_where = 'AND s.id_product_attribute = 0'; + if ($this->getCurrentCoverageWarehouse() != -1) $this->_where .= ' AND s.id_warehouse = '.$this->getCurrentCoverageWarehouse(); diff --git a/controllers/admin/AdminSupplierOrdersController.php b/controllers/admin/AdminSupplierOrdersController.php index 0aa3fba8f..67b36746f 100644 --- a/controllers/admin/AdminSupplierOrdersController.php +++ b/controllers/admin/AdminSupplierOrdersController.php @@ -355,7 +355,7 @@ class AdminSupplierOrdersControllerCore extends AdminController ), ), 'submit' => array( - 'title' => $this->l(' Save order modifications '), + 'title' => $this->l(' Save order '), ) ); @@ -881,6 +881,7 @@ class AdminSupplierOrdersControllerCore extends AdminController if ($id_supplier_order != null) { $supplier_order = new SupplierOrder($id_supplier_order); + $products_already_in_order = $supplier_order->getEntries(); $currency = new Currency($supplier_order->id_ref_currency); if (Validate::isLoadedObject($supplier_order)) @@ -901,7 +902,7 @@ class AdminSupplierOrdersControllerCore extends AdminController $product_ids_str = Tools::getValue('product_ids', null); $product_ids = explode('|', $product_ids_str); - // updates existing products ids + // manage each product foreach ($product_ids as $id) { $errors = array(); @@ -969,6 +970,25 @@ class AdminSupplierOrdersControllerCore extends AdminController else $entry->save(); } + + //delete products that are not managed anymore + foreach ($products_already_in_order as $paio) + { + $product_ok = false; + + foreach ($product_ids as $id) + { + $id_check = $paio['id_product'].'_'.$paio['id_product_attribute']; + if ($id_check == $id) + $product_ok = true; + } + + if ($product_ok === false) + { + $entry = new SupplierOrderDetail($paio['id_supplier_order_detail']); + $entry->delete(); + } + } } } }