Product comparison API¶
Comparison is a basket with a special type
No events are thrown when adding products to a comparison, so adding to comparison is quicker than adding items to a basket. However, there is no data validation in the background. Data validation, such as for the minimum order amount or for mixing of downloads with normal products, is done when adding those items into the shopping basket.
New attributes are added to
comparison baskets to handle the necessary additional data for the comparison list.
These attributes are not declared in the
Basket class, but must be added dynamically by the
comparisonAttributes is an associative array which defines the comparable attributes for the current object's comparison category.
comparisonAttributes has the following sub-structure:
1 2 3 4 5 6 7 8 9 10 11 12
comparisonElements is an array which contains the data for the product columns in the comparison list.
comparisonElements has the following sub-structure:
1 2 3 4 5 6 7 8
ComparisonServiceInterface interface determines methods necessary for implementing different comparison services.
getComparisonCategory(CatalogElement $catalogElement) determines the correct comparison category for the given catalog element.
getComparisonInformation(array $comparisonList) determines the necessary comparison information for every given comparison category
To change the logic that determines to which categories to assign particular products, you need to override the comparison service or implement a new one.
First, the service must implement
getComparisonCategory() method takes a catalog element (products included) as an argument.
This method must implement the logic to determine the comparison category for the passed product.
The standard logic implementation:
- Tries to get product type from the
- Tries to get the type from parent element category
- If everything else fails, places the product in the default category