2

Actually, I created a multi-vendor site. I did most of the things but now am stuck in invoice creation.
I filter the invoice items in the New Invoice page shown in the screenshot enter image description here

In this order, there are 4 Items but I already filter each vendor can see own items.
In this screenshort, you can see 2 items because the current login vendor has 2 items in this order.

My Problem is when I click on "submit invoice" button in this page it creates 4 records mean insert 4 items in sales_invoice_item table. I want to insert just those records that shown in New Invoice Page which I filtered . Others invoice item will be excluded.

How can I make restriction? please guide me. Thanks

4
  • are you looking for to create multiple invoices for the same order for each vendor with their items? Commented Mar 19, 2019 at 7:53
  • first i want to insert just filtered items in sales_invoice_item then i will discuss after .
    – HaFiz Umer
    Commented Mar 19, 2019 at 8:06
  • In my opinion it still would be better not to make changes that way but to use quantities as proposed in my answer to a former question magento.stackexchange.com/a/265960/76597 In that way you will not have any impact on order totals and everything would work as you need. If you dont't want to show some items in the form you should rather think about changing the form (i.e. hide rows with qty = 0) than changing the totals calculation.
    – HelgeB
    Commented Mar 19, 2019 at 8:07
  • Dear HelgeB ! i will try your this answer beforePrepareInvoice for filtering invoice item. I will give you feed back soon. Thank you
    – HaFiz Umer
    Commented Mar 19, 2019 at 8:20

1 Answer 1

0

You have to override the controller which is generating the invoice for the order. Following file is doing this

Magento\Sales\Controller\Adminhtml\Order\Invoice\Save.php

You have to modify the invoiceItems array according to the vendor items

$invoiceItems = isset($invoiceData['items']) ? $invoiceData['items'] : [];

Following line is processing the invoice

$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);

How to override controller

https://www.dckap.com/blog/how-to-override-a-controller-in-magento-2/

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.