Closed joshuapease closed 2 years ago
Hi @joshuapease
Thank you for your message.
As you stated the only real multi-site aware feature for variants is indirectly related via the "Enable for site" feature on the product. For example, if you delete a variant it will delete it for all sites. This means that variants themselves are related to all sites.
There is a way for you to perform the query you are looking for, it would look something like this:
{% set variants = craft.variants({
hasProduct: {
enabledForSite: true
}
}).all() %}
<ul>
{% for v in variants %}
<li>{{ v.product.title ~ ' - ' ~v.title }}</li>
{% endfor %}
</ul>
This will return you all the variants that have a product that is enabled for the current site.
Hope this helps, thanks!
Thanks so much! I see it in the docs now that I know what I'm looking for.
Hi @joshuapease
Great news, thanks!
Description
I'm trying to query a subset of variants that are enabled for a certain site.
Since the "Enable for site" Lightswitch is at the product level, I suppose this makes sense, but... variants are directly tied to a product, so my assumption would be that using
->site()
would return only Variants who's product is for that specific site (or thatcurrentSite
would be the default is site wasn't explicitly added).Curious if there are any workarounds or if this is something that could be added in a future release.
Thanks for your help!
Steps to reproduce
Additional info
Composer.json