It appears fieldsets are no longer an option for moving custom data fields around. Not clear if this is intentional, or a side-effect of other changes.
I just ran into the same problem with payments. I traced that back to \Magento\Quote\Model\Quote\Payment\ToOrderPayment::convert()
:
public function convert(Payment $object, $data = [])
{
$paymentData = $this->objectCopyService->getDataFromFieldset(
'quote_convert_payment',
'to_order_payment',
$object
);
$orderPayment = $this->orderPaymentFactory->create();
$this->dataObjectHelper->populateWithArray(
$orderPayment,
array_merge($paymentData, $data),
'\Magento\Sales\Api\Data\OrderPaymentInterface'
);
$orderPayment->setAdditionalInformation(
array_merge(
$object->getAdditionalInformation(),
[Substitution::INFO_KEY_TITLE => $object->getMethodInstance()->getTitle()]
)
);
// set directly on the model
$orderPayment->setCcNumber($object->getCcNumber());
$orderPayment->setCcCid($object->getCcCid());
return $orderPayment;
}
It starts by processing the fieldset to copy data from $object
into the $paymentData
array, but then feeds that array into \Magento\Framework\Api\DataObjectHelper::populateWithArray()
to actually set the values on the target object (here, $orderPayment
).
Rather than directly adding the data array to the object as in Magento 1, DataObjectHelper
looks for 'set__' or 'setIs__' methods corresponding to each key, and then calls those methods with the value. If such method does not exist, the data key is skipped entirely.
Quote addresses and items are processed the same way, in \Magento\Quote\Model\Quote\Address\ToOrderAddress
and \Magento\Quote\Model\Quote\Item\ToOrderItem
respectively.
What does that mean?
- Adding the key to a fieldset is not sufficient, unless a set method already exists on the object corresponding to that key.
- It appears that copying custom fields from quote to order will require either overriding the target class to add the necessary setter method(s) (via dependency injection), or using observers like
sales_model_service_quote_submit_before
to copy the data manually.
Also note that the quote module has its own fieldsets defined, including quote_convert_address
and quote_convert_item
. It does not appear that the sales_convert_quote* fieldsets are in use anymore.
Sure, just add "fieldClass" property to the column configuration:
<column name="column_name">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="fieldClass" xsi:type="string">your-css-rule(s)</item>
</item>
</argument>
</column>
Best Answer
Assuming you have created 'custom_item_column' in sales_order_item table you can add a custom column to Items Grid in sales order view by following:
1.Create sales_order_view.xml file in
app/code/[Vendor]/[Modulename]/view/adminhtml/layout
folder and add the below code.2.Create "custom_item_column.phtml" file in [Namespace]/[Modulename]/view/adminhtml/templates folder and add the below code.
source : https://github.com/magento/magento2/pull/11076