magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Catalog price rule condition get the wrong attribute value (wrong scope). #36752

Closed dekzer007 closed 1 year ago

dekzer007 commented 1 year ago

Preconditions and environment

We have 2 websites and each website has 1 store. mg2_02

USD store set the value to empty. mg2_03

DKK store set the value to "B". mg2_04

In database look like this. mg2_05

USD store frontend reult. mg2_06

DKK store frontend reult. mg2_07

DKK store should show the discount price.

Steps to reproduce

  1. Create 2 websites, 1 store for each website.
  2. Create dropdown product attribute (scope : website), Add to an attribute set.
  3. Create a simple product
    • first store : set the attribute value to empty
    • second store : set the attribute value to some value that match the product price rule condition.
  4. Create a catalog price rule. Set condition where the dropdown attribute in step 2 match some option value. (in my case is "B")
  5. Apply catalog price rules, re-index and flush cache.

Expected result

Frontend price:

Actual result

Frontend price:

Additional information

From many test cases we have done. We think catalog price rule get the first atribute value record without store/website filter.

For example, we try to set the match value on the first store and set value to empty for the second store. mg2_08

Then frontend show discount for both stores which also unexpected.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @dekzer007. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 1 year ago

Hi @dekzer007,

Thank you for reporting and collaboration. Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Steps to reproduce

1.Create 2 websites, 1 store for each website. 2.Create dropdown product attribute (scope : website), Add to an attribute set. 3.Create a simple product a.first store : set the attribute value to empty b.second store : set the attribute value to some value that match the product price rule condition. 4.Create a catalog price rule. Set condition where the dropdown attribute in step 2 match some option value. (in my case is "B") 5.Apply catalog price rules, re-index and flush cache.

Screenshot 2023-01-19 at 2 20 37 PM Screenshot 2023-01-19 at 2 20 18 PM Screenshot 2023-01-19 at 2 20 04 PM Screenshot 2023-01-19 at 2 26 19 PM

As per catalog price rule Discount should be applied for this store, because attribute matching the catalog rule.Discount is not applying.

Screenshot 2023-01-19 at 2 26 28 PM

When we try to set the match value on the first store and set value to empty for the second store.

Discount is applying for both the stores.

Screenshot 2023-01-19 at 5 01 41 PM Screenshot 2023-01-19 at 5 01 54 PM

Hence Confirming this issue.

Thanks.

github-jira-sync-bot commented 1 year ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-7740 is successfully created for this GitHub issue.

m2-assistant[bot] commented 1 year ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

Kannakiraj123 commented 1 year ago

@magento I am working on this

Vasudev-22 commented 1 year ago

@magento I am working on this

engcom-Hotel commented 1 year ago

Hello @dekzer007.

We had a discussion on this flow internally and with PO as well, as per the outcome of the discussion, this is expected behavior and if customers want to cart price rule to be applied only for a specific website, they should set only this specific website as the rule scope.

Thanks

dekzer007 commented 1 year ago

Hello @dekzer007.

We had a discussion on this flow internally and with PO as well, as per the outcome of the discussion, this is expected behavior and if customers want to cart price rule to be applied only for a specific website, they should set only this specific website as the rule scope.

Thanks

Hi @engcom-Hotel

I wanted to follow up on the issue. We have tried your suggestion, but it does not seem to be working correctly 100%.

When we set the USD store to empty (which does not have the discount) image

and the DKK store to "B" (which should have the discount) image

In database look like this. image

the frontend does not show the discount for either store, even though it should show for the DKK store.


We have also tested another scenario, where we set "C" for the USD store (which should not have the discount) image

and "B" for the DKK store (which should have the discount) image

In database look like this. image

In this case, the frontend shows the correct results.

It seems that the issue might be related to the "null" value. Could you please investigate this further? We have suggested to our client to set the default value for the dropdown attribute, which the default value should not have the discount. However, we want to make sure that this issue does not occur again, in case the admin sets the empty value (null) on the dropdown attribute.

Best regards,

nige-one commented 2 months ago

The issue lies in

https://github.com/magento/magento2/blob/d196d504d8b387454a123033ec2a74d7fd3d5430/app/code/Magento/CatalogRule/Model/Rule.php#L355

The resulting select for for the $productCollection in

https://github.com/magento/magento2/blob/d196d504d8b387454a123033ec2a74d7fd3d5430/app/code/Magento/CatalogRule/Model/Rule.php#L363-L364

will always check for the global scope (0) and the configured default StoreView. So it looks some like this:

SELECT `e`.*,
       IF(at_{ATTRIBUTE_CODE}.value_id > 0, at_{ATTRIBUTE_CODE}.value,
          at_{ATTRIBUTE_CODE}_default.value) AS `product_of_the_month`
FROM `catalog_product_entity` AS `e`
         INNER JOIN `catalog_product_website` AS `product_website`
                    ON product_website.product_id = e.entity_id AND product_website.website_id IN (8)
         LEFT JOIN `catalog_product_entity_int` AS `at_{ATTRIBUTE_CODE}_default`
                   ON (`at_{ATTRIBUTE_CODE}_default`.`entity_id` = `e`.`entity_id`) AND
                      (`at_{ATTRIBUTE_CODE}_default`.`attribute_id` = '493') AND
                      `at_{ATTRIBUTE_CODE}_default`.`store_id` = 0
         LEFT JOIN `catalog_product_entity_int` AS `at_{ATTRIBUTE_CODE}`
                   ON (`at_{ATTRIBUTE_CODE}`.`entity_id` = `e`.`entity_id`) AND
                      (`at_{ATTRIBUTE_CODE}`.`attribute_id` = '493') AND (`at_{ATTRIBUTE_CODE}`.`store_id` = 1)
WHERE ((e.entity_id IN ((SELECT `ca_product_of_the_month`.`entity_id`
                         FROM `catalog_product_entity_int` AS `ca_product_of_the_month`
                         WHERE (ca_product_of_the_month.attribute_id = '493')
                           AND (ca_product_of_the_month.value IN ('195'))))))

The value of the StoreView specific value is not loaded if it is not coming from

AND (`at_{ATTRIBUTE_CODE}`.`store_id` = 1)

If you save the product itself in the BE it will work, but the indexer will overwrite it based on aforementioned mechanism.