Get the values from magento2 checkout page but I need to pass into the rest api. How to pass the values.

*$params =   array( 'OrderLineId'=>$orderLineId,
                        'PartnerId'=>  $partnerId,
                        'CustomerId'=> $customerId,
                        'OrderType'=> $orderType,
                        'OrderSource'=>  $orderSource,
                        'CurrId'=> $currId,
                        'UserName'=> $userName);
                        $data = json_encode($params);
$ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
            $response = curl_exec($ch);

         } catch (Exception $e) {
             echo $e->getMessage(); exit;

Can you anyone please help me.

  • When you need to send the data? Before the order is finished, when the checkout page is loaded? Depending on your answer, the best approach would be creating a plugin. There you could put your business logic. Feb 11, 2018 at 11:17
  • Before place an order I fetch the data through the observer. But I ran this page not posting to API. Feb 11, 2018 at 14:29
  • then you can listen to the event checkout_type_onepage_save_order_after it dispaches ['order' => $order, 'quote' => $this->getQuote()] At your observer you could use $order = $observer->getEvent()->getOrder() in order to get the order. Feb 11, 2018 at 14:42
  • values are not passing to rest API from this data Feb 12, 2018 at 8:44
  • You may be doing something wrong then. Feb 12, 2018 at 9:02

1 Answer 1


If you are using a observer, you could listen to event checkout_type_onepage_save_order_after

Take a look into vendor/magento/module-downloadable/etc/events.xml

You will see:

 <event name="sales_model_service_quote_submit_success">
    <observer name="checkout_type_onepage_save_order_after" instance="Magento\Downloadable\Observer\SetHasDownloadableProductsObserver" />

You can implement you logic the same way that Magento\Downloadable\Observer\SetHasDownloadableProductsObserver class does. Check the method execute

 * Set checkout session flag if order has downloadable product(s)
 * @param \Magento\Framework\Event\Observer $observer
 * @return $this
public function execute(\Magento\Framework\Event\Observer $observer)
    if (!$this->_checkoutSession->getHasDownloadableProducts()) {
        $order = $observer->getEvent()->getOrder();
        foreach ($order->getAllItems() as $item) {
            /* @var $item \Magento\Sales\Model\Order\Item */
            if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
                || $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
                || $item->getProductOptionByCode(
            ) {

    return $this;

You just need to adapt the code to your needs. Most of your work is copy and paste.


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.