Magento 2 – Property Does Not Have Accessor Method in ShippingInformationExtensionInterface

checkoutextension-attributesmagento2

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 🙂

Best Answer

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.

Related Topic