Define the extension attribute in XML
app/code/Vendor/Module/etc/extension_attributes.xml
1 2 3 4 5 6 |
<?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="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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
namespace Vendor\Module\Model\Checkout; /** * Class ShippingInformationManagementPlugin * @package Oye\Deliverydate\Model\Checkout */ class ShippingInformationManagementPlugin { protected $quoteRepository; /** * @param \Magento\Quote\Model\QuoteRepository $quoteRepository */ public function __construct( \Magento\Quote\Model\QuoteRepository $quoteRepository ) { $this->quoteRepository = $quoteRepository; } /** * @param \Magento\Checkout\Model\ShippingInformationManagement $subject * @param $cartId * @param \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation */ public function beforeSaveAddressInformation( \Magento\Checkout\Model\ShippingInformationManagement $subject, $cartId, \Magento\Checkout\Api\Data\ShippingInformationInterface $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.
[crayon-63d3d698bbfa8504840315/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.