Which class::method() is responsible for Invoice Items Collection in the Invoice to Items Selection in the New Invoice page?
I just want to make some custom filter in this collection.
Can anyone guide me please.

  • I guess that you want to the function or class which provide list of item which able for invoice
    – Amit Bera
    Mar 12 '19 at 7:29
  • Yes ! just want to known which function return invoice collection that set at New Invoice Page at Invoice of Items section
    – HaFiz Umer
    Mar 12 '19 at 10:01
  • i make custom attribute in sales_order_item table that name is "current_admin_id" and save ids. Now just display those item in invoice list that is belong to current login admin. I make the filter on those function. But exactly i don't which function return invoice collection.
    – HaFiz Umer
    Mar 12 '19 at 10:04
public function __construct(
    \Magento\Sales\Model\Order\InvoiceRepositoryFactory $invoiceRepositoryFactory,
    \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria        
) {

     $this->invoiceRepositoryFactory = $invoiceRepositoryFactory;
    $this->searchCriteria = $searchCriteria;

 * @return $this
public function execute()
    $invoiceRepo = $this->invoiceRepositoryFactory->create();
    $invoiceRepoCollection = $invoiceRepo->getList($this->searchCriteria);
    $items = $invoiceRepoCollection->getItems();
    foreach ($items as $item) {


Using Repository interface


Another way is


check this link How to get Invoice collection magento 2?


You want to get class and method which is responsible for providing available items during new invoice creation at New Invoice page then take a look at Below class:


and this class below code

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

is responsible for available items for new invoice creation

So, if want to modify on this item collection then you have to work on


that function you can get order item see foreach ($order->getAllItems() as $orderItem) {

  • foreach ($order->getAllItems() as $orderItem) { } i want to try nested foreach under this foreach bracket but code is not enter this loop. then i try to print_r(orderItem) it broken the web page to much data come
    – HaFiz Umer
    Mar 13 '19 at 5:31
  • Please share your code
    – Amit Bera
    Mar 13 '19 at 7:30
  • public function prepareInvoice(Order $order, array $qtys = []) { $invoice = $this->orderConverter->toInvoice($order); $totalQty = 0; $qtys = $this->prepareItemsQty($order, $qtys); foreach ($order->getAllItems() as $orderItem) { // print_r($orderItem); die('die'); foreach ($orderItem as $items){ print_r($items); } //magento core code her } code is not enter in my foreach loop
    – HaFiz Umer
    Mar 13 '19 at 7:36
  • i save custome attribute ("seller_id") in sales_order_item table and save seller_ids there. Now i want to apply filter on just display those items in Invoice Item section in New invoice page. I already apply filter in order view page. just those items display in which seller_id match. Same i want this filter in invoice page
    – HaFiz Umer
    Mar 13 '19 at 7:40

Module/Sale/Model/Order/Invoice.php and method is getAllItems() is responsible that collection of invoice items in New Invoice page. I create afterGetAllItems() plugin for making custom collection (custom invoice items)

After that you can modify Subtotal and Grand Total

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.