Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sku from operators to validate condition #20412

Merged
merged 6 commits into from
Mar 20, 2019
Merged

Remove sku from operators to validate condition #20412

merged 6 commits into from
Mar 20, 2019

Conversation

igor-imaginemage
Copy link

Description

@andersonalves faced an issue with our customers running Magento 2.2. When you create a product with a sku and you use the sku as a condition to a cart rule it will use the "{}"(contains) condition, and not equals "==". We debugged the code and we found an issue available only on Magento 2.2.

Fixed Issues

This PR will fix this issue on Magento 2.2. Magento 2.1 and 2.3 are working correctly, this fix was already applied to them.

Manual testing scenarios

  1. Create a product with a sku 123
  2. Create a configurable product with sku conf123.
  3. Create simple products for this configurable with 123 inside the skus, for example conf-red-123 and conf-blue-123.
  4. Create a cart rule and inside actions add a condition to apply the discount only if a product sku is equals to 123.
  5. You can specify a coupon code or not for this rule, it's optional.
  6. Specify a discount amount or a percentage.
  7. Add the configurable product to the cart and go to the cart page.
  8. You will see the discount is being applied to the configurable product, and the configurable product sku is not equals to 123, it contains 123 in the sku, but is not equal.

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Jan 18, 2019

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team
Copy link
Contributor

Hi @igor-imaginemage. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.2-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@igor-imaginemage igor-imaginemage changed the title Remove sku from this condition Remove sku from operators to validate condition Jan 18, 2019
@sivaschenko
Copy link
Member

Hi @igor-imaginemage I see that sku is present in the condition changed by this pull request on 2.3-develop branch, was it fixed there using a different approach?

@igor-imaginemage
Copy link
Author

igor-imaginemage commented Jan 18, 2019

Hi @sivaschenko, on 2.1 and 2.3-develop this class doesn't have the sku inside the conditions in the getOperatorForValidate method. We tested and it's not happening on 2.1 and 2.3, only on 2.2 because on 2.2-develop we have this condition on this method.

Here is the same class on 2.3-develop: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php

@igor-imaginemage
Copy link
Author

igor-imaginemage commented Jan 18, 2019

This is the code on 2.3 and 2.1 (working correctly):
if ($this->getInputType() == "category") {

This is the code on 2.2 (not working properly with sku):
if (in_array($this->getInputType(), ["category", "sku"])) {

It's the same method (getOperatorForValidate), but only on 2.2 it's using the sku inside the first if.

@sivaschenko
Copy link
Member

sivaschenko commented Jan 19, 2019

Thanks for the detailed explanation @igor-imaginemage !

The only my concern is the actual reason why the sku was added to the condition.

These two commits: 8d62341 and d5b596a were introduced to fix the issue #11897 .

In order to merge this pull request, it's required to ensure that the mentioned issue for multiple SKUs will not reappear. Would you be able to add proper handling of multiple SKUs condition to this pull request?

@igor-imaginemage
Copy link
Author

@sivaschenko, I just tested with mutiple skus and it's working correctly. I tested a cart rule with multiple skus and also a product list widget, as reported in the issue #11897. Both are working correctly.

This verifications on getOperatorForValidate that was including the sku attribute is not necessary, because if we want to use multiple skus we have to use the is one of options and not is. See here: https://prnt.sc/ma1ktf

This previous inclusion of sku was forcing the is to be a is one of comparator. The is has to compare only one item, and not multiple items.

@igor-imaginemage
Copy link
Author

@sivaschenko, this change that I've made in this PR is already on 2.1 and 2.3. By some reason is not available only on 2.2. Maybe who fixed that forgot to create the PR to 2.2.

@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko, thank you for the review.
ENGCOM-4000 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@igor-imaginemage thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@okorshenko okorshenko removed this from the Release: 2.2.8 milestone Jan 28, 2019
@sivaschenko
Copy link
Member

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko, here is your new Magento instance.
Admin access: https://pr-20412.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@ghost
Copy link

ghost commented Mar 20, 2019

Hi @igor-imaginemage, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@magento-engcom-team magento-engcom-team added this to the Release: 2.2.9 milestone Mar 20, 2019
@igor-imaginemage igor-imaginemage deleted the feature/2.2-fix-cart-rule-sku-condition branch March 20, 2019 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants