I have create custom attribute("current_seller_id") in sales_invoice_item and now want to save some value in this column how can i do this. Actually i already save the value in sale_order_item table with same name attribute("current_seller_id"). i was use around plugin for that. code is

namespace MyVendor\MyModuleName\Plugin;
class QuoteToOrder
    public function aroundConvert(
        \Magento\Quote\Model\Quote\Item\ToOrderItem $subject,
        \Closure $proceed,
        \Magento\Quote\Model\Quote\Item\AbstractItem $item,
        $additional = []
    ) {
        /** @var $orderItem \Magento\Sales\Model\Order\Item */
        $orderItem = $proceed($item, $additional);
        return $orderItem;

these lines of code save value in each record of sale_order_item table. you see this $item->getCurrentSellerId() i make attribute "current_seller_id" in eav_attribute table and save value of current user with each product saving. I need the same event or plugin that fire before saving invoce items in sales_invoice_item table because i need to send some custom value in table column

1 Answer 1


I would suggest to create a plugin after Magento\Sales\Model\Order\Invoice\Item::register() and copy there the data from the order item to the newly created corresponding invoice item. This could be the plugin method:

public function afterRegister(\Magento\Sales\Model\Order\Invoice\Item $subject, $result)
    return $result;

However you can try to add the current_seller_id to the fieldset which is used for a newly created invoice item to copy values from an order item. But I heard that this doesn't work in some Magento versions.

For this approach add the following into a fieldset.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <scope id="global">
        <fieldset id="sales_convert_order_item">
            <field name="current_seller_id">
                <aspect name="to_invoice_item" />
  • HelgeB ! after plugin or before ? i want to save value in database.
    – HaFiz Umer
    Commented Mar 18, 2019 at 11:24
  • 1
    after is better, before would probably also work. The saving process is however later. The register method is only called when a new invoice is created and therefore it is the best place for you.
    – HelgeB
    Commented Mar 18, 2019 at 11:28
  • let me check please :)
    – HaFiz Umer
    Commented Mar 18, 2019 at 11:29
  • Dear HelgeB! It work perfect i use afterRegister plugin. Thank You .
    – HaFiz Umer
    Commented Mar 18, 2019 at 11:44
  • you have the usual events around the save process which every model has, in this case sales_order_invoice_save_before and sales_order_invoice_save_after
    – HelgeB
    Commented Mar 18, 2019 at 13:40

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.