2

i need to add to fields to the order entity, so that i can store custom datum in two fields, is it possible to add attribute to the order entity, because i can't get eav tables for the order entity,

if order entity is not EAV , then how to add custom fields to order,

1 Answer 1

3

The sales tables are flat tables. You could add new fields via installer script to the sales_flat_order tables. Like:

$installer = $this;
$installer->startSetup();

$installer->getConnection()->addColumn($installer->getTable('sales_flat_order'), 'new_attribute', 'int');
$installer->getConnection()->addColumn($installer->getTable('sales_flat_order_grid'), 'new_attribute', 'int');

$installer->endSetup();
2
  • ,how to store the values to the fields , i'm creating order programatically , i'm creating order using quote and service objects Commented Jan 13, 2017 at 14:34
  • I'm not sure how you create these orders. Via API? Not sure if this would work for you but one option would be to create an observer which is listening to an event like 'sales_order_place_after' and add the logic there. Like public function salesOrderPlaceAfter($observer) { $order = $observer->getEvent()->getOrder(); ... $order->setData('new_field', $valueOfTheNewField); $order->save(); }
    – Stefan
    Commented Jan 13, 2017 at 15:00

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.