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

ISSUE-20004: Refactoring minimum order amount including tax value in the calculate #33327

Open
wants to merge 8 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

viniciusbord9
Copy link

@viniciusbord9 viniciusbord9 commented Jun 23, 2021

Description (*)

It fixes the issue reported when the tax value was not taking account when the minimum order amount was blocking the customer proceed to checkout even when the grant total of the cart was bigger than the minimum order amount value.

Related Pull Requests

#33316

That PR has been closing by me due to some confusion author for the commits.

Fixed Issues (if relevant)

  1. Fixes Enable Minimum order amount with Include Tax to Amount configuration. it's not working on magento 2 default functionality. #20004

Manual testing scenarios (*)

  1. See Enable Minimum order amount with Include Tax to Amount configuration. it's not working on magento 2 default functionality. #20004

Questions or comments

I have created a new boolean field (is_minimum_order_amount) on the Magento/Quote/Api/Data/TotalsInterface.php that can impact positively the APIs that returns that entity. It will include a flag that indicates if the quote's total value is bigger than the minimum order amount.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] ISSUE-20004: Refactoring minimum order amount including tax value in the calculate #33490: ISSUE-20004: Refactoring minimum order amount including tax value in the calculate

@m2-assistant
Copy link

m2-assistant bot commented Jun 23, 2021

Hi @viniciusbord9. Thank you for your contribution
Here are 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

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

@m2-community-project m2-community-project bot added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. labels Jun 23, 2021
@viniciusbord9
Copy link
Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@viniciusbord9
Copy link
Author

@magento run Unit Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@viniciusbord9
Copy link
Author

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@viniciusbord9
Copy link
Author

viniciusbord9 commented Jun 23, 2021

Part of the tests that not pass are not related to my changes:

Magento\Security\Model\UserExpiration\ValidatorTest::testValidateUserExpiresAt with data set "non_default_english_textual" ('de_DE')
Failed asserting that false is true.
Failed asserting that any element by '//tr[1]//td[count(//div[@data-role='grid-wrapper']//tr//th[contains(., 'Quantity per Source')]/preceding-sibling::th) +1 ]//*[text()='Test Source 1 60d3832e7ff7b2']/following-sibling::span' on page /admin/catalog/product/index
Elements: 
+ <span> 100
contains text '99'

But the Semantic Version checker really gets some changes that I did on the interface, but I do not now what I should do in that case to pass that test.

Please let me know if you have any questions.

Copy link
Contributor

@Den4ik Den4ik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viniciusbord9 Thanks for your work.

But the Semantic Version checker really gets some changes that I did on the interface, but I do not now what I should do in that case to pass that test.

You may find answer to this question in Backward Compatibility Policy

Introduction of a method to a class or interface
Create a new interface with a new method instead of introducing a method to a class or interface.

The new interface may take over existing methods from the class if it makes sense to group them together. In this case, you must deprecate corresponding methods in the old interface/class with the @see annotation. The old methods should proxy the calls to the new interface instead of duplicating the logic.

@viniciusbord9
Copy link
Author

@Den4ik thank you for the clarification. I am going to do it soon.

@viniciusbord9
Copy link
Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@viniciusbord9
Copy link
Author

@magento run Functional Tests CE

@viniciusbord9
Copy link
Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@Den4ik
Copy link
Contributor

Den4ik commented Jul 12, 2021

@magento run Functional Tests EE, Functional Tests CE, Functional Tests B2B

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@viniciusbord9
Copy link
Author

@Den4ik I have created a new functional test for the order minimum amount, it is working smoothly on my local, but it is broken during the automated tests. Basically the button 'proceed to checkout' should be disabled when accessing the cart page but it is not. I saw the screenshot of the test and I am wonder why it is rendering the multiple addresses option right below the proceed checkout button even when the minimum amount is enabled and active on the checkout. Can you help me to understand what is wrong with the test?

@viniciusbord9
Copy link
Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@viniciusbord9
Copy link
Author

@Den4ik I've pushed a new update that fix the issue that I mentioned previously, therefore, you can ignore my last comment asking for help. Now the functional tests are working well. Those two tests that have broken (Functional Tests EE, Functional Tests B2B) are not related to my changes and they seem be another issue.

Please let me know if anything is not like you expected.

@Den4ik
Copy link
Contributor

Den4ik commented Jul 15, 2021

@magento create issue

Copy link
Contributor

@Den4ik Den4ik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viniciusbord9 Could you check my comments

@@ -475,7 +475,7 @@ public function getTotalSegments();
* @return $this
*/
public function setTotalSegments($totals = []);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rollback

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

<click selector="{{CheckoutCartSummarySection.shippingMethodElementId('freeshipping', 'freeshipping')}}" stepKey="selectShippingMethod"/>
<scrollTo selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="scrollToProceedToCheckout" />
<actionGroup ref="StorefrontClickProceedToCheckoutActionGroup" stepKey="goToCheckout"/>
<comment userInput="Adding the comment to replace waitForPageToLoad action for preserving Backward Compatibility" stepKey="waitForPageToLoad"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment block used on refactored mftf tests to preserve backward compatibility and don't needed in new mftf tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Please review again when you have a chance.

@@ -2298,6 +2298,8 @@ public function validateMinimumAmount($multishipping = false)
$storeId
);

$this->collectTotals()->save();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that triggering recollect totals in this method is good solution.
I believe that we can extend QuoteRepository with additional param triggerRecollect that will set triggerRecollect data at Quote object.
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Quote/Model/Quote.php#L2461-L2470

@ihor-sviziev what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viniciusbord9 Could you pay attention to this comment? Extending of QuoteRepository allow to reuse recollect functional in a future.
Or may be you have another points for this case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Den4ik

I was waiting for an answer from @ihor-sviziev to whom you asked for sooner. I am going to try to implement your idea and check if it is viable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Den4ik I think it's a good idea

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Den4ik @ihor-sviziev

I was developing the new repository extending the QuoteRepository as suggested and due to a necessity of injecting the repository for two classes(TotalsInformationManagement, CartTotalRepository) , I have realized that maybe the current flow was not working well.

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Model/TotalsInformationManagement.php

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Quote/Model/Cart/CartTotalRepository.php

The class TotalsInformationManagement depends on the CartTotalRepository and apply changes to the quote but do not save the data

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Model/TotalsInformationManagement.php#L48-L61

I have only change the line 61 from $quote->collectTotals(); to $quote->collectTotals()->save(); and then my changes worked as expected.

I have finished the implementation of the QuoteRepository supporting an additional parameter $triggerRecollect with default value 0. If you still think that change is the best one I will proceed, but to be honest I think it is too big that fix.

@m2-community-project m2-community-project bot moved this from Changes Requested to Review in Progress in High Priority Pull Requests Dashboard Jul 24, 2021
@viniciusbord9
Copy link
Author

@magento run all tests 

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@m2-community-project m2-community-project bot moved this from Review in Progress to Changes Requested in High Priority Pull Requests Dashboard Jul 25, 2021
@m2-community-project m2-community-project bot moved this from Changes Requested to Review in Progress in High Priority Pull Requests Dashboard Jul 26, 2021
@ihor-sviziev ihor-sviziev removed their assignment Jul 26, 2021
@ishakhsuvarov ishakhsuvarov moved this from Review in Progress to Pending Review in High Priority Pull Requests Dashboard Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Component: Checkout Component: Quote Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review Release Line: 2.4 Severity: S2 Major restrictions or short-term circumventions are required until a fix is available.
Projects
None yet
5 participants