// 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
This commit is contained in:
+30
-16
@@ -185,6 +185,10 @@ class CarrierCore extends ObjectModel
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.5.0
|
||||||
|
* @see ObjectModel::delete()
|
||||||
|
*/
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
if (!parent::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
|
* @return array Group
|
||||||
*/
|
*/
|
||||||
public function getGroups()
|
public function getGroups()
|
||||||
@@ -680,6 +685,7 @@ class CarrierCore extends ObjectModel
|
|||||||
* Add new delivery prices
|
* Add new delivery prices
|
||||||
*
|
*
|
||||||
* @param array $priceList Prices list in multiple arrays (changed to array since 1.5.0)
|
* @param array $priceList Prices list in multiple arrays (changed to array since 1.5.0)
|
||||||
|
* @param Shop $shop Optionnal
|
||||||
* @return boolean Insertion result
|
* @return boolean Insertion result
|
||||||
*/
|
*/
|
||||||
public function addDeliveryPrice($price_list, Shop $shop = null)
|
public function addDeliveryPrice($price_list, Shop $shop = null)
|
||||||
@@ -859,6 +865,10 @@ class CarrierCore extends ObjectModel
|
|||||||
return $suffix;
|
return $suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $id_carrier
|
||||||
|
*/
|
||||||
public static function getIdTaxRulesGroupByIdCarrier($id_carrier)
|
public static function getIdTaxRulesGroupByIdCarrier($id_carrier)
|
||||||
{
|
{
|
||||||
if (!isset(self::$cache_tax_rule[(int)$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
|
* @since 1.5
|
||||||
* @param Address $address
|
* @param Address $address
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public function getTaxesRate(Address $address)
|
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
|
* @since 1.5.0
|
||||||
* @param string $rangeTable
|
* @param string $rangeTable
|
||||||
@@ -923,8 +934,10 @@ class CarrierCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move a carrier
|
* Moves a carrier
|
||||||
* @param boolean $way Up (1) or Down (0)
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
* @param boolean $way Up (1) or Down (0)
|
||||||
* @param integer $position
|
* @param integer $position
|
||||||
* @return boolean Update result
|
* @return boolean Update result
|
||||||
*/
|
*/
|
||||||
@@ -962,9 +975,10 @@ class CarrierCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reorder carrier position.
|
* Reorders carrier positions.
|
||||||
* Call it after deleting a carrier.
|
* Called after deleting a carrier.
|
||||||
*
|
*
|
||||||
|
* @since 1.5.0
|
||||||
* @return bool $return
|
* @return bool $return
|
||||||
*/
|
*/
|
||||||
public static function cleanPositions()
|
public static function cleanPositions()
|
||||||
@@ -988,11 +1002,10 @@ class CarrierCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getHigherPosition
|
* Gets the highest carrier position
|
||||||
*
|
*
|
||||||
* Get the higher carrier position
|
* @since 1.5.0
|
||||||
*
|
* @return int $position
|
||||||
* @return integer $position
|
|
||||||
*/
|
*/
|
||||||
public static function getHigherPosition()
|
public static function getHigherPosition()
|
||||||
{
|
{
|
||||||
@@ -1000,17 +1013,19 @@ class CarrierCore extends ObjectModel
|
|||||||
FROM `'._DB_PREFIX_.'carrier`
|
FROM `'._DB_PREFIX_.'carrier`
|
||||||
WHERE `deleted` = 0';
|
WHERE `deleted` = 0';
|
||||||
$position = DB::getInstance()->getValue($sql);
|
$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
|
* 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
|
* @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)
|
public static function getAvailableCarrierList($product, $id_warehouse, $id_shop = null)
|
||||||
{
|
{
|
||||||
if(is_numeric($product))
|
if (is_numeric($product))
|
||||||
$product = new Product((int)$product);
|
$product = new Product((int)$product);
|
||||||
else if (is_array($product))
|
else if (is_array($product))
|
||||||
{
|
{
|
||||||
@@ -1026,7 +1041,7 @@ class CarrierCore extends ObjectModel
|
|||||||
$query->select('id_carrier');
|
$query->select('id_carrier');
|
||||||
$query->from('product_carrier', 'pc');
|
$query->from('product_carrier', 'pc');
|
||||||
$query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0');
|
$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);
|
$query->where('id_shop = '.(int)$id_shop);
|
||||||
$carriers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
$carriers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||||
if (!empty($carriers))
|
if (!empty($carriers))
|
||||||
@@ -1066,8 +1081,7 @@ class CarrierCore extends ObjectModel
|
|||||||
if (($carrier->max_width > 0 && $carrier->max_width < $product->width)
|
if (($carrier->max_width > 0 && $carrier->max_width < $product->width)
|
||||||
|| ($carrier->max_height > 0 && $carrier->max_height > $product->height)
|
|| ($carrier->max_height > 0 && $carrier->max_height > $product->height)
|
||||||
|| ($carrier->max_depth > 0 && $carrier->max_depth > $product->depth)
|
|| ($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]);
|
unset($carrier_list[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,6 +175,9 @@ class WarehouseCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public function setCarriers($ids_carriers)
|
public function setCarriers($ids_carriers)
|
||||||
{
|
{
|
||||||
|
if (!is_array($ids_carriers))
|
||||||
|
$ids_carriers = array();
|
||||||
|
|
||||||
$row_to_insert = array();
|
$row_to_insert = array();
|
||||||
foreach ($ids_carriers as $id_carrier)
|
foreach ($ids_carriers as $id_carrier)
|
||||||
$row_to_insert[] = array($this->def['primary'] => $this->id, 'id_carrier' => (int)$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
|
DELETE FROM '._DB_PREFIX_.'warehouse_carrier
|
||||||
WHERE '.$this->def['primary'].' = '.(int)$this->id);
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3497,6 +3497,35 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
if (Combination::isFeatureActive())
|
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));
|
$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(
|
$data->assign(array(
|
||||||
'attributes' => $attributes,
|
'attributes' => $attributes,
|
||||||
'available_quantity' => $available_quantity,
|
'available_quantity' => $available_quantity,
|
||||||
@@ -3506,11 +3535,11 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
'show_quantities' => $show_quantities,
|
'show_quantities' => $show_quantities,
|
||||||
'token_preferences' => Tools::getAdminTokenLite('AdminPPreferences'),
|
'token_preferences' => Tools::getAdminTokenLite('AdminPPreferences'),
|
||||||
'token' => $this->token,
|
'token' => $this->token,
|
||||||
'languages' => $languages
|
'languages' => $languages,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
else
|
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();
|
$this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch();
|
||||||
}
|
}
|
||||||
@@ -3582,7 +3611,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
else
|
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();
|
$this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch();
|
||||||
}
|
}
|
||||||
@@ -3627,7 +3656,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
else
|
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();
|
$this->tpl_form_vars['custom_form'] = $this->context->smarty->createTemplate($this->tpl_form, $data)->fetch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -389,8 +389,7 @@ class AdminWarehousesControllerCore extends AdminController
|
|||||||
$obj->setShops(Tools::getValue('ids_shops'));
|
$obj->setShops(Tools::getValue('ids_shops'));
|
||||||
|
|
||||||
// handles carriers associations
|
// 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
|
// updates/creates address if it does not exist
|
||||||
if (Tools::isSubmit('id_address') && (int)Tools::getValue('id_address') > 0)
|
if (Tools::isSubmit('id_address') && (int)Tools::getValue('id_address') > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user