| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Showing only certain categories in the sidebar / adding a second categories box | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Showing only certain categories in the sidebar / adding a second categories box
Hi all,
We're in the process of upgrading our last website to 5.4. On this site, we use two types of category: one to sort by product type and one to sort by product application. I therefore want to add a second categories sidebar to the site so that I can separate them. Adding the custom module, etc, to display a second box in the sidebar is something that I've done on a previous site (although not to display a category list), so I think I can cover that bit. The bit I am struggling with is how I formulate the code to select which categories to display in which box. When I did this on a previous version of X-Cart, I was able to do it by using an IF statement and looking at the $category_id (as shown here https://forum.x-cart.com/showpost.php?p=280361&postcount=13) but I'm struggling with it on X-Cart 5. Does anyone know how I can code an IF statement to select (for instance) only categories with an ID of less than 50? Or have any suggestions of a better way to achieve what I'm trying to do? Thanks in advance.
__________________
Four sites using X-Cart 5.4.x.x. Oh the joy |
|||||||
#2
|
|||||||||
|
|||||||||
Re: Showing only certain categories in the sidebar / adding a second categories box
I wouldn't count on the category id as you may add new categories or remove existing or rename existing to move them form one to the other.
I see 2 ways of doing that - using the category position or adding new property exclusively for this purpose. If you use category position you can select categories with position less than X for the first block and the rest for the second block (or position more than X for one block and the rest for the other, whatever works best). The problem with using position is that categories are sorted by position to begin with and you will have to be very careful how you manage position so it satisfies both. I think it is better to add another filed to the categories table for this purpose. Whatever you call it doesn't matter and it can just be boolean field - true being type and false being application. Then you can do the queries to select categories for type and application based on this field's value.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#3
|
|||||||
|
|||||||
Re: Showing only certain categories in the sidebar / adding a second categories box
Hi Steve,
Thanks for your reply. Yes, using the category_id isn't ideal, but I had experience doing it that way from a previous version of X-Cart. I think I would prefer to use position, rather than trying to add new fields to the database and I could envisage that product type could be in one number range and application could be in a different range. That way, they'd always be separated, even if the positions were changed. I've managed to work out the IF statement syntax I would need if i use category_id, but I can't seem to find the correct name / syntax to reference for category position. Any ideas? Thanks in advance.
__________________
Four sites using X-Cart 5.4.x.x. Oh the joy |
|||||||
#4
|
|||||||
|
|||||||
Re: Showing only certain categories in the sidebar / adding a second categories box
The table xc_categories have two fields called rpos and lpos, which, I think, correspond to"category positions".
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
#5
|
|||||||||
|
|||||||||
Re: Showing only certain categories in the sidebar / adding a second categories box
Quote:
Using he position may confuse you because categories are positioned within their parent category. So the position field may hold same value for 1st level category and 3 level category. This will only work if you have one level of categories or if you do the splitting based on 1st level categories only. The category position field in the table is called "pos". "lpos" and "rpos" are used to position the category in relation to prev and next and parent category.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
|
#6
|
|||||||
|
|||||||
Re: Showing only certain categories in the sidebar / adding a second categories box
Hi,
Yes, all the categories are at root level. If I use a statement such as: Code:
then I can get the result I'm looking for. If I use Code:
then it doesn't work. As most of my programming experience stems from Sinclair Basic waaaay back in the day, I think it's probably a lack of understanding of the correct syntax to use, so any tips are gratefully received.
__________________
Four sites using X-Cart 5.4.x.x. Oh the joy |
|||||||
#7
|
|||||||||
|
|||||||||
Re: Showing only certain categories in the sidebar / adding a second categories box
"this" does not refer to a category so there is no "pos" for it.
I am not sure where you are using this "this._category.id" so hard to say what you have there. In this case you can use "this._category.pos" or "this._category.position" - depends on how it is called within the _category array. You can also try "this._category.getPos()" or "this._category.getPosition()". If none of them works you will have to decorate the appropriate class behind the template and see how to add the category position to each element so you can use it in the template.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#8
|
|||||||
|
|||||||
Re: Showing only certain categories in the sidebar / adding a second categories box
I think I'm getting too far down the rabbit hole on this one for the knowledge that I have (and don't currently have the spare time to do the necessary learning for something that is obviously more involved than I was hoping it would be).
So I think I'll run with using category.id, as I can get that working at present and worry about possible issues that new categories might present when they occur. By then, I might have had time to learn what I'm doing. Many thanks for your help, Steve.
__________________
Four sites using X-Cart 5.4.x.x. Oh the joy |
|||||||
|
|||
X-Cart forums © 2001-2020
|