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
  #11  
Old 11-28-2014, 04:30 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 should definitely decorate XLite\Module\XC\ProductFilter\View\Filter\Attribut eList or its parent \XLite\Module\XC\ProductFilter\View\Filter\AFilter

As for category ID, since you are on category pages for sure, you can call it like this:
$this->getCategory()->getCategoryId();

I would be happy to help you with this mod in details, but cannot afford it right now. I will do my best to look into it next week.

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
  #12  
Old 11-28-2014, 05:13 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 Tony, that's very helpful ....
.. I'll have a go and let you know how I get on.

Jan
__________________
Jan Beesley
(Currently Xcart 5
Previously XCart Gold from 3.5....)
Reply With Quote

The following user thanks JannieB for this useful post:
tony_sologubov (12-01-2014)
  #13  
Old 11-28-2014, 06:52 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

I seem to have managed to get this working .... possibly not in the most elegant way but this is what I did:

I decorated the class
\XLite\Module\XC\ProductFilter\View\FormField\Sele ct\Attribute

and added this function

Code:
protected function getFilteredOptions() { // get attribute options - only include those options with products in currently selected category $list = array(); $categoryId = $this->getCategory()->getCategoryId(); foreach ($this->getParam(self::PARAM_ATTRIBUTE)->getAttributeOptions() as $option) { $attributeValueId = $option->getId(); $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); $prodCount = count($qb->getResult()); if ($prodCount > 0) { $list[$option->getId()] = $option->getName(); } } // sort attributes alphabetically by name if (is_array($list)) { asort($list); } return $list; }

The I amended the tpl /skin..../modules/XC/ProductFilter/form_field/select/checkbox_list/select.tpl to use my function getFilteredOptions instead of getOptions.

I created a new function in case the getOptions function was used elsewhere ... this way I can choose which to use.

No doubt there is a more sophisticated way of doing this, but it seems to work so I will leave it alone now!

Thanks for your help ... I have been grappling with this for days!!

Jan
__________________
Jan Beesley
(Currently Xcart 5
Previously XCart Gold from 3.5....)
Reply With Quote

The following 2 users thank JannieB for this useful post:
juancho (12-12-2014), tony_sologubov (12-01-2014)
  #14  
Old 12-01-2014, 05:13 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

Good job, Jan!
__________________
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
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 11:37 PM.

   

 
X-Cart forums © 2001-2020