0

I'm working on get extension attribute through checkout page
And i did it correctly(i thing), check this image below, the extension_attribute is rendered. enter image description here

But when i click on "Next" button, it appear an error:

Property "AmdeliverydatePo" does not have accessor method "getAmdeliverydatePo" in class "Magento\Checkout\Api\Data\ShippingInformationExtensionInterface

I don't know how to fix this error or have any solution for this, i've searched a lot but still no hope :(
Here is what i've done:

extension_attributes.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Checkout\Api\Data\ShippingInformationInterface">
        <attribute code="amdeliverydate_po" type="string"/>
    </extension_attributes>

    <extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
        <attribute code="amdeliverydate_po" type="string"/>
    </extension_attributes>
</config>

default.js

define(
    [
        'jquery',
        'underscore',
        'ko',
        'Magento_Checkout/js/model/quote',
        'Magento_Checkout/js/model/resource-url-manager',
        'mage/storage',
        'Magento_Checkout/js/model/payment-service',
        'Magento_Checkout/js/model/payment/method-converter',
        'Magento_Checkout/js/model/error-processor',
        'Magento_Checkout/js/model/full-screen-loader',
        'Magento_Checkout/js/action/select-billing-address'
    ],
    function (
        $,
        _,
        ko,
        quote,
        resourceUrlManager,
        storage,
        paymentService,
        methodConverter,
        errorProcessor,
        fullScreenLoader,
        selectBillingAddressAction
    ) {
        'use strict';

        return {
            saveShippingInformation: function () {
                var payload;

                if (!quote.billingAddress()) {
                    selectBillingAddressAction(quote.shippingAddress());
                }

                payload = {
                    addressInformation: {
                        shipping_address: quote.shippingAddress(),
                        billing_address: quote.billingAddress(),
                        shipping_method_code: quote.shippingMethod().method_code,
                        shipping_carrier_code: quote.shippingMethod().carrier_code,
                        extension_attributes:{
                            amdeliverydate_comment: $('[name="amdeliverydate_comment"]').val(),
                            amdeliverydate_po: $('[name="amdeliverydate_po"]').val()
                        }
                    }
                };

                fullScreenLoader.startLoader();

                return storage.post(
                    resourceUrlManager.getUrlForSetShippingInformation(quote),
                    JSON.stringify(payload)
                ).done(
                    function (response) {
                        quote.setTotals(response.totals);
                        paymentService.setPaymentMethods(methodConverter(response.payment_methods));
                        fullScreenLoader.stopLoader();
                    }
                ).fail(
                    function (response) {
                        errorProcessor.process(response);
                        fullScreenLoader.stopLoader();
                    }
                );
            }
        };
    }
);

Thanks for reading :)

  • 1
    have you tried to remove the generated folder? Magento generates ExtensionInterfaces on the fly in developer mode or during setup:di:compile in production mode. If everything is ok with your xml it has to be probably generated once again. – Sebastian Oct 22 '18 at 12:10
  • @Sebastian Oh my god, you rock, saved my day bro :") I've spend about 4 or 5 hours to looking for this but i forgot 1 important thing that i should not forgot, delete "generated" folder :( Please answer it so i can give you 1 up vote and tick in your answer :) – fudu Oct 22 '18 at 13:33
4

You need to remove generated folder. Magento generates ExtensionInterfaces on the fly in developer mode or during setup:di:compile in production mode. If everything is ok with your xml it has to be, probably, generated once again.

  • Thank you!! A couple of hours pulling my hair off, just to realise the "magic" of Magento's auto-generated code :D – Manuel García Solipa Sep 18 '19 at 11:52
  • @sebastian you are a legend – jibin george Oct 17 '19 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.