magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.3k forks source link

module-sales/Model/Order/Creditmemo/Total/Tax.php division by 0 on line 139 and 140 #37686

Closed Naberdz closed 1 year ago

Naberdz commented 1 year ago

Preconditions and environment

Steps to reproduce

Create order and choose delivery method with 0 costs. Complete order and click on creditmemo button. you will get error

Schermafbeelding 2023-06-29 om 08 25 55

Expected result

Creditmemo should be working

Actual result

We get error.

had to replace those lines with the following:

139                 $part = $creditmemo->getShippingAmount() / ($orderShippingAmount != 0 ? $orderShippingAmount :  1);
140                 $basePart = $creditmemo->getBaseShippingAmount() / ($baseOrderShippingAmount !=0 ? $baseOrderShippingAmount : 1);
Schermafbeelding 2023-06-29 om 08 26 44

Additional information

No response

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @Naberdz. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, here is your Magento Instance: https://82ff5428c157a16b7ac2d70bf4c4447a.instances-prod.magento-community.engineering Admin access: https://82ff5428c157a16b7ac2d70bf4c4447a.instances-prod.magento-community.engineering/admin_d1c4 Login: b6cedd99 Password: bc3d1696060c

engcom-Bravo commented 1 year ago

Hi @Naberdz,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Steps to reproduce

We are able to create the credit memo for the order having $0 shipping method.

Screenshot 2023-06-30 at 12 11 25 PM

Kindly recheck the behaviour on Magento 2.4-develop instance and elaborate steps to reproduce if the issue is still reproducible.

Thanks.

engcom-Bravo commented 1 year ago

Hi @Naberdz,

Kindly provide latest update on this comment https://github.com/magento/magento2/issues/37686#issuecomment-1614203759 if you are able to reproduce the issue please elaborate steps to reproduce if the issue is still reproducible.

Thanks.

dudzio12 commented 1 year ago

There is a problem in isShippingIncludeTaxWithTaxAfterDiscount() method, which returns true here: https://github.com/magento/magento2/blob/ca30c47787db932b9431e42226bb918e95c932d9/app/code/Magento/Sales/Model/Order/Creditmemo/Total/Tax.php#L137

Then it runs the $part = $creditmemo->getShippingAmount() / $orderShippingAmount;, where $orderShippingAmount can be 0 at this point.

Actually there is a fix already for this issue in this commit: https://github.com/magento/magento2/commit/d32646fd5f04cc7f5a2bf4d1f73b110a78197d83

Those changes implements checking if $orderShippingAmount > 0 and runs that part of the code only if it's true.

engcom-Bravo commented 1 year ago

@dudzio12 Thanks for your contribution & collaboration over here.

Hi @Naberdz,

This issue has been fixed under this commit d32646f Hence we are closing this issue.

Thanks.