Skip to content

Ensures that the quote's customer is set on newly created quotes#5344

Open
azambon wants to merge 13 commits into
OpenMage:mainfrom
azambon:patch-5
Open

Ensures that the quote's customer is set on newly created quotes#5344
azambon wants to merge 13 commits into
OpenMage:mainfrom
azambon:patch-5

Conversation

@azambon
Copy link
Copy Markdown
Contributor

@azambon azambon commented Mar 23, 2026

I've recently encountered a bug where, upon first creating a new quote, the quote's customer_id field was not set.
Later requests by the same customer (possibly sent from a different device with a different session cookie) then attempted to load the active quote for the same customer_id but, since the quote didn't have the customer_id field set, the load operation didn't find anything and a second quote was created.
And then, somehow, the first quote was populated with the customer_id value.

The end result was that we ended up with multiple active quotes for the same customer in the same store view, which should not happen.

This fix should make sure that the customer_id field is set right away even for newly created quotes whenever a customer is available.

Unfortunately I don't have a testing scenario. In our site we implemented a "remember me" feature that uses Magento's persistent session, and I suspect that such "remember me" is what causes this bug to surface.

Having said that, the fix is just a couple lines of code, so it should be easy to inspect. And I haven't seen any new occurrences of the issue ever since applying this fix so... your call.

I've encountered a bug where upon first creating a new quote, the quote's customer_id field was not set. Later requests then attempted to load the active quote for the same customer but, since the quote didn't have the customer_id field set, the load operation didn't find anything and a second quote was created.
This should make sure that the customer_id field is set right away even for newly created quotes whenever a cusotmer is available.
Copilot AI review requested due to automatic review settings March 23, 2026 08:40
@github-actions github-actions Bot added the Component: Checkout Relates to Mage_Checkout label Mar 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a checkout-session edge case where a newly created quote can remain without customer_id, which can lead to duplicate active quotes for the same customer (especially in persistent/“remember me” scenarios).

Changes:

  • Adjusts Mage_Checkout_Model_Session::getQuote() to set a customer on the quote even when the quote is newly created (no quote_id yet).

Comment thread app/code/core/Mage/Checkout/Model/Session.php Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@sreichel sreichel added the review needed Problem should be verified label Mar 25, 2026
@sonarqubecloud
Copy link
Copy Markdown

@sreichel sreichel added this to the 20.19.0 milestone May 4, 2026
@sreichel
Copy link
Copy Markdown
Contributor

sreichel commented May 4, 2026

Thanks. Pls run composer run phpstan:baseline

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread app/code/core/Mage/Checkout/Model/Session.php Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread app/code/core/Mage/Checkout/Model/Session.php Outdated
Comment thread .phpstan.dist.baselines/booleanOr.leftNotBoolean.php Outdated
@sreichel
Copy link
Copy Markdown
Contributor

a3ca823

  • return type for getQuoteId is incomplete and should be update (null|int) ... casting to bool is not required
  • check for !is_null

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

}

if ($this->getQuoteId() && ($customerSession->isLoggedIn() || $this->_customer)) {
if ((!is_null($this->getQuoteId()) || !$quote->getCustomerId()) && ($customerSession->isLoggedIn() || $this->_customer)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Checkout Relates to Mage_Checkout phpstan review needed Problem should be verified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants