Open SamJUK opened 1 month ago
We are running the following composer patch in production now, and thats allowing Credit Memos to be processed successfully now.
--- Helper/OpenInvoice.php
+++ Helper/OpenInvoice.php
@@ -127,7 +127,7 @@
$product = $item->getProduct();
$imageUrl = "";
- if ($image = $product->getSmallImage()) {
+ if ($product && $image = $product->getSmallImage()) {
$imageUrl = $this->imageHelper->init($product, 'product_page_image_small')
->setImageFile($image)
->getUrl();
@@ -185,16 +185,18 @@
$formattedTaxPercentage = $this->adyenHelper->formatAmount($item->getTaxPercent(), $currency);
$product = $item->getProduct();
+ $productId = $product ? $product->getId() : $item->getProductId();
+ $productUrl = $product ? $product->getUrlModel()->getUrl($product) : '';
return [
- 'id' => $product->getId(),
+ 'id' => $productId,
'amountExcludingTax' => $formattedPriceExcludingTax,
'amountIncludingTax' => $formattedPriceIncludingTax,
'taxAmount' => $formattedTaxAmount,
'description' => $item->getName(),
'quantity' => (int) ($qty ?? $item->getQty()),
'taxPercentage' => $formattedTaxPercentage,
- 'productUrl' => $product->getUrlModel()->getUrl($product),
+ 'productUrl' => $productUrl,
'imageUrl' => $this->getImageUrl($item)
];
}
Hi @SamJUK,
Thank you for reporting this issue and sharing the patch with us. We have opened an internal investigation to find alternative ways of finding the ID to be used to populate the line items.
Checking your patch, with regards to the error being thrown in this line -> 'id' => $product->getId(),
, wouldn't it be necessary to change the way this ID is being fetched?
Kind regards, Rok
Hi @RokPopov ,
Yes your correct, I uploaded an incomplete version of the patch. I've updated it now to the full version, essentially just replacing both id
and productUrl
in the return array with the variables defined above.
Thanks Sam
Hi @SamJUK,
Thank you for adjusting the patch, much appreciated. Would you be willing to create a PR with the changes in the patch?
Kind regards, Rok
@RokPopov Sure thing, opened a PR with ID #2645
Describe the bug Unable to create a credit memo for orders containing deleted products. Getting the following Error message
An error has happened during application run. See exception log for details.
With the following log messageTo Reproduce Steps to reproduce the behavior:
Expected behavior Credit memo to create successfully.
Magento version 2.4.5-p7
Plugin version 9.5.2
Additional Information It should be expected that calling
getProduct
on a order item could return null, in the case the original product no longer exists in the catalog. Either should be looking to use the data baked into the line item, or have logic to handle cases where the original item no longer exists.