experius / Magento-2-Module-Experius-ExtraCheckoutAddressFields

Add Extra Address Attributes to the Magento 2 Checkout
GNU General Public License v3.0
41 stars 25 forks source link

Error occurred during "shipping_address" processing on guest checkout #11

Open sorinsinner opened 5 years ago

sorinsinner commented 5 years ago

I can't seem to get around this. Everything is working perfectly for logged in customer checkout (both frontend, and admin side).

But guest customer cannot place error with the following error coming up in the first step (Shipping) of checkout:

Error occurred during "shipping_address" processing. Error occurred during "customAttributes" processing. A custom attribute is specified with a missing attribute code. Verify the code and try again.

Can you help me figure this out? Checked on two different Magento 2.3 installations. One was fresh made just for testing this, and the other one is also 2.3 but with a theme applied.

svijany commented 5 years ago

Did you ever resolve this issue?

IonutGorgos commented 5 years ago

I have just found a solution. You need to rename the "customAttributes" key from the JSON that will be sent to guest-rest-api, with "custom_attributes".

Here you can find the documentation: https://devdocs.magento.com/redoc/2.3/guest-rest-api.html#operation/checkoutGuestShippingInformationManagementV1SaveAddressInformationPost

Jyotishina commented 5 years ago

Hey @IonutGorgos could you eloborate how does the issue is resolved? did you override core code

IonutGorgos commented 5 years ago

Hello,

I think that the solution wasn't to rename the "customAttributes" key. I did other things too. I will enumerate the steps.

  1. You need to create another plugin for GuestPaymentInformationManagement. Copy and paste this code in etc/di.xml file.
<type name="Magento\Checkout\Model\GuestPaymentInformationManagement">
        <plugin disabled="false" name="Experius_ExtraCheckoutAddressFields_Plugin_Magento_Checkout_Model_GuestPaymentInformationManagement"
                sortOrder="10" type="Experius\ExtraCheckoutAddressFields\Plugin\Magento\Checkout\Model\GuestPaymentInformationManagement"/>
</type>
  1. Create the file Plugin/Magento/Checkout/Model/GuestPaymentInformationManagement.php You can copy and paste the PaymentInformationManagement.php file from the same folder and just add the email param in the beforeSavePaymentInformation method.

beforeSavePaymentInformation method:

public function beforeSavePaymentInformation(
        \Magento\Checkout\Model\GuestPaymentInformationManagement $subject,
        $cartId,
        $email,
        PaymentInterface $paymentMethod,
        AddressInterface $address
    ) {
        $extAttributes = $address->getExtensionAttributes();
        if (!empty($extAttributes)) {
            $this->helper->transportFieldsFromExtensionAttributesToObject(
                $extAttributes,
                $address,
                'extra_checkout_billing_address_fields'
            );
        }
    }
  1. Now, if you did all this steps, the following error will occur: "Property "0" does not have accessor method "get0" in class "Magento\Quote\Api\Data\AddressExtensionInterface"." That is because you need to do some changes in view/frontend/web/js/action/set-shipping-information-mixin.js

We need to have the extension_attributes key something like that:

{
 attribute_code1_key: "attribute_code1_value",
 attribute_code2_key: "attribute_code2_value",
 ....... ....... ....... ....... ....... ........
 attribute_codeN_key: "attribute_codeN_value",
}
  1. Some changes in view/frontend/web/js/action/set-shipping-information-mixin.js:
            if (shippingAddress.customAttributes !== undefined) {
                $.each(shippingAddress.customAttributes, function (key, value) {

                    var attrCode = value['attribute_code'];
                    var attrValue = value['value'];

                    shippingAddress['customAttributes'][attrCode] = value;
                    shippingAddress['extension_attributes'][attrCode] = attrValue;
                });
            }
  1. Some changes in view/frontend/web/js/action/create-shipping-address-mixin.js:

            if (messageContainer.custom_attributes != undefined) {
                $.each(messageContainer.custom_attributes , function( key, value ) {
                    messageContainer['custom_attributes'][key] = value;
                });
            }
  2. Some changes in view/frontend/web/js/action/set-billing-address-mixin.js:

    
                if (billingAddress.customAttributes != undefined) {
                    $.each(billingAddress.customAttributes, function (key, value) {
    
                        var attrCode = value['attribute_code'];
                        var attrValue = value['value'];
    
                        billingAddress['extension_attributes'][attrCode] = attrValue;
                    });
                }
  3. Don't forget the fieldset.xml and extensions_attributes.xml files.

Jyotishina commented 5 years ago

Hey @IonutGorgos Im still getting get0 exception while changing set-shipping-information-mixins could you share updated code and files please so that could everyone get cleared:

jyotishina94@gmail.com

Jyotishina commented 5 years ago

Report ID: webapi-5d4c9c422969a; Message: Property "0" does not have accessor method "get0" in class "Magento\Quote\Api\Data\AddressExtensionInterface". {"exception":"[object] (Exception(code: 0): Report ID: webapi-5d4c9c422969a; Message: Property \"0\" does not have accessor method \"get0\" in class \"Magento\Quote\Api\Data\AddressExtensionInterface\". at /home/dev73onlinetesti/public_html/magento/project-community-edition/vendor/magento/framework/Webapi/ErrorProcessor.php:206, LogicException(code: 0): Property \"0\" does not have accessor method \"get0\" in class \"Magento\Quote\Api\Data\AddressExtensionInterface\". at /home/dev73onlinetesti/public_html/magento/project-community-edition/vendor/magento/framework/Reflection/NameFinder.php:100)"} []

Jyotishina commented 5 years ago

@sorinsinner did you resolve issue?

KovalskiWeb commented 5 years ago

Has anyone solved this problem?

Jyotishina commented 5 years ago

yes its solved by your solution of files thanks.

On Fri, Aug 30, 2019 at 6:00 PM KovalskiWeb notifications@github.com wrote:

Has anyone solved this problem?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/experius/Magento-2-Module-Experius-ExtraCheckoutAddressFields/issues/11?email_source=notifications&email_token=AFZ56DQY7DA7XFTURXLVBFDQHERYTA5CNFSM4G5FAHS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5RXSMI#issuecomment-526612785, or mute the thread https://github.com/notifications/unsubscribe-auth/AFZ56DX2P2DUHPVQKP5LSILQHERYTANCNFSM4G5FAHSQ .

RonakParmar commented 4 years ago

Is anyone has fix of this issue? Tried above solution but still getting same error.

hmhosseini commented 4 years ago

hi,problem still remains any solution ?