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

Fix getReservedOrderId() to use current store instead of default store #11702

Conversation

tdgroot
Copy link
Member

@tdgroot tdgroot commented Oct 24, 2017

Description

Fix getReservedOrderId() to use current store instead of default store. When placing orders from a new store view under the same website, it would use the reserved order id from the default store view.

In the image below, you'll the first 2 created orders without the fix. The last order(2000000001) is after the fix and you'll see the increment id corresponds to the store view.
image

I also saw a typo in Quote::substractProductFromQuotes() and refactored the method. I created a placeholder for the old method and deprecated it.

So this problem is fixed this way, but I'm wondering why it was implemented like this in the first place. Does this have implications for Single Store Mode? I'd say it wouldn't, but I think it's good to be sure. Please let me know :)

Fixed Issues (if relevant)

  1. Default Store is always used when retrieving sequence value's for sales entity's. #9055

Manual testing scenarios

  1. Setup a clean install of Magento
  2. Add a second store view to the default website
  3. Place an order on the second store view

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)
  • All automated tests passed successfully (all builds on Travis CI are green)

@ihor-sviziev
Copy link
Contributor

@tdgroot I think we we need to add unit test for reserved order id, check that it now actually use current store. It will prevent do regression in this place

@tdgroot
Copy link
Member Author

tdgroot commented Oct 25, 2017

Fair point, I'm on it.

@tdgroot
Copy link
Member Author

tdgroot commented Oct 25, 2017

@ihor-sviziev Unit test added!

@@ -167,7 +167,7 @@ public function getReservedOrderId($quote)
{
return $this->sequenceManager->getSequence(
\Magento\Sales\Model\Order::ENTITY,
$quote->getStore()->getGroup()->getDefaultStoreId()
$quote->getStore()->getStoreId()
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that $quote has method getStoreId(). Isn't it better to use it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the review.

I'd say that's better indeed, but it shouldn't matter nonetheless. If you want it to use $quote->getStoreId() I can change that.

@tdgroot
Copy link
Member Author

tdgroot commented Oct 25, 2017

@ihor-sviziev I changed it to $quote->getStoreId() and the concerning Test. I also improved the test to make sure the method returns the same value as the sequence value.

@fooman
Copy link
Contributor

fooman commented Oct 25, 2017

@tdgroot Thanks for this pull request and working on adding tests. We'll wait to see what Travis reports back.

I generally agree with the proposed fix.

One thing I am concerned about is, when we roll out this change it changes the behaviour of existing stores. So people that already have stores running with order numbers 00000002 would all over a sudden start getting order numbers like 200000003 which would be unexpected.

Any thoughts on this and what could be done to mitigate it?

Also for the deprecated notice 101.0.0 is the currently already released version - the next one where this change would be included in the develop-2.2 branch would currently be 101.0.1.

@tdgroot
Copy link
Member Author

tdgroot commented Oct 26, 2017

@fooman Well we could write a data upgrade to set the prefix to NULL for every additional store view in a website so the increment ids stay consistent. But that doesn't feel right, because their order numbers are bugged now, and after applying this fix, that problem is solved. It'd be better to make sure this change is mentioned in the release notes.

As for the deprecation: the version number now is 101.0.1 :).

@fooman
Copy link
Contributor

fooman commented Oct 26, 2017

@tdgroot thanks for the updates and thoughts. Let me get some wider feedback on how best to deal with existing stores.

@magento-engcom-team magento-engcom-team added 2.2.x Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 7, 2017
@dverkade
Copy link
Member

@fooman We have several clients complaining about this issue, because the behaviour of M2 right now is different then the expected behaviour of the user and the behaviour of Magento 1. So from a user perspective it's already broken and needs to be fixed. Therefor I do not see an issue when the prefixes will be changed.

@okorshenko
Copy link
Contributor

Update: we are waiting for approval from Product Owner of this feature

@okorshenko
Copy link
Contributor

Update: Product Owner approved this change. Thank you everyone for collaboration

@magento-team magento-team merged commit f76d7cb into magento:2.2-develop Dec 12, 2017
magento-team pushed a commit that referenced this pull request Dec 12, 2017
@tdgroot
Copy link
Member Author

tdgroot commented Dec 12, 2017

@okorshenko Thanks for finalizing this PR! Will this change get merged in 2.3 branch by Magento engineering or does it need another backport PR?

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Dec 12, 2017
@ihor-sviziev
Copy link
Contributor

@tdgroot accepting PRs are usually much faster. Could you please create PRs with the same changes to 2.1-develop and 2.3-develop branches?

@tdgroot tdgroot deleted the 2.2-develop-fix_getreservedorderid_current_store_id branch June 2, 2018 15:51
@mimou78
Copy link

mimou78 commented Feb 27, 2019

Hello,

I think this is not a good solution.
I think the best solution is to make this configurable.
because in my case I use the storeview to have two languages in my site. I do not have to have a different incremetation per language.

Thanks

@ihor-sviziev
Copy link
Contributor

Hi @mimou78,
It looks like a feature request. PR is welcomed 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants