i am trying to overwrite invoice tax model, and I want to get the product id. for the invoice item. But it returns the parent product id if purchased product is a configurable product.

file \Magento\Sales\Model\Order\Invoice\Total\Tax.php


foreach ($invoice->getAllItems() as $item) {

             $orderItem = $item->getOrderItem();
            die('from invoice model...');

It returns parent product id but I want the purchased product id, how can I do it.

Please help.

  • please try $invoice->getAllVisibleItems() – Nagaraju K Jul 24 '17 at 13:37
  • @NAGARAJUKASA It result in error. – Nitin Pawar Jul 24 '17 at 13:41

You can based on this plugin :


 * Get product id
 * @param \Magento\Sales\Model\Order\Admin\Item $subject
 * @param callable $proceed
 * @param \Magento\Sales\Model\Order\Item $item
 * @return int
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
public function aroundGetProductId(
    \Magento\Sales\Model\Order\Admin\Item $subject,
    \Closure $proceed,
    \Magento\Sales\Model\Order\Item $item
) {
    if ($item->getProductType() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
        $productOptions = $item->getProductOptions();
        $product = $this->productFactory->create();
        return $product->getIdBySku($productOptions['simple_sku']);
    return $proceed($item);
| improve this answer | |

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.