craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
215 stars 169 forks source link

[3.x]: hasSales attribute not filtering out items that are not promotable #3553

Open mcclaskiem opened 1 week ago

mcclaskiem commented 1 week ago

What happened?

Description

I have a weird issue where items that are not promotable are showing up when I use the hasSales attribute set to true on a variant query:

{% paginate craft.products({
    relatedTo: params,
    limit: 15,
    order: 'sku asc',
    with: [['frontImage', {withTransforms: ['viewAll']}]],
    hasVariant: variantQuery
}) as pageInfo, products %}

 {% set variantQuery = {
    hasStock: true,
    hasSales: saleItems ? true : false
} %}

I have a query parameter that is being passed from the frontend to determine if the user is looking for on sale items or not

Steps to reproduce

1.

Expected behavior

Expect that returned results will all have active sales when user requests "sales items"

Actual behavior

Showing all items related to their filtered query

Craft CMS version

3.9.5

Craft Commerce version

3.4.23

PHP version

7.4

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

linear[bot] commented 1 week ago

PT-1885 [3.x]: hasSales attribute not filtering out items that are not promotable

lukeholder commented 1 week ago

I was ~able~ unable to reproduce this issue:

{% paginate craft.products.hasVariant({hasSales: true}).limit(100) as pageInfo, pageProducts %}

this showed items on sale, and passing false showed items not on sale.

Should the variantQuery variable be set before you pass it into the pagination query?

mcclaskiem commented 1 week ago

The variantQuery variable is set before being passed I just pasted both code snippets in no particular order.

To add some more context:

I have a sale that is applied to certain category of products, basically a specific designer. We don’t want all of the products from that designer to be on sale so I have some set with “promotable” disabled however those products still show up on the sale page.

On Tue, Jun 25, 2024 at 01:15 Luke Holder @.***> wrote:

I was able to reproduce this issue:

{% paginate craft.products.hasVariant({hasSales: true}).limit(100) as pageInfo, pageProducts %}

this showed items on sale, and passing false showed items not on sale.

Should the variantQuery variable be set before you pass it into the pagination query?

— Reply to this email directly, view it on GitHub https://github.com/craftcms/commerce/issues/3553#issuecomment-2187995611, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVFXLZTQNRK4RUQGXBXJF3ZJD4HDAVCNFSM6AAAAABJXRV67CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBXHE4TKNRRGE . You are receiving this because you authored the thread.Message ID: @.***>

lukeholder commented 1 week ago

I made a typo on my last response. I was UNable to reproduce. Could you send you database backup, composer.json and composer.lock to support@craftcms.com so we can take a look. Please reference this issue when you submit the support ticket. Thanks.

mcclaskiem commented 1 week ago

@lukeholder Just sent it over via email. Thanks for taking a look!