[-] BO : #PSTEST-369 - Durring the category removing, allow to not delete the products
This commit is contained in:
@@ -50,4 +50,38 @@
|
||||
{/foreach}
|
||||
{/if}
|
||||
</div>
|
||||
{if isset($delete_category) && $delete_category}
|
||||
<form action="{$REQUEST_URI}" method="post">
|
||||
<div class="warn">
|
||||
<h2>{l s='Do you want to delete products too?'}</h2>
|
||||
<ul class="listForm">
|
||||
<li>
|
||||
<input type="radio" name="deleteMode" value="linkanddisable" id="deleteMode_linkanddisable" />
|
||||
<label for="deleteMode_linkanddisable" style="float:none;">{l s='No, I want to link products without others categories with the parent category and disable them.'}</label>
|
||||
</li>
|
||||
<li>
|
||||
<input type="radio" name="deleteMode" value="link" id="deleteMode_link" />
|
||||
<label for="deleteMode_link" style="float:none;">{l s='No, I want to link products without others categories with the parent category.'}</label>
|
||||
</li>
|
||||
<li>
|
||||
<input type="radio" name="deleteMode" value="delete" id="deleteMode_delete" />
|
||||
<label for="deleteMode_delete" style="float:none">{l s='Yes, I want to remove products linked with this category and without any others categories.'}</label>
|
||||
</li>
|
||||
</ul>
|
||||
{foreach $POST as $key => $value}
|
||||
{if $key != 'deleteMode'}
|
||||
{if is_array($value)}
|
||||
{foreach $value as $val}
|
||||
<input type="hidden" name="{$key}[]" value="{$val}" />
|
||||
{/foreach}
|
||||
{else}
|
||||
<input type="hidden" name="{$key}" value="{$value}" />
|
||||
{/if}
|
||||
{/if}
|
||||
{/foreach}
|
||||
<br /><input type="submit" class="button" value="{l s=' Validate '}" />
|
||||
</div>
|
||||
</form>
|
||||
<div class="clear"> </div>
|
||||
{/if}
|
||||
{/block}
|
||||
|
||||
+42
-23
@@ -78,6 +78,12 @@ class CategoryCore extends ObjectModel
|
||||
public $is_root_category;
|
||||
|
||||
public $groupBox;
|
||||
|
||||
/** @var boolean does the product have to be removed during the delete process */
|
||||
public $remove_products = true;
|
||||
|
||||
/** @var boolean does the product have to be disable during the delete process */
|
||||
public $disable_products = false;
|
||||
|
||||
protected static $_links = array();
|
||||
|
||||
@@ -195,15 +201,15 @@ class CategoryCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive scan of subcategories
|
||||
*
|
||||
* @param integer $max_depth Maximum depth of the tree (i.e. 2 => 3 levels depth)
|
||||
* @param integer $current_depth specify the current depth in the tree (don't use it, only for rucursivity!)
|
||||
* @param integer $id_lang Specify the id of the language used
|
||||
* @param array $excluded_ids_array specify a list of ids to exclude of results
|
||||
*
|
||||
* @return array Subcategories lite tree
|
||||
*/
|
||||
* Recursive scan of subcategories
|
||||
*
|
||||
* @param integer $max_depth Maximum depth of the tree (i.e. 2 => 3 levels depth)
|
||||
* @param integer $current_depth specify the current depth in the tree (don't use it, only for rucursivity!)
|
||||
* @param integer $id_lang Specify the id of the language used
|
||||
* @param array $excluded_ids_array specify a list of ids to exclude of results
|
||||
*
|
||||
* @return array Subcategories lite tree
|
||||
*/
|
||||
public function recurseLiteCategTree($max_depth = 3, $current_depth = 0, $id_lang = null, $excluded_ids_array = null)
|
||||
{
|
||||
$id_lang = is_null($id_lang) ? Context::getContext()->language->id : (int)$id_lang;
|
||||
@@ -245,15 +251,15 @@ class CategoryCore extends ObjectModel
|
||||
|
||||
|
||||
/**
|
||||
* Recursively add specified category childs to $to_delete array
|
||||
*
|
||||
* @param array &$to_delete Array reference where categories ID will be saved
|
||||
* @param array $id_category Parent category ID
|
||||
*/
|
||||
* Recursively add specified category childs to $to_delete array
|
||||
*
|
||||
* @param array &$to_delete Array reference where categories ID will be saved
|
||||
* @param array $id_category Parent category ID
|
||||
*/
|
||||
protected function recursiveDelete(&$to_delete, $id_category)
|
||||
{
|
||||
if (!is_array($to_delete) || !$id_category)
|
||||
die(Tools::displayError());
|
||||
if (!is_array($to_delete) || !$id_category)
|
||||
die(Tools::displayError());
|
||||
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_category`
|
||||
@@ -295,7 +301,7 @@ class CategoryCore extends ObjectModel
|
||||
$tmp_category->deleteImage();
|
||||
}
|
||||
|
||||
/* Delete products which were not in others categories */
|
||||
/* Delete or link products which were not in others categories */
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_product`
|
||||
FROM `'._DB_PREFIX_.'product`
|
||||
@@ -305,7 +311,20 @@ class CategoryCore extends ObjectModel
|
||||
{
|
||||
$product = new Product((int)$p['id_product']);
|
||||
if (Validate::isLoadedObject($product))
|
||||
$product->delete();
|
||||
{
|
||||
if ($this->remove_products)
|
||||
$product->delete();
|
||||
else
|
||||
{
|
||||
if ($this->disable_products)
|
||||
{
|
||||
$product->active = 0;
|
||||
}
|
||||
|
||||
$product->addToCategories($this->id_parent);
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set category default to 1 where categorie no more exists */
|
||||
@@ -892,11 +911,11 @@ class CategoryCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Each parent category of this category until the root category
|
||||
*
|
||||
* @param integer $id_lang Language ID
|
||||
* @return array Corresponding categories
|
||||
*/
|
||||
* Get Each parent category of this category until the root category
|
||||
*
|
||||
* @param integer $id_lang Language ID
|
||||
* @return array Corresponding categories
|
||||
*/
|
||||
public function getParentsCategories($id_lang = null)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
|
||||
@@ -90,11 +90,23 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
parent::init();
|
||||
|
||||
// context->shop is set in the init() function, so we move the _category instanciation after that
|
||||
if ($id_category = Tools::getvalue('id_category'))
|
||||
if (($id_category = Tools::getvalue('id_category')) && $this->action != 'select_delete')
|
||||
$this->_category = new Category($id_category);
|
||||
else
|
||||
$this->_category = new Category($this->context->shop->id_category);
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
if ($this->action == 'select_delete')
|
||||
$this->context->smarty->assign(array(
|
||||
'delete_form' => true,
|
||||
'url_delete' => htmlentities($_SERVER['REQUEST_URI']),
|
||||
'boxes' => $this->boxes,
|
||||
));
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
public function setMedia()
|
||||
{
|
||||
@@ -159,6 +171,11 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
$this->tpl_list_vars['categories_name'] = $categories_name;
|
||||
$this->tpl_list_vars['category_root'] = $root;
|
||||
|
||||
if (Tools::isSubmit('submitBulkdelete'.$this->table) OR Tools::isSubmit('delete'.$this->table))
|
||||
$this->tpl_list_vars['delete_category'] = true;
|
||||
$this->tpl_list_vars['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
|
||||
$this->tpl_list_vars['POST'] = $_POST;
|
||||
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
@@ -225,7 +242,14 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
$this->action = 'add'.$this->table.'root';
|
||||
$this->display = 'edit';
|
||||
}
|
||||
return parent::initProcess();
|
||||
|
||||
parent::initProcess();
|
||||
|
||||
if ($this->action == 'delete' || $this->action == 'bulkdelete')
|
||||
if (Tools::getValue('deleteMode') == 'link' || Tools::getValue('deleteMode') == 'linkanddisable' || Tools::getValue('deleteMode') == 'delete')
|
||||
$this->delete_mode = Tools::getValue('deleteMode');
|
||||
else
|
||||
$this->action = 'select_delete';
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
@@ -443,6 +467,21 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
{
|
||||
if ($this->tabAccess['delete'] === '1')
|
||||
{
|
||||
if ($this->delete_mode == 'link' || $this->delete_mode == 'linkanddisable')
|
||||
{
|
||||
if (Validate::isLoadedObject($object = $this->loadObject()))
|
||||
{
|
||||
$object->remove_products = false;
|
||||
if ($this->delete_mode == 'linkanddisable')
|
||||
$object->disable_products = true;
|
||||
}
|
||||
}
|
||||
else if ($this->delete_mode != 'delete')
|
||||
{
|
||||
$this->_errors[] = Tools::displayError('Unknown delete mode:'.' '.$this->deleted);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Tools::isSubmit($this->table.'Box'))
|
||||
{
|
||||
if (isset($_POST[$this->table.'Box']))
|
||||
|
||||
Reference in New Issue
Block a user