[-] BO: Fix #PSCFV-7646 JS error when adding a product existing in an other shop
This commit is contained in:
@@ -193,7 +193,7 @@
|
||||
<p>
|
||||
<script>
|
||||
var no_related_product = '{l s='No related product'}';
|
||||
var id_product_redirected = {$product->id_product_redirected|escape:html:'UTF-8'};
|
||||
var id_product_redirected = {$product->id_product_redirected|intval};
|
||||
var product_name_redirected = '{$product_name_redirected|escape:html:'UTF-8'}';
|
||||
</script>
|
||||
<span id="related_product_name">{l s='No related product'}</span>
|
||||
|
||||
@@ -1162,27 +1162,6 @@ class AdminProductsControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent to add stock data to object
|
||||
* We don't want to make a "full" product load because of side effects to prices
|
||||
*
|
||||
* @param boolean $opt Return an empty object if load fail
|
||||
* @return object
|
||||
*/
|
||||
protected function loadObject($opt = false)
|
||||
{
|
||||
$result = parent::loadObject($opt);
|
||||
if ($result)
|
||||
{
|
||||
if ($this->object->id)
|
||||
if (!$this->object->isAssociatedToShop() && $this->object->id_shop_default)
|
||||
$this->object = new $this->className((int)$this->object->id, false, null, (int)$this->object->id_shop_default);
|
||||
|
||||
$this->object->loadStockData();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* postProcess handle every checks before saving products information
|
||||
*
|
||||
@@ -2352,33 +2331,6 @@ class AdminProductsControllerCore extends AdminController
|
||||
return;
|
||||
|
||||
$product = $this->object;
|
||||
$this->product_exists_in_shop = true;
|
||||
if ($this->display == 'edit' && Validate::isLoadedObject($product) && Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP && !$product->isAssociatedToShop($this->context->shop->id))
|
||||
{
|
||||
$this->product_exists_in_shop = false;
|
||||
if ($this->tab_display == 'Informations')
|
||||
$this->displayWarning($this->l('Warning: The product does not exist in this shop.'));
|
||||
|
||||
$default_product = new Product();
|
||||
$fields_to_copy = array('minimal_quantity',
|
||||
'price',
|
||||
'additional_shipping_cost',
|
||||
'wholesale_price',
|
||||
'on_sale',
|
||||
'online_only',
|
||||
'unity',
|
||||
'unit_price_ratio',
|
||||
'ecotax',
|
||||
'active',
|
||||
'available_for_order',
|
||||
'available_date',
|
||||
'show_price',
|
||||
'indexed',
|
||||
'id_tax_rules_group',
|
||||
'advanced_stock_management');
|
||||
foreach ($fields_to_copy as $field)
|
||||
$product->$field = $default_product->$field;
|
||||
}
|
||||
|
||||
// Product for multishop
|
||||
$this->context->smarty->assign('bullet_common_field', '');
|
||||
@@ -2441,6 +2393,20 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->tpl_form_vars['country_display_tax_label'] = $this->context->country->display_tax_label;
|
||||
$this->tpl_form_vars['has_combinations'] = $this->object->hasAttributes();
|
||||
|
||||
$this->product_exists_in_shop = true;
|
||||
if ($this->display == 'edit' && Validate::isLoadedObject($product) && Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP && !$product->isAssociatedToShop($this->context->shop->id))
|
||||
{
|
||||
$this->product_exists_in_shop = false;
|
||||
if ($this->tab_display == 'Informations')
|
||||
$this->displayWarning($this->l('Warning: The product does not exist in this shop.'));
|
||||
|
||||
$default_product = new Product();
|
||||
$definition = ObjectModel::getDefinition($product);
|
||||
foreach ($definition['fields'] as $field_name => $field)
|
||||
if (isset($field['shop']) && $field['shop'])
|
||||
$product->$field_name = ObjectModel::formatValue($default_product->$field_name, $field['type']);
|
||||
}
|
||||
|
||||
// let's calculate this once for all
|
||||
if (!Validate::isLoadedObject($this->object) && Tools::getValue('id_product'))
|
||||
$this->errors[] = 'Unable to load object';
|
||||
|
||||
Reference in New Issue
Block a user