Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm try to make sorting by price using search_api_sorts or standard views sorting. My products have different currency USD, EUR, GBR, UAH.
Example price sorting:
- product 1 = $10
- product 2 = $20
- product 3 = 400 UAH (same as $16)
- product 4 = $500
- product 5 = $550
Instead of:
- product 1 = $10
- product 3 = 400 UAH (same as $16)
- product 2 = $20
- product 4 = $500
- product 5 = $550
When I select UAH currency for display costs of products I have a look:
- product 1 = 250 UAH
- product 2 = 500 UAH
- product 3 = 400 UAH
- product 4 = 12500 UAH
- product 5 = 13750 UAH
Comments
Comment #2
drunken monkeyThe Search API generally has no concept of a "currency". For it, those values are integers, and there's nothing to indicate it should be sorted differently. Changing the displayed currency also won't change the indexed values, which the sort is based on.
It seems you would need a processor which converts prices of indexed products to the same, configured currency, so sorting (and, e.g., filtering) will work correctly. Maybe the Drupal Commerce (I expect you're using that?) maintainers would be up for providing such a processor – let's find out. In any case, it's out of scope for the Search API.
Comment #3
czigor CreditAttribution: czigor at Centarro commentedHi Dr. Osd,
It depends on how your prices are stored. In case you're using a multivalue price field you'll probably need to write your own search api processor/views handler. Otherwise, if you have separate fields for each currency (field_price_uah, field_price_usd etc) it should work out of the box.