I'm implementing a plugin for Magento\Quote\Model\Quote\Item\ToOrderItem
public function aroundConvert(\Magento\Quote\Model\Quote\Item\ToOrderItem $subject,
\Closure $proceed,
\Magento\Quote\Model\Quote\Item\AbstractItem $item,
$additional = []) {
$orderItem = $proceed($item, $additional);
$product = $this->productFactory->create();
$product->load($item->getProductId());
$unitPv = 0;
if ($product->getCustomAttribute('pv') != null) {
$unitPv = $product->getCustomAttribute('pv')->getValue();
}
$pv = $unitPv;
$qty = $orderItem->getQty();
// ???
$orderItem->setData('pv', $pv);
$orderItem->setData('total_pv', $qty * $pv);
return $orderItem;
}
This method to supposed to copy over a custom attribute (PV) from my products over to the sales order item field (PV and total PV) which I added directly to the sales_order_item table
.
My code above is able to retrieve the PV from the products but for some reason is unable to assign the values to the ordered item. Is my syntax to assign the PV and total_pv
to order_sales_item
correct?