From 6a4eb7e768115cb26bea7564c38dccc123b55711 Mon Sep 17 00:00:00 2001 From: bMancone Date: Thu, 22 Dec 2011 11:09:33 +0000 Subject: [PATCH] // AdminWarehousesController: fixed association with carriers. Warehouse: fixed association with carriers. Carrier: norm & tags. AdminProductsController: added warning when using the advanced stock management without assocations with warehouses/carriers git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11582 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Carrier.php | 46 ++++++++++++------- classes/stock/Warehouse.php | 6 ++- controllers/admin/AdminProductsController.php | 37 +++++++++++++-- .../admin/AdminWarehousesController.php | 3 +- 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/classes/Carrier.php b/classes/Carrier.php index 078ad0931..c6e0cf4b2 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -185,6 +185,10 @@ class CarrierCore extends ObjectModel return true; } + /** + * @since 1.5.0 + * @see ObjectModel::delete() + */ public function delete() { if (!parent::delete()) @@ -640,8 +644,9 @@ class CarrierCore extends ObjectModel } /** - * Get a specific group + * Gets a specific group * + * @since 1.5.0 * @return array Group */ public function getGroups() @@ -680,6 +685,7 @@ class CarrierCore extends ObjectModel * Add new delivery prices * * @param array $priceList Prices list in multiple arrays (changed to array since 1.5.0) + * @param Shop $shop Optionnal * @return boolean Insertion result */ public function addDeliveryPrice($price_list, Shop $shop = null) @@ -859,6 +865,10 @@ class CarrierCore extends ObjectModel return $suffix; } + /** + * + * @param int $id_carrier + */ public static function getIdTaxRulesGroupByIdCarrier($id_carrier) { if (!isset(self::$cache_tax_rule[(int)$id_carrier])) @@ -874,10 +884,11 @@ class CarrierCore extends ObjectModel /** - * Return the taxes rate associated to the carrier + * Returns the taxes rate associated to the carrier * * @since 1.5 * @param Address $address + * @return */ public function getTaxesRate(Address $address) { @@ -887,7 +898,7 @@ class CarrierCore extends ObjectModel } /** - * This tricky method generate a sql clause to check if ranged data are overloaded by multishop + * This tricky method generates a sql clause to check if ranged data are overloaded by multishop * * @since 1.5.0 * @param string $rangeTable @@ -923,8 +934,10 @@ class CarrierCore extends ObjectModel } /** - * Move a carrier - * @param boolean $way Up (1) or Down (0) + * Moves a carrier + * + * @since 1.5.0 + * @param boolean $way Up (1) or Down (0) * @param integer $position * @return boolean Update result */ @@ -962,9 +975,10 @@ class CarrierCore extends ObjectModel } /** - * Reorder carrier position. - * Call it after deleting a carrier. + * Reorders carrier positions. + * Called after deleting a carrier. * + * @since 1.5.0 * @return bool $return */ public static function cleanPositions() @@ -988,11 +1002,10 @@ class CarrierCore extends ObjectModel } /** - * getHigherPosition + * Gets the highest carrier position * - * Get the higher carrier position - * - * @return integer $position + * @since 1.5.0 + * @return int $position */ public static function getHigherPosition() { @@ -1000,17 +1013,19 @@ class CarrierCore extends ObjectModel FROM `'._DB_PREFIX_.'carrier` WHERE `deleted` = 0'; $position = DB::getInstance()->getValue($sql); - return ($position !== false) ? $position : -1; + return ($position !== false) ? (int)$position : -1; } /** * For a given {product, warehouse}, gets the carrier available * + * @since 1.5.0 * @param $product integer The id of the product, or an array with at least the package size and weight + * @return array */ public static function getAvailableCarrierList($product, $id_warehouse, $id_shop = null) { - if(is_numeric($product)) + if (is_numeric($product)) $product = new Product((int)$product); else if (is_array($product)) { @@ -1026,7 +1041,7 @@ class CarrierCore extends ObjectModel $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0'); - $query->where('id_product = '.(int)($product->id)); + $query->where('id_product = '.(int)$product->id); $query->where('id_shop = '.(int)$id_shop); $carriers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); if (!empty($carriers)) @@ -1066,8 +1081,7 @@ class CarrierCore extends ObjectModel if (($carrier->max_width > 0 && $carrier->max_width < $product->width) || ($carrier->max_height > 0 && $carrier->max_height > $product->height) || ($carrier->max_depth > 0 && $carrier->max_depth > $product->depth) - || ($carrier->max_weight > 0 && $carrier->max_weight > $product->weight) - ) + || ($carrier->max_weight > 0 && $carrier->max_weight > $product->weight)) unset($carrier_list[$key]); } } diff --git a/classes/stock/Warehouse.php b/classes/stock/Warehouse.php index d5952dfb3..b2c6685cb 100644 --- a/classes/stock/Warehouse.php +++ b/classes/stock/Warehouse.php @@ -175,6 +175,9 @@ class WarehouseCore extends ObjectModel */ public function setCarriers($ids_carriers) { + if (!is_array($ids_carriers)) + $ids_carriers = array(); + $row_to_insert = array(); foreach ($ids_carriers as $id_carrier) $row_to_insert[] = array($this->def['primary'] => $this->id, 'id_carrier' => (int)$id_carrier); @@ -183,7 +186,8 @@ class WarehouseCore extends ObjectModel DELETE FROM '._DB_PREFIX_.'warehouse_carrier WHERE '.$this->def['primary'].' = '.(int)$this->id); - Db::getInstance()->autoExecute(_DB_PREFIX_.'warehouse_carrier', $row_to_insert, 'INSERT'); + if ($row_to_insert) + Db::getInstance()->autoExecute(_DB_PREFIX_.'warehouse_carrier', $row_to_insert, 'INSERT'); } /** diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index d0f3bdf7e..d4dbb713d 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -3497,6 +3497,35 @@ class AdminProductsControllerCore extends AdminController if (Combination::isFeatureActive()) $data->assign('countAttributes', (int)Db::getInstance()->getValue('SELECT COUNT(id_product) FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.(int)$obj->id)); + // if advanced stock management is active, checks associations : product and warehouse, product/warehouse and carriers + $advanced_stock_management_warning = false; + if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $obj->advanced_stock_management) + { + $attributes = Product::getProductAttributesIds($obj->id); + $warehouses = array(); + foreach ($attributes as $attribute) + $warehouses[] = Warehouse::getProductWarehouseList($obj->id, $attribute['id_product_attribute']); + $warehouses = array_unique($warehouses); + + $carriers = array(); + foreach ($warehouses as $warehouse_list) + { + foreach ($warehouse_list as $warehouse) + $carriers[] = Carrier::getAvailableCarrierList($obj->id, $warehouse['id_warehouse']); + } + $carriers = array_unique($carriers); + + if (empty($warehouses) || empty($carriers)) + $advanced_stock_management_warning = true; + } + if ($advanced_stock_management_warning) + { + $this->displayWarning($this->l('If you wish to use the advanced stock management, you have to:')); + $this->displayWarning('- '.$this->l('associates your products with warehouses.')); + $this->displayWarning('- '.$this->l('associates your warehouses with carriers')); + $this->displayWarning('- '.$this->l('associates your warehouses with the appropriates shops')); + } + $data->assign(array( 'attributes' => $attributes, 'available_quantity' => $available_quantity, @@ -3506,11 +3535,11 @@ class AdminProductsControllerCore extends AdminController 'show_quantities' => $show_quantities, 'token_preferences' => Tools::getAdminTokenLite('AdminPPreferences'), 'token' => $this->token, - 'languages' => $languages + 'languages' => $languages, )); } else - $this->displayWarning($this->l('You must save this product before manage quantities.')); + $this->displayWarning($this->l('You must save this product before managing quantities.')); $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } @@ -3582,7 +3611,7 @@ class AdminProductsControllerCore extends AdminController )); } else - $this->displayWarning($this->l('You must save this product before manage suppliers')); + $this->displayWarning($this->l('You must save this product before managing suppliers')); $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } @@ -3627,7 +3656,7 @@ class AdminProductsControllerCore extends AdminController )); } else - $this->displayWarning($this->l('You must save this product before manage warehouses')); + $this->displayWarning($this->l('You must save this product before managing warehouses')); $this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch(); } diff --git a/controllers/admin/AdminWarehousesController.php b/controllers/admin/AdminWarehousesController.php index be6265413..9d6b66699 100644 --- a/controllers/admin/AdminWarehousesController.php +++ b/controllers/admin/AdminWarehousesController.php @@ -389,8 +389,7 @@ class AdminWarehousesControllerCore extends AdminController $obj->setShops(Tools::getValue('ids_shops')); // handles carriers associations - if (Tools::isSubmit('ids_carriers')) - $obj->setCarriers(Tools::getValue('ids_carriers')); + $obj->setCarriers(Tools::getValue('ids_carriers')); // updates/creates address if it does not exist if (Tools::isSubmit('id_address') && (int)Tools::getValue('id_address') > 0)