diff --git a/admin-dev/themes/template/products/combinations.tpl b/admin-dev/themes/template/products/combinations.tpl index d061f0185..012a757b5 100644 --- a/admin-dev/themes/template/products/combinations.tpl +++ b/admin-dev/themes/template/products/combinations.tpl @@ -100,8 +100,6 @@ {l s='EAN13:'} {l s='UPC:'} {l s='Special characters allowed:'} .-_#  - {l s='Location:'} - {l s='Special characters allowed:'} .-_#  diff --git a/admin-dev/themes/template/products/informations.tpl b/admin-dev/themes/template/products/informations.tpl index e676bf32b..15cb241a8 100644 --- a/admin-dev/themes/template/products/informations.tpl +++ b/admin-dev/themes/template/products/informations.tpl @@ -126,12 +126,6 @@ {l s='(US, Canada)'} - - - - - - {* status informations *} diff --git a/admin-dev/themes/template/products/suppliers.tpl b/admin-dev/themes/template/products/suppliers.tpl index a940860e3..89433c2aa 100644 --- a/admin-dev/themes/template/products/suppliers.tpl +++ b/admin-dev/themes/template/products/suppliers.tpl @@ -39,6 +39,7 @@
+

 

@@ -54,42 +55,48 @@

{l s='You can specify product reference(s) for each supplier associated.'}

- - - - - - -
- - - - - {foreach from=$associated_suppliers item=supplier} - - {/foreach} - - - - {foreach from=$attributes item=attribute} - - - {foreach from=$associated_suppliers item=supplier} - {assign var=reference value=''} - {foreach from=$associated_suppliers_collection item=asc} - {if $asc->id_product == $attribute['id_product'] && $asc->id_product_attribute == $attribute['id_product_attribute'] && $asc->id_supplier == $supplier->id_supplier} - {assign var=reference value=$asc->product_supplier_reference} - {/if} - {/foreach} - - {/foreach} - + +
+ {foreach from=$associated_suppliers item=supplier} +

{$supplier->name}

+
+
{l s='Product Name'}{$supplier->name}
{$product_designation[$attribute['id_product_attribute']]} - -
+ + + + + + + + {foreach from=$attributes item=attribute} + {assign var=reference value=''} + {foreach from=$associated_suppliers_collection item=asc} + {if $asc->id_product == $attribute['id_product'] && $asc->id_product_attribute == $attribute['id_product_attribute'] && $asc->id_supplier == $supplier->id_supplier} + {assign var=reference value=$asc->product_supplier_reference} + {/if} {/foreach} - -
{l s='product name'}{l s='supplier reference'}
-
+ + {$product_designation[$attribute['id_product_attribute']]} + + + + + {/foreach} + + + + {/foreach} + + +

 

+ + \ No newline at end of file diff --git a/admin-dev/themes/template/products/warehouses.tpl b/admin-dev/themes/template/products/warehouses.tpl new file mode 100644 index 000000000..f0ee0e0b3 --- /dev/null +++ b/admin-dev/themes/template/products/warehouses.tpl @@ -0,0 +1,69 @@ + + + + + + +
+ {l s='Product location in warehouses'} +
+
+

{l s='Please choose the warehouses associated to this product, and the default one.'}

+ +{assign var=confirm value="Are you sure you want to delete entered product information?"} + + + {l s='Create new warehouse'} {l s='Create new warehouse'} + + + + +
+ {foreach from=$warehouses item=warehouse} +

{$warehouse['name']}

+
+ + + + + + + {foreach from=$attributes item=attribute} + {assign var=location value=''} + {assign var=selected value=''} + {foreach from=$associated_warehouses item=aw} + {if $aw->id_product == $attribute['id_product'] && $aw->id_product_attribute == $attribute['id_product_attribute'] && $aw->id_warehouse == $warehouse['id_warehouse']} + {assign var=location value=$aw->location} + {assign var=selected value=true} + {/if} + {/foreach} + + + + + + {/foreach} +
{l s='In the warehouse?'}{l s='product name'}{l s='location in the warehouse (optionnal)'}
+ {$product_designation[$attribute['id_product_attribute']]} +
+
+ {/foreach} +
+

 

+
+ +
+ + \ No newline at end of file diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 52d9d9220..79a2029ff 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -45,6 +45,7 @@ class AdminProductsControllerCore extends AdminController 'Attachments', 'Quantities', 'Suppliers', + 'Warehouses', 'Accounting'); public function __construct() @@ -912,7 +913,9 @@ class AdminProductsControllerCore extends AdminController //Manage suppliers else if (Tools::isSubmit('submitSupplierReferences')) $this->postProcessFormSupplierReferences(); - + //Manage warehouses + else if (Tools::isSubmit('submitProductWarehouses')) + $this->postProcessFormWarehouses(); parent::postProcess(true); } @@ -1783,6 +1786,7 @@ class AdminProductsControllerCore extends AdminController $this->addJs(_PS_JS_DIR_.'attributesBack.js'); $this->display = 'edit'; $this->addJqueryUI('ui.datepicker'); + $this->addJqueryUI('ui.accordion'); $this->tpl_form_vars['pos_select'] = ($tab = Tools::getValue('tabs')) ? $tab : '0'; $this->tpl_form_vars['token'] = $this->token; $this->tpl_form_vars['combinationImagesJs'] = $this->getCombinationImagesJs(); @@ -1983,7 +1987,7 @@ class AdminProductsControllerCore extends AdminController if ($reference != $psc->product_supplier_reference) { $psc->product_supplier_reference = pSQL($reference); - $psc->save(); + $psc->update(); } break; } @@ -1995,6 +1999,88 @@ class AdminProductsControllerCore extends AdminController } } + /** + * Post traitment for warehouses + */ + public function postProcessFormWarehouses() + { + if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product')))) + { + // Get all id_product_attribute + $attributes = $product->getAttributesResume($this->context->language->id); + if (empty($attributes)) + $attributes[] = array( + 'id_product_attribute' => 0, + 'attribute_designation' => '' + ); + + // Get all available warehouses + $warehouses = Warehouse::getWarehouses(true); + + // Get already associated warehouses + $associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id); + + $elements_to_manage = array(); + + // get form inforamtion + foreach ($attributes as $attribute) + { + foreach ($warehouses as $warehouse) + { + $key = $warehouse['id_warehouse'].'_'.$attribute['id_product'].'_'.$attribute['id_product_attribute']; + + // get elements to manage + if (Tools::isSubmit('check_warehouse_'.$key)) + { + $location = Tools::getValue('location_warehouse_'.$key, ''); + $elements_to_manage[$key] = $location; + } + } + } + + // Delete entry if necessary + foreach ($associated_warehouses_collection as $awc) + { + if (!array_key_exists($awc->id_warehouse.'_'.$awc->id_product.'_'.$awc->id_product_attribute, $elements_to_manage)) + $awc->delete(); + } + + // Manage locations + foreach ($elements_to_manage as $key => $location) + { + $params = explode('_', $key); + + $wpl_id = WarehouseProductLocation::getIdByProductAndWarehouse($params[1], $params[2], $params[0]); + + if (empty($wpl_id)) + { + //create new record + $warehouse_location_entity = new WarehouseProductLocation(); + $warehouse_location_entity->id_product = $params[1]; + $warehouse_location_entity->id_product_attribute = $params[2]; + $warehouse_location_entity->id_warehouse = $params[0]; + $warehouse_location_entity->location = pSQL($location); + $warehouse_location_entity->save(); + } + else + { + $warehouse_location_entity = new WarehouseProductLocation($wpl_id); + + $location = pSQL($location); + + if ($location != $warehouse_location_entity->location) + { + $warehouse_location_entity->location = pSQL($location); + $warehouse_location_entity->update(); + } + break; + } + } + + $this->confirmations[] = $this->l('Warehouses and location(s) of the product have been updated'); + } + } + /** * Init data for accounting */ @@ -2476,11 +2562,11 @@ class AdminProductsControllerCore extends AdminController // @todo : uses the helperform $data->assign('displayAssoShop', $this->displayAssoShop()); $data->assign('carrier_list', $this->getCarrierList()); - + $product_props = array(); // global informations - array_push($product_props, 'reference', 'ean13', 'upc', 'location', + array_push($product_props, 'reference', 'ean13', 'upc', 'available_for_order', 'show_price', 'online_only', 'id_manufacturer' ); @@ -2756,7 +2842,7 @@ class AdminProductsControllerCore extends AdminController $this->tpl_form_vars['product'] = $product; $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } - + protected function getCarrierList() { $carrier_list = Carrier::getCarriers($this->context->language->id); @@ -2773,7 +2859,7 @@ class AdminProductsControllerCore extends AdminController } return $carrier_list; } - + protected function addCarriers() { if (Tools::getValue('carriers')) @@ -2785,7 +2871,7 @@ class AdminProductsControllerCore extends AdminController } } } - + public function initFormImages($obj, $token = null) { $this->addJs('admin-dnd'); @@ -2931,7 +3017,6 @@ class AdminProductsControllerCore extends AdminController $combArray[$combinaison['id_product_attribute']]['upc'] = $combinaison['upc']; $combArray[$combinaison['id_product_attribute']]['minimal_quantity'] = $combinaison['minimal_quantity']; $combArray[$combinaison['id_product_attribute']]['available_date'] = strftime($combinaison['available_date']); - $combArray[$combinaison['id_product_attribute']]['location'] = $combinaison['location']; $combArray[$combinaison['id_product_attribute']]['id_image'] = isset($combinationImages[$combinaison['id_product_attribute']][0]['id_image']) ? $combinationImages[$combinaison['id_product_attribute']][0]['id_image'] : 0; $combArray[$combinaison['id_product_attribute']]['default_on'] = $combinaison['default_on']; $combArray[$combinaison['id_product_attribute']]['ecotax'] = $combinaison['ecotax']; @@ -3003,7 +3088,7 @@ class AdminProductsControllerCore extends AdminController '.$this->l('Modify this combination').'  '.(!$product_attribute['default_on'] ? ' '.$this->l('Make this the default combination').'' : '').' @@ -3172,6 +3257,47 @@ class AdminProductsControllerCore extends AdminController $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } + public function initFormWarehouses($obj) + { + $data = $this->context->smarty->createData(); + + if ($this->object->id) + { + // Get all id_product_attribute + $attributes = $obj->getAttributesResume($this->context->language->id); + if (empty($attributes)) + $attributes[] = array( + 'id_product_attribute' => 0, + 'attribute_designation' => '' + ); + + $product_designation = array(); + + foreach ($attributes as $attribute) + $product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id].' - '.$attribute['attribute_designation'], ' - '); + + // Get all available warehouses + $warehouses = Warehouse::getWarehouses(true); + + // Get already associated warehouses + $associated_warehouses_collection = WarehouseProductLocation::getCollection($this->object->id); + + $data->assign(array( + 'attributes' => $attributes, + 'warehouses' => $warehouses, + 'associated_warehouses' => $associated_warehouses_collection, + 'product_designation' => $product_designation, + 'product' => $this->object, + 'link' => $this->context->link, + 'token' => $this->token + )); + } + else + $data->assign('content', ''.$this->l('You must save this product before manage warehouses').'.'); + + $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); + } + public function initFormFeatures($obj) { if (!Feature::isFeatureActive()) diff --git a/controllers/admin/AdminStockMvtController.php b/controllers/admin/AdminStockMvtController.php index 5249e3fd1..b4ed1e036 100644 --- a/controllers/admin/AdminStockMvtController.php +++ b/controllers/admin/AdminStockMvtController.php @@ -280,7 +280,7 @@ class AdminStockMvtControllerCore extends AdminController ), 'reason' => array( 'title' => $this->l('Reason'), - 'width' => 250, + 'width' => 100, 'havingFilter' => true ), 'employee' => array( diff --git a/controllers/admin/AdminSupplyOrdersController.php b/controllers/admin/AdminSupplyOrdersController.php index d366c0f2d..5cf0a7655 100644 --- a/controllers/admin/AdminSupplyOrdersController.php +++ b/controllers/admin/AdminSupplyOrdersController.php @@ -518,22 +518,22 @@ class AdminSupplyOrdersControllerCore extends AdminController $this->fieldsDisplay = array( 'reference' => array( 'title' => $this->l('Order Reference'), - 'width' => 120, + 'width' => 100, 'havingFilter' => true ), 'supplier' => array( 'title' => $this->l('Supplier'), - 'width' => 200, + 'width' => 100, 'filter_key' => 's!name' ), 'warehouse' => array( 'title' => $this->l('Warehouse'), - 'width' => 200, + 'width' => 100, 'filter_key' => 'w!name' ), 'state' => array( 'title' => $this->l('State'), - 'width' => 250, + 'width' => 200, 'filter_key' => 'stl!name', 'color' => 'color', ), diff --git a/controllers/admin/AdminWarehousesController.php b/controllers/admin/AdminWarehousesController.php index 03dab5e29..51fcbb3fa 100644 --- a/controllers/admin/AdminWarehousesController.php +++ b/controllers/admin/AdminWarehousesController.php @@ -204,8 +204,8 @@ class AdminWarehousesControllerCore extends AdminController 'type' => 'text', 'label' => $this->l('City:'), 'name' => 'city', - 'size' => 10, - 'maxlength' => 12, + 'size' => 20, + 'maxlength' => 32, 'required' => true, ), array( diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql index 2b453cb29..4e84ec195 100644 --- a/install-dev/sql/db.sql +++ b/install-dev/sql/db.sql @@ -2067,14 +2067,13 @@ CREATE TABLE `PREFIX_warehouse` ( ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE `PREFIX_warehouse_product_location` ( -`id_product` INT(11) UNSIGNED NOT NULL, -`id_product_attribute` INT(11) UNSIGNED NOT NULL, -`id_warehouse` INT(11) UNSIGNED NOT NULL, -`location` VARCHAR(64) DEFAULT NULL, - PRIMARY KEY (`id_product`, `id_product_attribute`, `id_warehouse`), - KEY `id_warehouse` (`id_warehouse`), - KEY `id_product` (`id_product`), - KEY `id_product_attribute` (`id_product_attribute`) + `id_warehouse_product_location` int(11) unsigned NOT NULL AUTO_INCREMENT, + `id_product` int(11) unsigned NOT NULL, + `id_product_attribute` int(11) unsigned NOT NULL, + `id_warehouse` int(11) unsigned NOT NULL, + `location` varchar(64) DEFAULT NULL, + PRIMARY KEY (`id_warehouse_product_location`), + UNIQUE KEY `id_product` (`id_product`,`id_product_attribute`,`id_warehouse`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE `PREFIX_warehouse_shop` ( @@ -2245,4 +2244,4 @@ CREATE TABLE `PREFIX_accounting_product_zone_shop` ( `account_number` varchar(64) NOT NULL, PRIMARY KEY (`id_accounting_product_zone_shop`), UNIQUE KEY `id_product` (`id_product`,`id_shop`,`id_zone`) -) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; \ No newline at end of file +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; diff --git a/js/attributesBack.js b/js/attributesBack.js index eab86ba2d..5562d58e0 100644 --- a/js/attributesBack.js +++ b/js/attributesBack.js @@ -27,7 +27,7 @@ var storeUsedGroups = {}; function fillCombinaison(wholesale_price, price_impact, weight_impact, unit_impact, reference, -ean, quantity, image, old_attr, id_product_attribute, default_attribute, eco_tax, location, upc, minimal_quantity, available_date, +ean, quantity, image, old_attr, id_product_attribute, default_attribute, eco_tax, upc, minimal_quantity, available_date, virtual_product_name_attribute, virtual_product_filename_attribute, virtual_product_nb_downloable, virtual_product_expiration_date_attribute, virtual_product_nb_days, is_shareable) { @@ -59,7 +59,7 @@ virtual_product_nb_days, is_shareable) getE('attribute_unity').value = Math.abs(unit_impact); if ($('#attribute_ecotax').length != 0) getE('attribute_ecotax').value = eco_tax; - getE('attribute_location').value = location; + if (default_attribute == 1) getE('attribute_default').checked = true; else