3

I have added one custom attribute to order. but i am not able to save it from my custom file programatically.

use \Magento\Sales\Model\Order;
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $_objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId(000000004);
$dat = $order->getData();
$order->setData('is_send_review',1);
$order->save();

I am able to print array of order by $dat, but when i am going to save it's gives internal server error.

1
  • It is your new attribute ? and did you flush the cache ?
    – Keyur Shah
    Commented Sep 22, 2017 at 13:57

3 Answers 3

2

First flush the cache from var/cache and using php bin/magento cache:flush Remove use \Magento\Sales\Model\Order;

then try this code:

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $_objectManager ->create('Magento\Sales\Model\Order');
$order->loadByIncrementId('000000004');
if($order->getId()){
$order->setData('is_send_review',1);
$order->save();
}
1

Try $order->setIsSendReview(1);

instead of $order->setData('is_send_review',1);

Hope it works :)

3
  • I have also tried it but not working. BTW i am doing this from 1 custom file in magento root.
    – Magecode
    Commented Sep 22, 2017 at 13:43
  • Did you check that order attribute is shown in $dat object ? Commented Sep 22, 2017 at 13:44
  • Yes i have checked that it's giving all information for order.
    – Magecode
    Commented Sep 25, 2017 at 6:13
0

Magento is considering the EAV model for the sales entities deprecated quite for a long time since now (starting with some old versions of Magento 1 as well) but they don't force you not to use it. Thereby, in the eav_entity_type table you have a code for order as well.

For the sales entities, Magento default is using the flat tables. There are no EAV attributes for orders/invoices/cm/shipments.

The sales tables are flat tables so you may add your custom field as a separate column in sales_order via an InstallSchema/UpgradeSchema script.

Hope it helps,

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.