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.5k stars 9.31k forks source link

Customer unable to place order with new address #29288

Closed martynas-al closed 3 years ago

martynas-al commented 4 years ago

Preconditions (*)

  1. Magento version: 2.3.5-p1
  2. Customer object needs to have extension attribute data

Steps to reproduce (*)

  1. Log in as a customer which has extension attribute data
  2. Add product to cart
  3. In checkout step add new shipping address and add checkbox to save it.
  4. Place an order with newly added address.

Expected result (*)

  1. Order created successfully

Actual result (*)

  1. I get "Invalid state change requested" error message

I did some digging around and basically figured out why this happens. Magento calls Magento\Quote\Model\ChangeQuoteControl::isAllowed before quote is saved and performs a check to see if customer_id in quote and in user's context match and it doesn't if customer added new shipping address which needs to be saved.

The customer_id doesn't match because a couple of steps before Magento\Quote\Model\Quote::setCustomer is called. In this method customer object is beeing flattened and the flattened values are set as quote values. While customer flattening happens, Magento\Framework\Convert\ConvertArray::toFlatArray is called and this is where the issue happens. If your customer object has extension attributes which have id field in them, then after flattening customer object's id becomes the id value of the last processed extension attribute's ID. Basically, because of recursive calls array_merge overrides previously set values.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 4 years ago

Hi @martynas-al. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

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

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

Please, add a comment to assign the issue: @magento I am working on this


: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, please join the Community Contributions Triage session to discuss the appropriate ticket.

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

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

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

MeCapron commented 2 years ago

Hello,

I reopen this issue as I bump into this earlier.

To add a bit explanations just look at :

    public function toFlatArray(
        ExtensibleDataInterface $dataObject,
        $skipCustomAttributes = [],
        $dataObjectType = null
    ) {
        $dataObjectArray = $this->toNestedArray($dataObject, $skipCustomAttributes, $dataObjectType);
        return ConvertArray::toFlatArray($dataObjectArray);
    }

in magento/framework/Api/ExtensibleDataObjectConverter.php

Having the same attribute name as customer one in your extension attribute will result in your extension attribute overriding customer one.

Example :

{
    "id": "172",
    "extension_attributes": {
         "posts": [
               {
                    "id": "187",
                    "desc": "test"
               }
         ]
    }
}

Will give the customer with the wrong ID, 187 in this case.

I think that the "ConvertArray::toFlatArray" method must skip extension attributes in its transform process.

Can we have any help on this?

Thanks you