Commerce: Disabled product's variants still appear in query results

Created on 1 Mar 2019  路  2Comments  路  Source: craftcms/commerce

Description

As per
https://github.com/craftcms/commerce/issues/380
https://github.com/craftcms/commerce/issues/454

The variants of disabled products appear within queries

For instance {% set results = craft.variants %} will return product variants from products that have been disabled.

Disabling the variants themselves prevents them appearing. However, it's no possible to disable the default variant so that is still showing (even when the product is disabled).

Additional info

  • Craft version: 3.1.14

Most helpful comment

Thanks for the tip to get around it.

It does, however, feel broken. It does not seem logical that the query would return variants of disabled products when querying for products wouldn't return those that were disabled unless specifically added as a clause.

All 2 comments

Thanks for submitting the issue.

We plan to leave this as it is for now, you can achieve what you need with:

{% set results = craft.variants.hasProduct({'status':'enabled'}).all() %}

On a technical note, If you query for a matrix block, it doesn't factor in if the owner (entry) is disabled.

Thanks for the tip to get around it.

It does, however, feel broken. It does not seem logical that the query would return variants of disabled products when querying for products wouldn't return those that were disabled unless specifically added as a clause.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sjcallender picture sjcallender  路  6Comments

Anubarak picture Anubarak  路  3Comments

benface picture benface  路  5Comments

brandonkelly picture brandonkelly  路  3Comments

engram-design picture engram-design  路  4Comments