Page 1 of 1

How to filter by property?

Posted: 08 Jul 2021, 16:30
by materialshop
Hello--

I'm trying to create a shop where the products are different materials that mainly differ in dimensions (thickness, diameter, length, width, etc.). I would like to be able to filter by these dimensions (show only products from X category that have a thickness of Y, and/or a width greater than Z-- for example).

I'm having trouble understanding how best to go about this. I'm pretty sure that I need to have my product have a product.property.value and product.property.type corresponding to each different dimension, because otherwise I would have hundreds of different attributes of Width, or Diameter.

In the filters though, there are no parameters for product properties (as there are for attributes and suppliers). What is the best approach to accomplishing my goal?

Re: How to filter by property?

Posted: 11 Jul 2021, 16:30
by aimeos
(Product) Properties are text strings and you won't be able to filter by them because "500" isn't greater than "50.0" when comparing texts. If you only sell products that all have these dimensions, our recommendation would be to add these dimensions as additional columns to the mshop_product table with a matching column type (float or decimal). You can use a decorator for that:
https://aimeos.org/docs/latest/models/extend-managers/

Then, you have to adapt the HTML frontend to add your filters and extend the catalog/lists component (create a new class and extend from the original one) to pass the additional filters if available:
https://github.com/aimeos/ai-client-htm ... #L710-L721

Use the compare() method of the product frontend controller to add the conditions:
https://github.com/aimeos/ai-controller ... hp#L53-L62
e.g.

Code: Select all

$cntl->compare( '>', 'diameter', '5.0' );
Don't forget to sanitize the values first ("," vs. "." for decimal separator) or better use number fields.