0

Is their any way we can continue execution of program after below exception

throw new \Magento\Framework\Exception\LocalizedException(
                                __('If the invoice was created offline, try creating an offline credit memo.'),
                                $e
                            );

Actually i have created an shipment refund script that refunds shipment for orders. i pass order id in csv & it created online credit memo. But for some order (that i don't know). get stuck in below exception, That is why the next order id does not gets executed. Is their any way i can skip this exception or check something in script to prevent call going into this code ?

Magento2/vendor/magento/module-sales/Model/Order/Payment.php

throw new \Magento\Framework\Exception\LocalizedException(
                                __('If the invoice was created offline, try creating an offline credit memo.'),
                                $e
                            );
3
  • any thoughts on this ? –
    – devhs
    Commented May 31, 2021 at 11:51
  • Try to create a credit memo in the admin. There's a checkbox to make it an offline credit memo. This checkbox is posted to the server. Post this checkbox value in your script.
    – David Tay
    Commented May 31, 2021 at 13:59
  • Thankyou for the advice, checking that checkbox will result into "offline refund" & i need to process refund online.
    – devhs
    Commented Jun 1, 2021 at 4:55

1 Answer 1

0

I would like to see the script in order to have a better opinion.But I imagine that you are looping the CSV Items and calling a method that Payment class throws the exception.

Lets suppose that you have that loop:

foreach ($csvOrders as $csvOrder){
....
     try {
            // Call vendor/magento/module-sales/Model/Order/Payment.php method

     } catch (Magento\Framework\Exception\LocalizedException $e ) {
            // Log the error $e->getMessage()
     }
}

It will process all the orders and save the errors on log file, then you can track the issue of others.

I hope it helps you.

4
  • Thanks for the answer, but that payment.php executes this code - throw new \Magento\Framework\Exception\LocalizedException( __('If the invoice was created offline, try creating an offline credit memo.'), $e ); That just stop execution further.
    – devhs
    Commented Jun 5, 2021 at 5:41
  • Can you share the script? it can give us some clue. Commented Jun 5, 2021 at 12:17
  • Yes - magento.stackexchange.com/questions/339283/…
    – devhs
    Commented Jun 5, 2021 at 12:29
  • I realized that your code is catching the interpreter exception: \Magento\Framework\Exception\NoSuchEntityException. However Magento\Framework\Exception\LocalizedException is a runtime exception, that is a different type and level. Please, try to change the NoSuchEntityException by Exception that catches all the exceptions and it must work. Commented Jun 6, 2021 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.