Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Product Filters - only show values for products in current category

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 11-13-2014, 04:11 AM
 
JannieB JannieB is offline
 

Senior Member
  
Join Date: Sep 2004
Posts: 117
 

Default Product Filters - only show values for products in current category

Hello,

When on a category page, is it possible to only show those attributes in the filter list which have products in the currently displayed category.

This would avoid a long list of attribute values being shown, which will return a null result if selecetd (quite annoying for the customer).

(perhaps in a similar way to the way the All Brands page only shows brands with products).

Thanks,

Jan
__________________
Jan Beesley
(Currently Xcart 5
Previously XCart Gold from 3.5....)
Reply With Quote
  #2  
Old 11-13-2014, 06:15 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Product Filters - only show values for products in current category

You can use the following option:
http://awesomescreenshot.com/0a73ueu62e

on the category details page in admin area.

Please, let me know if it works for you.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #3  
Old 11-13-2014, 07:36 AM
 
JannieB JannieB is offline
 

Senior Member
  
Join Date: Sep 2004
Posts: 117
 

Default Re: Product Filters - only show values for products in current category

Thanks Tony,

I am using that option but the problem is this:

I have a global Product Class called Brands. Lets say there are 50 brands listed.

If I have a category, let's say Lighting. The products in Lighting are from say, 5 brands. In the brands filter I only want to see 5 brands (ie the ones attached to products in this category).

At the moment it lists all the brands, which is not what I want. It's not a true filter of what is on the page...

I feel this must be possible, but not sure how.

Thanks,

Jan

PS. The Brands class needs to be global as each brand may have products in multiple categories. I can view all Brand products via the Brand page (courtesy of the ShopByBrand module).
__________________
Jan Beesley
(Currently Xcart 5
Previously XCart Gold from 3.5....)
Reply With Quote
  #4  
Old 11-17-2014, 05:08 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Product Filters - only show values for products in current category

I see. In this case, there is indeed a mod needed.

The method that returns widgets of product attributes is getAttributesList() in the \XLite\Module\XC\ProductFilter\View\Filter\AFilter \AttributeList class. You need to decorate this one, or better prepareAttributesList() that prepares widgets to display. In this method you will be able to sort attributes so that it displays only meaningful options.

Please, let me know if it helps.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #5  
Old 11-24-2014, 06:30 AM
 
JannieB JannieB is offline
 

Senior Member
  
Join Date: Sep 2004
Posts: 117
 

Default Re: Product Filters - only show values for products in current category

Hello,

Sorry for delay in replying .... got drawn into something else ... can you give me a steer on how I can extract a product count for each attribute ... then I can decorate the class as you suggest to exclude those with a product count of zero.

I have been looking at the code but am getting a bit befuddled.

Thanks,

Jan
__________________
Jan Beesley
(Currently Xcart 5
Previously XCart Gold from 3.5....)
Reply With Quote
  #6  
Old 11-25-2014, 06:11 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Product Filters - only show values for products in current category

Well, I would be happy to give you a hand in this task, but I need some time to deal with other dev docs. Will it be OK for you to wait for ~month, so I could describe the process in dev docs and then share it with you?

Tony.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #7  
Old 11-25-2014, 08:08 AM
 
JannieB JannieB is offline
 

Senior Member
  
Join Date: Sep 2004
Posts: 117
 

Default Re: Product Filters - only show values for products in current category

Thanks for your reply ... I need to crack this one this week sadly.
I am thinking of looking at the way the category filter works and see if I can use any of that code to basically find out if each attribute option has any products in the given category.

Any suggestions gratefully received....

Jan
__________________
Jan Beesley
(Currently Xcart 5
Previously XCart Gold from 3.5....)
Reply With Quote
  #8  
Old 11-26-2014, 09:46 AM
 
JannieB JannieB is offline
 

Senior Member
  
Join Date: Sep 2004
Posts: 117
 

Default Re: Product Filters - only show values for products in current category

What I am basically trying to do is run this SQL query for each attribute option ... passing in the
category id (of the page we are on, example = 13)
Attribute_option_id (of the option in question, example = 99)

Code:
SELECT count(xc_category_products.product_id) as productCount FROM xc_category_products LEFT JOIN xc_attribute_values_select ON xc_category_products.product_id = xc_attribute_values_select.product_id WHERE xc_category_products.category_id = '13' AND xc_attribute_values_select.attribute_option_id= '99'

This query would return the number of products in this category for this attribute option (quite a handy thing to have anyway).

I am guessing the best place of the code is as part of the getOptions() function in \XLite\Module\XC\ProductFilter\View\FormField\Sele ct\Attribute.php, but I'm not sure how this will get access to the category id, and also how to build that query in the new x-cart architecture ...

Would really appreciate some help on this Tony if you can spare a few moments ....


Jan
__________________
Jan Beesley
(Currently Xcart 5
Previously XCart Gold from 3.5....)
Reply With Quote
  #9  
Old 11-28-2014, 03:00 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Product Filters - only show values for products in current category

Hi Jan!

OK, here is an example of how to pull number of products based on the attribute_option_id and category:

Code:
<?php require_once 'top.inc.php'; require_once 'top.inc.additional.php'; $categoryId = 4; $attributeValueId = 112; $qb = \XLite\Core\Database::getRepo('XLite\Model\Product')->createQueryBuilder('p') ->linkInner('p.categoryProducts') ->linkInner('categoryProducts.category') ->linkInner('p.attributeValueS') ->andWhere('category.category_id = :categoryId AND attributeValueS.attribute_option = :attributeValueId') ->setParameter('categoryId', $categoryId) ->setParameter('attributeValueId', $attributeValueId); echo count($qb->getResult());

I assume that you will add this code to some .PHP script inside X-Cart folder. Please, try this out and let me know if it suits your needs.

Tony.
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #10  
Old 11-28-2014, 03:41 AM
 
JannieB JannieB is offline
 

Senior Member
  
Join Date: Sep 2004
Posts: 117
 

Default Re: Product Filters - only show values for products in current category

Thank you for this ..... I am just wondering where I should put it?

maybe in XLite\Module\XC\ProductFilter\View\Filter\Attribut eList, or at a lower level in \XLite\Module\XC\ProductFilter\View\FormField\Sele ct\Attribute (decorated versions obviously).

Also, while I can get the option id, I'm not sure how to pass the category id through.... it exists as part of the Filter class, but when I've tried to access it at a lower level I get an error ...

....

Thanks in advance ....

Jan

PS. I think this should be aprt of the core Product Filter functionality as otherwise it's not really filtering what's on the page .... if I come up with a solution (with your help!) I will publish it here for others to use..
__________________
Jan Beesley
(Currently Xcart 5
Previously XCart Gold from 3.5....)
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:05 PM.

   

 
X-Cart forums © 2001-2020