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 issue where address extension attributes would be set as an array #26707

Open
wants to merge 3 commits into
base: 2.4-develop
from

Conversation

@NathMorgan
Copy link
Contributor

NathMorgan commented Feb 5, 2020

Description (*)

This PR fixes a issue where the extension attributes in the $address parameter being sent to

private function getShippingMethods(Quote $quote, $address)
will get converted to an array. This causes an issue on
$address->getExtensionAttributes()->setDiscounts([]);
where it tries to access the extension attribute on the address as a object.

This fix sets the extension attribute back as a object after the addData() function gets called.

Related Pull Requests

Fixed Issues (if relevant)

  1. #26682: Magento 2.3.4 Quote Address Extension Attribute Issue

Manual testing scenarios (*)

  1. Create a custom extension attribute on the address field using this example module https://github.com/NathMorgan/module-test-module
  2. Call the estimate-shipping-methods passing the extension attribute. For example: {"address":{"street":["Example High Street"],"city":"Example City","region_id":null,"region":null,"country_id":"GB","postcode":"TES 01","company":"Example Company","telephone":"0000 00000","fax":null,"extension_attributes":{"test_attribute":"2"}}}

Questions or comments

Sadly I'm a bit unsure how to cover this with unit tests if anyone can provide assistance that would be much appericated

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 are green)
@m2-assistant

This comment has been minimized.

Copy link

m2-assistant bot commented Feb 5, 2020

Hi @NathMorgan. 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

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

@mrtuvn

This comment has been minimized.

Copy link

mrtuvn commented Feb 7, 2020

can you coverage your changes with tests
method getShippingMethods in corressponding class when get shipping with extension attributes

@Swahjak

This comment has been minimized.

Copy link

Swahjak commented Feb 11, 2020

@NathMorgan I think this could be easily covered by adding the 'discount' extension attribute to dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestShipmentEstimationTest.php like:

            $data = [
                AddressInterface::KEY_ID => (int)$address->getId(),
                AddressInterface::KEY_REGION => $address->getRegion(),
                AddressInterface::KEY_REGION_ID => $address->getRegionId(),
                AddressInterface::KEY_REGION_CODE => $address->getRegionCode(),
                AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(),
                AddressInterface::KEY_STREET => $address->getStreet(),
                AddressInterface::KEY_COMPANY => $address->getCompany(),
                AddressInterface::KEY_TELEPHONE => $address->getTelephone(),
                AddressInterface::KEY_POSTCODE => $address->getPostcode(),
                AddressInterface::KEY_CITY => $address->getCity(),
                AddressInterface::KEY_FIRSTNAME => $address->getFirstname(),
                AddressInterface::KEY_LASTNAME => $address->getLastname(),
                AddressInterface::KEY_CUSTOMER_ID => $address->getCustomerId(),
                AddressInterface::KEY_EMAIL => $address->getEmail(),
                AddressInterface::SAME_AS_BILLING => $address->getSameAsBilling(),
                AddressInterface::CUSTOMER_ADDRESS_ID => $address->getCustomerAddressId(),
                AddressInterface::SAVE_IN_ADDRESS_BOOK => $address->getSaveInAddressBook(),
                ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => [
                    'discounts' => []
                ],
            ];
...
            $requestData = [
                'address' => [
                    'country_id' => "US",
                    'postcode' => null,
                    'region' => null,
                    'region_id' => null,
                    ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => [
                        'discounts' => []
                    ]
                ],

The 'discounts' extension is part of the SalesRule module so I'm not sure if you have to modify the existing test or create a new test in the SalesRule test directory. Maybe @mrtuvn has a useful comment on that.

@NathMorgan

This comment has been minimized.

Copy link
Contributor Author

NathMorgan commented Feb 12, 2020

I've got another change to make to the code in this PR as I've noticed this fix currently breaks logged in customers with saved addresses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pull Requests Dashboard
  
Pending Review
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.