5

I am working on custom extension and need to execute my code when the customer clicks on "Next" button available in checkout.

I need an event observer in which, used shipping and billing address selected or added by customer.

See screenshot.

enter image description here

4
  • what about sales_quote_collect_totals_after ?
    – Keyur Shah
    Nov 9, 2016 at 13:09
  • @KeyurShah already try that event, but not working. Nov 9, 2016 at 13:10
  • What do you mean by not working ? this event always execute
    – Keyur Shah
    Nov 9, 2016 at 13:12
  • @KeyurShah can give me sample code using which, I get selected address into of customer. I need event only for this action not every time cart is reload or other function. Nov 9, 2016 at 13:19

1 Answer 1

5

You should use plugin to get the shipping info:

Your di should be under etc folder: app/code/Extension/Vendor/etc/di.xml

<?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="get_shipping_info" type="Vendor\Module\Plugin\Checkout\Model\ShippingInformationManagement" sortOrder="1"/>
    </type>
</config>

Your Plugin:

/**
     * @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
    )
    {
       ......
    }

    public function afterSaveAddressInformation(
        \Magento\Checkout\Model\ShippingInformationManagement $shipping,
         $result
    )
    {
        ......
    }
17
  • I will check and let you know. Nov 9, 2016 at 13:19
  • I am try above code, but in not called our function when we click on "Next" button. Nov 10, 2016 at 4:52
  • Which is your function? the saveAddressInformation() function will be called when click Next. Nov 10, 2016 at 4:58
  • I try to implement this public function afterSaveAddressInformation but not called Nov 10, 2016 at 5:06
  • Updated my answer. Nov 10, 2016 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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