How to filter by property?

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
materialshop
Posts: 1
Joined: 08 Jul 2021, 16:19

How to filter by property?

Post by materialshop » 08 Jul 2021, 16:30

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?

User avatar
aimeos
Administrator
Posts: 7885
Joined: 01 Jan 1970, 00:00

Re: How to filter by property?

Post by aimeos » 11 Jul 2021, 16:30

(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.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply