0

I am doing a custom order placement based on the API data I receive, I have to introduce the new column on the sales_order table whet I have to add them before order save using addData or setNewfield, I am not sure which one to use and how to achieve them

$order = $this->quoteManagement->submit($quot)

$Newfield = ['Newfield' =>'NewfieldValue'];
$order->addData($Newfield);
Or
$order->setNewfield($this->NewfieldDate);

$order->save();

I found this one but not sure why we have to create on quote table. Magento 2 Add extra data to an order

Thanks in advance...

1 Answer 1

0

It depends on your logic, you can create the attribute on the order or on the quote it won't affect anything.

Then for your question :

setData('data_code',$dataValue);

or

setDataCode($dataValue);

These two are equivalent. The second method is a magical method that will call the first one.

The datavalue depends on where you have stores your value.

The only things you have to do is to add on the order if you create the attribute on the order and add on the quote if you create on the quote.

2
  • So I can create a custom module with InstallSchema $installer->getConnection()->addColumn( $installer->getTable('sales_order'), 'data_code', [ 'type' => 'text', 'nullable' => true, 'comment' => 'data_code', ] ); and go directly for setDataCode($dataValue); before order save
    – fernandus
    Feb 18, 2022 at 11:00
  • yes you can add a column to the order table. Save it in the controller later.
    – Claims
    Feb 18, 2022 at 11:01

Your Answer

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

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