Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Trick: New category in a few places of tree categories Rate Topic   - - - - -

 
  • soft-solid
  • Junior Member
  • Members
  • Join Date: 19-Apr 10
  • 883 posts

Posted 18 December 2012 - 12:54 PM #1

Hello

Sometimes it is necessary to add a new category in the category tree a few places.
It is quite time-consuming if the category is a lot. This simple modification allows you to add a new category in many places in the category tree.
You need to modify two files.
controllers/customer/categories.php


 //
// Create/update category
//
if ($mode == 'update') {
if(is_array($_REQUEST['category_data']['parent_id'])) {
foreach ($_REQUEST['category_data']['parent_id'] as $key => $value) {
if($value == 0) continue;
$data = $_REQUEST['category_data'];
$data['parent_id'] = $value;
$category_id = fn_update_category($data, $_REQUEST['category_id'], DESCR_SL);
$suffix = '.manage';
}
} else {
$category_id = fn_update_category($_REQUEST['category_data'], $_REQUEST['category_id'], DESCR_SL);

if (!empty($category_id)) {
fn_attach_image_pairs('category_main', 'category', $category_id, DESCR_SL);

$suffix = ".update?category_id=$category_id" . (!empty($_REQUEST['category_data']['block_id']) ? "&selected_block_id=" . $_REQUEST['category_data']['block_id'] : "");
} else {
$suffix = '.manage';
}
}
}


admin/view/categories/update.tpl

 {if $smarty.request.dispatch == 'categories.add'}
{section name=cats start=1 loop=10 step=1}
<div class="form-field">
{if "categories"|fn_show_picker:$smarty.const.CATEGORY_THRESHOLD}
<label class="cm-required" for="location_category_id">{$lang.location}:</label>
{include file="pickers/categories_picker.tpl" data_id="location_category" input_name="category_data[parent_id][`$smarty.section.cats.index`]" item_ids=$category_data.parent_id|default:"0" hide_link=true hide_delete_button=true show_root=true default_name=$lang.root_level display_input_id="location_category_id" except_id=$id}
{else}
<label for="category_data_parent_id">{$lang.location}:</label>
<select name="category_data[parent_id][{$smarty.section.cats.index}]" id="category_data_parent_id">
<option value="0" {if $category_data.parent_id == "0"}selected="selected"{/if}>- {$lang.root_level} -</option>
{foreach from=0|fn_get_plain_categories_tree:false item="cat" name="categories"}

{if $cat.id_path|strpos:"`$category_data.id_path`/" === false && $cat.category_id != $id || !$id}
<option value="{$cat.category_id}" {if $cat.disabled}disabled="disabled"{/if} {if $category_data.parent_id == $cat.category_id}selected="selected"{/if}>{$cat.category|indent:$cat.level:"&#166;&nbsp;&nbsp;&nbsp;&nbsp;":"&#166;--&nbsp;"}</option>
{/if}


{/foreach}
</select>
{/if}
</div>
{/section}
{else}
<div class="form-field">
{if "categories"|fn_show_picker:$smarty.const.CATEGORY_THRESHOLD}
<label class="cm-required" for="location_category_id">{$lang.location}:</label>
{include file="pickers/categories_picker.tpl" data_id="location_category" input_name="category_data[parent_id]" item_ids=$category_data.parent_id|default:"0" hide_link=true hide_delete_button=true show_root=true default_name=$lang.root_level display_input_id="location_category_id" except_id=$id}
{else}
<label for="category_data_parent_id">{$lang.location}:</label>
<select name="category_data[parent_id]" id="category_data_parent_id">
<option value="0" {if $category_data.parent_id == "0"}selected="selected"{/if}>- {$lang.root_level} -</option>
{foreach from=0|fn_get_plain_categories_tree:false item="cat" name="categories"}

{if $cat.id_path|strpos:"`$category_data.id_path`/" === false && $cat.category_id != $id || !$id}
<option value="{$cat.category_id}" {if $cat.disabled}disabled="disabled"{/if} {if $category_data.parent_id == $cat.category_id}selected="selected"{/if}>{$cat.category|indent:$cat.level:"&#166;&nbsp;&nbsp;&nbsp;&nbsp;":"&#166;--&nbsp;"}</option>
{/if}


{/foreach}
</select>
{/if}
</div>
{/if}



Posted Image

I hope it's useful for someone. If you have questions please contact us.
Robert.

Attached Files

  • Attached File  cats.tgz   5.04KB   17 downloads

Team of SoftSolid
cs-cart.pl

 
  • Webrunner
  • Member
  • Members
  • Join Date: 06-Dec 06
  • 68 posts

Posted 22 January 2013 - 02:34 PM #2

Thank you for this post. For which version of CS-Cart dit you make this modification? I've checked with the latest version of CS-Cart ultimate and it doesn't seem to work.

Authorized Reseller Bitcoin accepted!
CS-Cart $345 - Ultimate $775 - Multi-Vendor $1250 https://sprintweb.nl
 


 
  • StellarBytes
  • Senior Member
  • Members
  • Join Date: 08-Aug 11
  • 1807 posts

Posted 22 January 2013 - 04:23 PM #3

It isn't Ultimate (nor V3 Professional), note the missing Store field between Categories and Full Description.
Hire StellarBytes for CS-Cart Design & Development Services

 
  • soft-solid
  • Junior Member
  • Members
  • Join Date: 19-Apr 10
  • 883 posts

Posted 23 January 2013 - 05:41 PM #4

Hello.
This trick works on all versions of CS-Cart. Please contact me on priv, we will try to help you start the modification.

Regards
Robert
Team of SoftSolid
cs-cart.pl