OroCommerce: How to add new fields to Order LineItems?

244 Views Asked by At

Using Entities Management I've extended Order Line Item adding some new fields that I need, updated schema and etc, new fields appeared in the line items grid on the order view page, but nothing was added to the line items grid in order edit mode.. I did the same to the Shopping List Line Items and new fields appeared both on view/edit and Add Line Item Form, so whats wrong with order and how to add new fields there?

Upd: Looking to the order edit templates I see that there is no fields definition in template and eachline item fields are rendered via form sections. So the only working solution I found is to change oro source code for the Oro\Bundle\OrderBundle\Form\Type\OrderLineItemType adding sections for my fields

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        parent::buildView($view, $form, $options);

        $this->getSectionProvider()->addSections(
            \get_class($this),
            [
                'start_date' => ['data' => ['startDate' => []], 'order' => 5],
                'end_date' =>   ['data' => ['endDate' => []], 'order' => 6],
            ]
        );
    }

and they appeared in order edit. But its unacceptable to modify oro source code so I created my custom class CustomOrderLineItemType extends OrderLineItemType and added migration to replace existing formtype for OrderLineItem.. and its not working, seems that oro still uses internal class, why?

class UpdateOrderLineItemFormType implements Migration
{
    /**
     * {@inheritdoc}
     */
    public function up(Schema $schema, QueryBag $queries)
    {
        $queries->addQuery(
            new UpdateEntityConfigEntityValueQuery(
                OrderLineItem::class,
                'form',
                'form_type',
                CustomOrderLineItemType::class
            )
        );
    }
}
1

There are 1 best solutions below

2
On

You can extend the table in a form by overriding the template, where it's rendered. See the documentation on how to find the template using twig inspector and how to override it in OroCommerce:

https://doc.oroinc.com/frontend/back-office/templates/

To extend the existing form with the new field you can write a form type extension: https://symfony.com/doc/current/form/create_form_type_extension.html