We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Define the extension attribute in XML

    app/code/Vendor/Module/etc/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="MagentoCheckoutApiDataShippingInformationInterface">
            <attribute code="address_two" type="string"/>
        </extension_attributes>
    </config>
    

    Assigning the value for extension attributes in knockout js 

    app/code/Vendor/Module/view/frontend/web/js/shipping-save-processor-default.js

    saveShippingInformation: function () {
                    var payload;
    
                    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: {
                                address_two: $('form.form-shipping-address input[name="address2"]').val()
                            }
                        }
                    };
    
                    return storage.post(
                        resourceUrlManager.getUrlForSetShippingInformation(quote),
                        JSON.stringify(payload)
                    ).done(
                        function (response) {
                            quote.setTotals(response.totals);
                            paymentService.setPaymentMethods(methodConverter(response.payment_methods));
                        }
                    ).fail(
                        function (response) {
                            errorProcessor.process(response);
                        }
                    );
                }

    Save Extension Attribute to quote table using beforeSaveAddressInformation method using Plugin

    app/code/Vendor/Module/Model/Checkout/ShippingInformationManagementPlugin.php

     

    namespace VendorModuleModelCheckout;
    /**
     * Class ShippingInformationManagementPlugin
     * @package OyeDeliverydateModelCheckout
     */
    class ShippingInformationManagementPlugin
    {
    
        protected $quoteRepository;
    
        /**
         * @param MagentoQuoteModelQuoteRepository $quoteRepository
         */
        public function __construct(
            MagentoQuoteModelQuoteRepository $quoteRepository
        ) {
            $this->quoteRepository = $quoteRepository;
        }
    
        /**
         * @param MagentoCheckoutModelShippingInformationManagement $subject
         * @param $cartId
         * @param MagentoCheckoutApiDataShippingInformationInterface $addressInformation
         */
        public function beforeSaveAddressInformation(
            MagentoCheckoutModelShippingInformationManagement $subject,
            $cartId,
            MagentoCheckoutApiDataShippingInformationInterface $addressInformation
        ) {
            $extAttributes = $addressInformation->getExtensionAttributes();
            $address2=$extAttributes->getAddressTwo();
    
            $quote = $this->quoteRepository->getActive($cartId);
            
            $quote->setShippingAddressTwo($shippngaddress2);    
            $this->quoteRepository->save($quote);;
    
        }
    }

     

    CONTACT US to get Magento programming solutions by hiring a certified Magento expert.

    field_5bfb909c5ccae

      Get a Free Quote