Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECP-9246] Unable to create Credit Memos for orders containing deleted products. #2636

Closed
SamJUK opened this issue May 29, 2024 · 5 comments · Fixed by #2645
Closed

[ECP-9246] Unable to create Credit Memos for orders containing deleted products. #2636

SamJUK opened this issue May 29, 2024 · 5 comments · Fixed by #2645
Assignees
Labels
Bug report Indicates that issue has been marked as a possible bug

Comments

@SamJUK
Copy link
Contributor

SamJUK commented May 29, 2024

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 message

[2024-05-29T12:01:30.491360+00:00] main.CRITICAL: Error: Call to a member function getId() on null in /vendor/adyen/module-payment/Helper/OpenInvoice.php:190

To Reproduce
Steps to reproduce the behavior:

  1. Create a product
  2. Place an order using said product
  3. Invoice & Ship the order
  4. Delete the product
  5. Attempt to create a credit memo for the order

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.

@SamJUK SamJUK added the Bug report Indicates that issue has been marked as a possible bug label May 29, 2024
@SamJUK
Copy link
Contributor Author

SamJUK commented May 29, 2024

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)
         ];
     }

@RokPopov RokPopov changed the title Unable to create Credit Memos for orders containing deleted products. [ECP-9246] Unable to create Credit Memos for orders containing deleted products. May 30, 2024
@RokPopov
Copy link
Contributor

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

@SamJUK
Copy link
Contributor Author

SamJUK commented May 30, 2024

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

@RokPopov RokPopov self-assigned this May 30, 2024
@RokPopov
Copy link
Contributor

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

@SamJUK
Copy link
Contributor Author

SamJUK commented May 31, 2024

@RokPopov Sure thing, opened a PR with ID #2645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug report Indicates that issue has been marked as a possible bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants