X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Adding Subcategories on Home page (https://forum.x-cart.com/showthread.php?t=77406)

siddharth.puri@wheelandba 12-12-2019 11:08 PM

Adding Subcategories on Home page
 
Hi i want to add sub categories on home page. I have a category Promotions which has sub categories.

How can I add sub categories of this category on the home page.

{% if this.getSubcategories() %}
<div class="subcategories-container overide">
<div class="subcategory-heading">
<span class="category-name">{{ t('Subcategories') }}</span>
</div>
<ul class="subcategory-view-icons subcategory-list grid-list clearfix">
{% for subcategory in this.getSubcategories() %}
{% if subcategory.hasAvailableMembership() %}
<li>
<a href="{{ url('category', '', {'category_id': subcategory.category_id}) }}">
<span class="subcategory-icon" style="width:100%; height:100%;">
{{ widget('\\XLite\\View\\Image', image=subcategory.image, maxWidth=this.getIconWidth(), maxHeight=this.getIconHeight(), centerImage='1', alt=this.getAlt(subcategory.image)) }}
</span>
<span class="subcategory-name" style=" width:100%; font-size: 18px !important; font-weight:bold;">{{ subcategory.name }}</span>
</a>
</li>
{% endif %}
{% endfor %}
{% for item in this.getNestedViewList('children') %}
<li>{{ item.display() }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{{ widget_list('subcategories.base') }}


----


Below this I want to display the sub categories of one of these categories.


I can catch that specific category by using subcategory.category_id == 10

Now I am struggling to display its sub categories


__________________
- X-Cart Version 5.3.6.1

Ed B. 07-05-2020 05:23 AM

Re: Adding Subcategories on Home page
 
  • Probably there is a way to find the set of all subcategories from the category. Basically if you get the properties of a category, you will get these, and from which you will find a way to loop over them.
  • This might be less elegant, but the relation "the category with id n is a subcategory of the category with id m" is stored in the xc_categories table in the entry for the category id m, the value n in the column "root category". So instead of looking for all subcategories of the category m, you can simply look for all categories whose root category is m, and you are done.


All times are GMT -8. The time now is 10:22 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.