1

I am using Custom Shipping API where I am getting response from API. Here I want to save this response to my order and quote table, I used event checkout_onepage_controller_success_action Here's code of my event under etc/frontend

<?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="checkout_onepage_controller_success_action">
        <observer name="bigpost_order_controller_success_action" instance="Some\Somename\Observer\Processorder" />
    </event>
    </config>

Here's I am using in doing in execute function under Observer/Processorder

          $order_ids = $observer->getEvent()->getOrderIds()[0];
           $order = $this->orderRepository->get($order_ids);           
           $order_id = $order->getIncrementId();   
$job = json_decode($resut, true); //response here 
  foreach ($job as $key => $consignment) {
      $condignment = $consignment['CarrierConsignmentNumber']; //got reponse 'BP459090'
      try {
        $orderDetailData = $condignment;
        if(!empty($orderDetailData)){
        $order_id->setData('carrier_consignment_number', $orderDetailData); //tried to set data
        $order_id->save();
      }
        print("succssfully done");

    } catch (\Exception $e) {
        error_log($e->getMessage());
        print("error in this");
    }
            }

it's not saved my data in db under sale_order table or quote table. while I created column there.

Getting error here : Fatal error: Uncaught Error: Call to a member function setData() on string in

0

You are setting your data and also saving an order id which is a string instead of the order object.

change

$order_id->setData('carrier_consignment_number', $orderDetailData); //tried to set data
$order_id->save();

For

$order->setData('carrier_consignment_number', $orderDetailData); //tried to set data
$order->save();
  • Still have same error : Fatal error: Uncaught Error: Call to a member function setData() on string in – Rohit Kaushik Dec 6 '19 at 5:39
  • Check what is the content of order_ids and also make sure an actual order has been returned by $this->orderRepository->get($order_ids); – Carlo Ricci Dec 6 '19 at 18:51
  • SetData always work with existing tables not with custom table for this we have to make a plugin or call model – Rohit Kaushik Dec 10 '19 at 10:23

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.