If I want to print my order using some PDF extension which uses the table from transactions emails, some invoices with deleted products are causing an error. As a result the table will be blank. However some orders with deleted products print just fine. I believe if it was a configurable product, the error occurs. But I might be wrong with that. If I disable the PDF extension and WeltPixel EnhancedEmail it prints just fine.
There is probably an error in my code, do you have an idea how I could fix it?
The error:
main.CRITICAL: The product that was requested doesn't exist. Verify the product and try again. {"exception":"[object] (Magento\Framework\Exception\NoSuchEntityException(code: 0): The product that was requested doesn't exist. Verify the product and try again. at /xxx/vendor/magento/module-catalog/Model/ProductRepository.php:290)"} []
#0 /.../generated/code/Magento/Catalog/Model/ProductRepository/Interceptor.php(23): Magento\Catalog\Model\ProductRepository->get('2210107', false, NULL, false)
#1 /.../app/code/WeltPixel/EnhancedEmail/Block/Order/Email/Items/Order/DefaultOrder.php(73): Magento\Catalog\Model\ProductRepository\Interceptor->get('2210107')
#2 /.../app/code/WeltPixel/EnhancedEmail/Block/Order/Email/Items/Order/DefaultOrder.php(105): WeltPixel\EnhancedEmail\Block\Order\Email\Items\Order\DefaultOrder->getProduct()
/**
* @return \Magento\Catalog\Api\Data\ProductInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getProduct()
{
if ($this->getItem()->getProductOptionByCode('simple_sku')) {
$product = $this->_productRepository->get($this->getItem()->getProductOptionByCode('simple_sku'));
if($this->_productHasImage($product)) {
return $product;
} else {
if ($this->getItem()->getProduct()) {
$configProduct = $this->_productRepository->get($this->getItem()->getProduct()->getSku());
} else {
$configProduct = null;
}
return $configProduct;
}
} elseif($this->getItem()->getProductType() == 'grouped') {
$groupedProduct = $this->_productRepository->get($this->getItem()->getSku());
return $groupedProduct;
} else {
if ($this->getItem()->getProduct()) {
$configProduct = $this->_productRepository->get($this->getItem()->getProduct()->getSku());
} else {
$configProduct = null;
}
return $configProduct;
}
}
/**
* @return \Magento\Catalog\Model\Product
*/
public function getProductForThumbnail()
{
return $this->getProduct();
}