3

I had some customization on Shipping page of checkout on Magento2, now I want to send out some data back to my module by the user hitting "Next" button and add to the current cart, so in which way should I do this?

2 Answers 2

6

When you progress from the 'Shipping' step to the 'Review & Payment' step, an API request is sent to this function \Magento\Checkout\Model\ShippingInformationManagement::saveAddressInformation. You can view the js that sends the request here `Magento\Checkout\view\frontend\web\js\model\shipping-save-processor\default.js'

To send data to your module you can write a plugin for the saveAddressInformation method. For more information on how to write a plugin, see this documentation page:

http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html

3
  • one question, I tried to alert out the url of the post request in the above mentioned default.js file(which is resourceUrlManager.getUrlForSetShippingInformation(quote)) and got rest/default/V1/carts/mine/shipping-information. Could you explain its meaning?
    – Joel
    Jan 12, 2016 at 16:39
  • 1
    If you look in Magento/Checkout/etc/webapi.xml you will see several routes. The url you got in your alert points to the shipping-information route which defines which service will receive the payload. You can read more about the webapi.xml configuration file here devdocs.magento.com/guides/v2.0/extension-dev-guide/… Jan 12, 2016 at 16:44
  • Million thanks, I will try this out and tell you if this works :)
    – Joel
    Jan 13, 2016 at 1:52
1
  1. Make a module
  2. Use an obsever on the right event
  3. Implement your code for the observer to make the changes you wish

See for more details: https://firebearstudio.com/blog/magento-2-observers.html

Here is al list of events: http://cyrillschumacher.com/magento2-list-of-all-dispatched-events/

I think you are looking for checkout_cart_product_add_after but I am not sure depending on your explanation.

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.