0

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?

3
  • did you created 'pv, total_pv' columns on sales_order_item table? . Please verify the sales_order_item table. Commented Jul 9, 2019 at 8:02
  • The fields 'pv' and 'total_pv' are created and exists in the sales_order_item table. Commented Jul 9, 2019 at 8:05
  • $orderItem->getData('pv); $orderItem->getData('total_pv'); below the setData, try to print this values in logger and check whether the values are getting set or not in orderItem Object. Commented Jul 9, 2019 at 8:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.