[-] BO : Bug fixed related to #PSCFV-2490 - Default group should be copied

This commit is contained in:
fBrignoli committed 2012-05-21 15:51:50 +00:00
1 parent 21be2b2b1f
commit d29ad8a556
1 file changed
+41 -32
+41 -32
View File
@@ -248,8 +248,22 @@ class AdminShopControllerCore extends AdminController
protected function afterAdd($new_shop) protected function afterAdd($new_shop)
{ {
if (Tools::getValue('useImportData') && ($import_data = Tools::getValue('importData')) && is_array($import_data)) $import_data = Tools::getValue('importData');
if (Tools::getValue('useImportData') && is_array($import_data))
$new_shop->copyShopData((int)Tools::getValue('importFromShop'), $import_data); $new_shop->copyShopData((int)Tools::getValue('importFromShop'), $import_data);
// copy default data
if (!Tools::getValue('useImportData') || (is_array($import_data) && !isset($import_data['group'])))
{
$sql = 'INSERT INTO `'._DB_PREFIX_.'group_shop` (`id_shop`, `id_group`)
VALUES
('.(int)$new_shop->id.', '.(int)Configuration::get('PS_UNIDENTIFIED_GROUP').'),
('.(int)$new_shop->id.', '.(int)Configuration::get('PS_GUEST_GROUP').'),
('.(int)$new_shop->id.', '.(int)Configuration::get('PS_CUSTOMER_GROUP').')
';
Db::getInstance()->execute($sql);
}
return parent::afterAdd($new_shop); return parent::afterAdd($new_shop);
} }
@@ -540,45 +554,40 @@ class AdminShopControllerCore extends AdminController
$parent_id = (int)Tools::getValue('id_parent', 1); $parent_id = (int)Tools::getValue('id_parent', 1);
$this->afterAdd($object); $this->afterAdd($object);
$this->updateAssoShop($object->id); $this->updateAssoShop($object->id);
// datas to import
$import_data = Tools::getValue('importData');
// specific import for stock
if (isset($import_data['stock_available']) && isset($import_data['product']) && Tools::isSubmit('useImportData'))
{
$id_src_shop = (int)Tools::getValue('importFromShop');
if ($object->getGroup()->share_stock == false)
StockAvailable::copyStockAvailableFromShopToShop($id_src_shop, $object->id);
}
// if we import datas from another shop, we do not update the shop categories
if (!Category::updateFromShop(Tools::getValue('categoryBox'), $object->id))
$this->errors[] = $this->l('You need to select at least the root category.');
// Save and stay on same form // Save and stay on same form
if (!$this->errors) if (Tools::isSubmit('submitAdd'.$this->table.'AndStay'))
{ $this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&update'.$this->table.'&token='.$this->token;
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) // Save and back to parent
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&update'.$this->table.'&token='.$this->token; if (Tools::isSubmit('submitAdd'.$this->table.'AndBackToParent'))
// Save and back to parent $this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$parent_id.'&conf=3&token='.$this->token;
if (Tools::isSubmit('submitAdd'.$this->table.'AndBackToParent')) // Default behavior (save and back)
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$parent_id.'&conf=3&token='.$this->token; if (empty($this->redirect_after))
// Default behavior (save and back) $this->redirect_after = self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=3&token='.$this->token;
if (empty($this->redirect_after))
$this->redirect_after = self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=3&token='.$this->token;
}
} }
} }
$this->errors = array_unique($this->errors); $this->errors = array_unique($this->errors);
if (!empty($this->errors)) if (count($this->errors) > 0)
{ {
// if we have errors, we stay on the form instead of going back to the list $this->display = 'add';
$this->display = 'edit'; return;
return false;
} }
// datas to import
$import_data = Tools::getValue('importData');
// specific import for stock
if (isset($import_data['stock_available']) && isset($import_data['product']) && Tools::isSubmit('useImportData'))
{
$id_src_shop = (int)Tools::getValue('importFromShop');
if ($object->getGroup()->share_stock == false)
StockAvailable::copyStockAvailableFromShopToShop($id_src_shop, $object->id);
}
// if we import datas from another shop, we do not update the shop categories
if (!isset($import_data['category']))
Category::updateFromShop(Tools::getValue('categoryBox'), $object->id);
return $object; return $object;
} }