2

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 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 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 at 10:04
1

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:

Magento\Sales\Controller\Adminhtml\Order\Invoice\NewAction

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

Magento\Sales\Model\Service\InvoiceService::prepareInvoice

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 at 5:31
  • Please share your code – Amit Bera Mar 13 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 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 at 7:40
0
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()
{
    $this->searchCriteria->setFilterGroups();
    $invoiceRepo = $this->invoiceRepositoryFactory->create();
    $invoiceRepoCollection = $invoiceRepo->getList($this->searchCriteria);
    $items = $invoiceRepoCollection->getItems();
    print_r($invoiceRepoCollection->getSize());
    foreach ($items as $item) {
        print_r($item->getData());
    }
}

or

Using Repository interface

Magento\Sales\Api\InvoiceRepositoryInterface::getList

Another way is

Magento\Sales\Model\ResourceModel\Order\Invoice\CollectionFactory

check this link How to get Invoice collection magento 2?

0

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)

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.