[*] BO : New category management with multi shop

This commit is contained in:
vChabot
2011-12-20 17:36:08 +00:00
parent 74af9af141
commit 07ac99f5de
14 changed files with 260 additions and 14 deletions
@@ -118,6 +118,9 @@ class AdminCategoriesControllerCore extends AdminController
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
// we add restriction for shop
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON a.`id_category` = cs.`id_category`';
$this->_where = ' AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true);
parent::getList($id_lang, 'position', $order_way, $start, $limit, Context::getContext()->shop->getID(true));
// Check each row to see if there are combinations and get the correct action in consequence
@@ -170,7 +173,8 @@ class AdminCategoriesControllerCore extends AdminController
{
$this->initToolbar();
$obj = $this->loadObject(true);
$selected_cat = array(isset($obj->id_parent) ? $obj->id_parent : Tools::getValue('id_parent', 1));
$id_shop = Context::getContext()->shop->getID(true);
$selected_cat = array((isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? $obj->id_parent : Tools::getValue('id_parent', 1));
$this->fields_form = array(
'tinymce' => true,
+18 -1
View File
@@ -2101,6 +2101,8 @@ class AdminProductsControllerCore extends AdminController
$this->_errors[] = 'Unable to load object';
else
{
if (!Shop::isProductAvailable($this->object->id))
$this->_displayUnavailableProductWarning();
$this->_displayDraftWarning($this->object->active);
$this->{'initForm'.$this->tab_display}($this->object, $languages, $default_language);
$this->tpl_form_vars['product'] = $this->object;
@@ -3836,7 +3838,7 @@ class AdminProductsControllerCore extends AdminController
Pack::deleteItems($product->id);
// lines format: QTY x ID-QTY x ID
if (Tools::getValue('type_product') == 1)
if (Tools::getValue('ppack'))
{
$items = Tools::getValue('inputPackItems');
$lines = array_unique(explode('-', $items));
@@ -3906,4 +3908,19 @@ class AdminProductsControllerCore extends AdminController
$this->addCSS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.css');
}
}
protected function _displayUnavailableProductWarning()
{
$content = '<div class="warn">
<p>
<span style="float: left">
'.$this->l('Your product will be saved as draft').'
</span>
<span style="float:right"><a href="#" class="button" style="display: block" onclick="submitAddProductAndPreview()" >'.$this->l('Save and preview').'</a></span>
<input type="hidden" name="fakeSubmitAddProductAndPreview" id="fakeSubmitAddProductAndPreview" />
<br class="clear" />
</p>
</div>';
$this->tpl_form_vars['warning_unavailable_product'] = $content;
}
}
+70 -1
View File
@@ -213,6 +213,12 @@ class AdminShopControllerCore extends AdminController
)
);
}
$this->fields_form['input'][] = array(
'type' => 'categories_select',
'name' => 'categoryBox',
'label' => $this->l('Associated categories :'),
'category_tree' => $this->initCategoriesAssociation($this)
);
$categories = Category::getCategories($this->context->language->id, false, false);
$this->fields_form['input'][] = array(
@@ -335,10 +341,73 @@ class AdminShopControllerCore extends AdminController
'checked' => (Tools::getValue('addshop') !== false) ? true : false,
'defaultShop' => (int)Configuration::get('PS_SHOP_DEFAULT'),
);
if (isset($this->fields_import_form))
$this->tpl_form_vars = array_merge($this->tpl_form_vars, array('form_import' => $this->fields_import_form));
return parent::renderForm();
}
public function initCategoriesAssociation()
{
$selected_cat = Shop::getCategories(Tools::getValue('id_shop'));
$translations = array(
'Home' => $this->l('Home'),
'selected' => $this->l('selected'),
'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All'),
'Check All' => $this->l('Check All'),
'Uncheck All' => $this->l('Uncheck All'),
'search' => $this->l('Search a category')
);
return Helper::renderAdminCategorieTree($translations, $selected_cat, 'categoryBox', false, true);
}
/**
* Object creation
*
* @param string $token
*/
public function processAdd($token)
{
/* Checking fields validity */
$this->validateRules();
if (!count($this->_errors))
{
$object = new $this->className();
$this->copyFromPost($object, $this->table);
$this->beforeAdd($object);
if (!$object->add())
{
$this->_errors[] = Tools::displayError('An error occurred while creating object.').
' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
}
/* voluntary do affectation here */
else if (($_POST[$this->identifier] = $object->id) && $this->postImage($object->id) && !count($this->_errors) && $this->_redirect)
{
$parent_id = (int)Tools::getValue('id_parent', 1);
$this->afterAdd($object);
$this->updateAssoShop($object->id);
// Save and stay on same form
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay'))
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&update'.$this->table.'&token='.$token;
// Save and back to parent
if (Tools::isSubmit('submitAdd'.$this->table.'AndBackToParent'))
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$parent_id.'&conf=3&token='.$token;
// Default behavior (save and back)
if (empty($this->redirect_after))
$this->redirect_after = self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=3&token='.$token;
}
}
$this->_errors = array_unique($this->_errors);
if (count($this->_errors) > 0)
return;
$shop = new Shop($object->id);
$shop->updateCategories(Tools::getValue('categoryBox'));
return $object;
}
}