Total Invoice count by order id Magento 2.

You can count the no. of Invoice generated for the specific order by order id in Magento 2.

Using Magento\Sales\Api\InvoiceRepositoryInterface interface you need to use getList() method with SearchCriteriaBuilder class to fetch no. of an invoice for the order.

Using Below code snippet you can get the count of invoice for an order,

$orderId = 1; // order id
$this->getCountInvoicesForOrder($orderId);

Using the above way, You can fetch no. of an invoice for the single order.

Delete Invoice by invoice id Magento 2.

You can delete invoice data by invoice id in Magento 2.

Using Magento\Sales\Api\InvoiceRepositoryInterface interface you need to use get() and delete() function to delete invoice by id.

You must fetch the invoice object by id and then pass the invoice object as a parameter in delete() method to delete the specific invoice.

Using the above way you can delete the invoice using Invoice Repository.

Get Invoice data by invoice id Magento 2.

You can get full details of Invoice related data using invoice id in Magento 2.

Using Magento\Sales\Api\InvoiceRepositoryInterface class you can get details of invoice related data in Magento 2.

Get Invoice related data using below code snippet in Magento 2 by Invoice id, Continue reading “Get Invoice data by invoice id Magento 2.”