Last active
September 27, 2016 04:28
-
-
Save hongc-cc/71fdd9da81eeede3e32d29e3b5c0f7b1 to your computer and use it in GitHub Desktop.
[CraftCMS] Finding similar products by variants' fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# scenario | |
variants -> similar variants by variant's category -> variants group by product's "device" category field | |
#} | |
{# Similar Variants with eager loading #} | |
{% set similarVariants = craft.commerce.variants({ | |
relatedTo: someElements, | |
with: ['product.device', 'product.url'] | |
}).find() %} | |
{% set similarVariantsByProduct = similarVariants | group('product.device | last ') %} | |
{% for productDevice, variants in similarVariantsByProductId %} | |
<a href="{{ variants[0].product.url }}">{{ productDevice }}</a> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment