Price ordering
Ordering by selling price is one of the basic requirements for e-commerce applications. The price ordering constraint allows to sort the output entities by their selling price in ascending or descending order.
Price natural
- argument:enum(ASC|DESC)
- the ordering direction (ascending or descending), default value is ASC
Price discount
- argument:enum(ASC|DESC)?
- the ordering direction (ascending or descending), default value is DESC
- argument:string+
A mandatory specification of one or more price list names in order of priority from most preferred to least preferred from which the reference price should be taken into account for the discount calculation.
If the reference price is not found, the entity / product is considered not sortable by this constraint and will be sorted by the next sort constraint in the query (or by its primary key in ascending order at the end of the list).
Lowest price strategy
The lowest price strategy is typically used for virtual products that represent multiple similar products. In the end, only one of the products is selected for sale. When we query products by currency, set of price lists, validity timestamp, the virtual product with LOWEST_PRICE strategy manifests itself with sub-product (variant) with the lowest price. When we calculate the discount, we need to use the price from different price lists, but only the price that refers to the same product variant as the price for sale.
Sum price strategy
The sum-price strategy is typically used for products that consist of several sub-products (parts). Its sales price is calculated as the sum of the prices of the sub-products. If a certain subproduct doesn't have a price in the selected price lists, it is excluded from the sum. When we calculate the reference price for this product, we must also omit the prices of these sub-products, even if the reference price would be available for them. Otherwise, the calculated sum wouldn't be consistent with the sales price.
Yes, prices must be indexed in the database in order to sort products by discount amount. Non-indexed prices are accessible only when the entity body is fetched from disk, which would be very inefficient for sorting large datasets. Therefore, even the "non-indexed" prices must be indexed and kept in memory indexes to be able to calculate the discount amount in an efficient way.