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.

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

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();
}
| improve this answer | |
0

Try $order->setIsSendReview(1);

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

Hope it works :)

| improve this answer | |
  • I have also tried it but not working. BTW i am doing this from 1 custom file in magento root. – Magecode Sep 22 '17 at 13:43
  • Did you check that order attribute is shown in $dat object ? – Abhishek Panchal Sep 22 '17 at 13:44
  • Yes i have checked that it's giving all information for order. – Magecode Sep 25 '17 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,

| improve this answer | |

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.