Category filter by another table

5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 8, 2011   (RSS)

By ht1080z - July 6, 2011

Hi,

Building product catalog based on category menus when products are recorded in different table, i try to filter categories they have no related with recorded products, only for the menu structure and the same page when products displayed, show differently for the user.

Products only recorded on the last child of the category structure and when someone select from the menu any other category where is no products (or any other way to filter this...) showing only the selected category and his child's only and the related fields of the categories.

Look at the attached php file (trying this filter to work from the line 187). [:|]

Please advise if you have any suggestion,
Thank you in advance!
Attachments:

cat1_cmsb_panel.jpg 117K

products1.php 10K

Re: [ht1080z] Category filter by another table

By Jason - July 7, 2011

Hi,

I took a look at your code. If I understand it correctly, if your page has returned products, you want to display them. If not, you want to display the records from "$cat1Records". I did notice this in your code:

<?php if ($cat1Record['_isSelected'] || $cat1Record['_isDescendantSelected']): ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php if($cat1Record['name']) echo $cat1Record['name']; else echo $cat1Record['name']; ?></a>
<?php else: ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php if($cat1Record['name']) echo $cat1Record['name']; else echo $cat1Record['name']; ?></a>
<?php endif; ?>


In this code, you are outputting a category link regardless of whether that record is part of the selected category branch or not. If you want to only output categories if they're selected or their children are selected, try this:

<?php if ($cat1Record['_isSelected'] || $cat1Record['_isDescendantSelected']): ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php if($cat1Record['name']) echo $cat1Record['name']; else echo $cat1Record['name']; ?></a>
<?php endif; ?>


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [ht1080z] Category filter by another table

By Jason - July 8, 2011

Hi,

What's happening here is your using "=" which is an assignment operator instead of "==" which is for comparison.

Try this:

<?php foreach ($cat1Records as $cat1Record): ?>
<?php if (($cat1Record['_isSelected'] || $cat1Record['_isAncestorSelected'] ) && ($cat1Record['parentNum'] == $selected1Category['num'])): ?>
<a href="<?php echo $cat1Record['_link'] ?>"><?php echo $cat1Record['name']; ?></a>
<?php echo $cat1Record['content'] ?><br/>
<?php endif; ?>
<?php endforeach; ?>


This is actually a very common mistake (I make it all the time!)

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Category filter by another table

By ht1080z - July 8, 2011

Jason!

Thank for your support on this again! [:)]