Hello,
I am creating the custom module , In this After user registration successfully i want to call another third party api.
Can u pls help me how i can do this.
Solved! Go to Solution.
@amarpreetbd709
You can call your API function in observer function after success.
It will work in background after customer success.
for example:
public function execute( \Magento\Framework\Event\Observer $observer ) { $customer = $observer->getEvent()->getData('customer'); $this->callPostAPI(); }} public function callPostAPI() { // write you code here }
Hi @amarpreetbd709
Try the below code in Observer:
<?php namespace Cheermes\Widget\Observer\Checkout; class SubmitAllAfter implements \Magento\Framework\Event\ObserverInterface { /** * Execute observer * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute( \Magento\Framework\Event\Observer $observer ) { //Your observer code } }
Event add the following in existing
<event name="checkout_submit_all_after"> <observer instance="Cheermes\Widget\Observer\Checkout\SubmitAllAfter" name="cheermes_widget_observer_checkout_submitallafter_checkout_submit_all_after"/> </event>
I hope it will work!
Hi @amarpreetbd709
You can do using event observer.
Create a new module and use customer_register_success event.
more info : https://magento.stackexchange.com/a/262227
I hope it will help you!
Hi Vinod,
Can u pls also tell me how i can use third party post api in it.
Thanks
@amarpreetbd709
You can call your API function in observer function after success.
It will work in background after customer success.
for example:
public function execute( \Magento\Framework\Event\Observer $observer ) { $customer = $observer->getEvent()->getData('customer'); $this->callPostAPI(); }} public function callPostAPI() { // write you code here }
Hi Vimal,
Thanks, Now my third party api is working after user registration.
Now, can pls tell me how i can use third party after order placed successfully.
Hi @amarpreetbd709
Glad to know that it is working fine.
Same for order success you can use checkout_submit_all_after event for order success.
https://magento.stackexchange.com/a/190535
I hope it will help you!
hi @Vimal Kumar
I use the same way as u tell but it show "Sometime went wrond message at the time of placing the order.
Code that i use in events.xml file.
<?xml version="1.0" ?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="customer_register_success"> <observer instance="Cheermes\Widget\Observer\Customer\RegisterSuccess" name="customer_register_succes"/> </event> <event name="checkout_submit_all_after"> <observer instance="Cheermes\Widget\Observer\ProcessOrder" name="cheermes_widget_checkout_submit_all_after"/> </event> </config>
And in Observer folder I created the file ProcessOrder.php:
<?php namespace Cheermes\Widget\Observer; class ProcessOrder implements \Magento\Framework\Event\ObserverInterface { public function __construct() { } public function execute(\Magento\Framework\Event\Observer $observer) { $order = $observer->getEvent()->getOrder(); echo $order_id = $order->getID(); } }
Can u pls tell me where i m going wrong.
Hi @amarpreetbd709
Try the below code in Observer:
<?php namespace Cheermes\Widget\Observer\Checkout; class SubmitAllAfter implements \Magento\Framework\Event\ObserverInterface { /** * Execute observer * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute( \Magento\Framework\Event\Observer $observer ) { //Your observer code } }
Event add the following in existing
<event name="checkout_submit_all_after"> <observer instance="Cheermes\Widget\Observer\Checkout\SubmitAllAfter" name="cheermes_widget_observer_checkout_submitallafter_checkout_submit_all_after"/> </event>
I hope it will work!
Hi @Vimal Kumar
How I can use third party api after the order updated successfully.can u pls tell me which observer i have to use in this.