2

I added custom check box field in checkout 1st step below Shipping Methods section.

enter image description here

how to check is checked or not when i click next button,so based on this I can add custom fee in order totals.

when I click next button its calling rest api ShippingInformationManagement.

i think i need to override saveAddressInformation method in ShippingInformationManagement class.

Please find below for more details.

https://github.com/sivajik34/Delivery-Signature-Magento2

6

Follow the step:

how to check is checked or not when i click next button,so based on this I can add custom fee in order totals.

--You need to js saveShippingInformation method by following way. Create a requirejs-config.js [Vendor/Module/view/frontend/requirejs-config.js]


var config = {
    "map": {
        "*": {
            'Magento_Checkout/js/model/shipping-save-processor/default': 'vendor_Module/js/model/shipping-save-processor/default'
        }
    }
};

Now create default.js[Vendor/Module/view/frontend/web/js/model/shipping-save-processor/default.js]

Here you need to pass additional param. Here is an example Check following params


extension_attributes:{
                            delivery_date: $('[name="delivery_date"]').val()
                        }

Now you can able to pass value to api.

Create Vendor/Module/etc/di.xml for pluginize ShippingInformationManagement.


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\ShippingInformationManagement">
        <plugin name="sr_save_delivery_date_in_quote" type="Vendor\Module\Plugin\Checkout\Model\ShippingInformationManagement" sortOrder="1"/>
    </type>
</config>

Create Vendor/Module//Plugin/Checkout/Model/ShippingInformationManagement.php


namespace Vendor\Module\Plugin\Checkout\Model;
class ShippingInformationManagement
{
    protected $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();
        $deliveryDate = $extAttributes->getDeliveryDate();
    }
}

Create 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="Magento\Checkout\Api\Data\ShippingInformationInterface">
        <attribute code="delivery_date" type="string"/>
    </extension_attributes>
</config>

You can use this module as an example

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.