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

Incorrect method return value in \Magento\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes() #13319

Closed
korostii opened this issue Jan 22, 2018 · 3 comments
Assignees
Labels
Event: mm19in Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@korostii
Copy link
Contributor

Please see the method getTotalNumOfBoxes() in \Magento\Shipping\Model\Carrier\AbstractCarrier: https://github.com/magento/magento2/blob/2.2.2/app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php#L512-L531

Incoming $weight parameter is not checked to be integer. Moreover, even if it is, you can still get a float result when $weight > $maxPackageWeight since these are both arbitrary numbers.

This method is a member of AbstractCarrier class commonly used for 3-rd party implementations of the Shipmen Carrier SPI and might be used by 3rd-party developers in their modules.
In order to apply proper validation and\or rounding around the method's return results, it would be helpful to see the actual return value in PHPDocs which are commonly used by IDEs when providing hints, for example here: http://take.ms/9dnaD

Additionally, the method name is severely misleading: it implies the method is a getter, however it can modify object's internal state. Moreover, the value returned is in fact what seems to be an average weight of a box, not "Total number of boxes" as one might assume.

Backward Compatibility: Please note that Magento's USPS implementation expects float return value, implying internal knowledge of the method: https://github.com/magento/magento2/blob/2.2.2/app/code/Magento/Usps/Model/Carrier.php#L341
If any rounding is to be added, it should probably be done via a new extra method, deprecating the old one (if at all)

Preconditions

  1. Magento CE 2.1.10, Magento CE 2.2.2
  2. PHP 7.0.18

Steps to reproduce

  1. Open file app/code/Magento/Shipping/Model/Carrier/AbstractCarrier.php
  2. Scroll down to getTotalNumOfBoxes method

Expected result

  1. Observe correct return type "float" declared in PHPDoc block
    OR proper rounding applied to the $weight variable.

Actual result

  1. Observe incorrect return type "int" declared in PHPDoc block
    AND no rounding applied to $weight variable
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jan 22, 2018
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Feb 8, 2018
@magento-engcom-team
Copy link
Contributor

@korostii, thank you for your report.
We've acknowledged the issue and added to our backlog.

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Feb 8, 2018
@cedmudit cedmudit self-assigned this Feb 3, 2019
@magento-engcom-team
Copy link
Contributor

Hi @cedmudit. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@magento-engcom-team
Copy link
Contributor

Hi @korostii. Thank you for your report.
The issue has been fixed in #20898 by @cedmudit in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.2 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Mar 30, 2019
magento-engcom-team added a commit that referenced this issue Mar 30, 2019
…\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes() #20898

 - Merge Pull Request #20898 from cedmudit/magento2:2.3-developpr13319
 - Merged commits:
   1. 56504e1
magento-engcom-team pushed a commit that referenced this issue Mar 30, 2019
…\Shipping\Model\Carrier\AbstractCarrier::getTotalNumOfBoxes() #20898
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Event: mm19in Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

3 participants