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

Set minimum qty 1 after cast to int #21928

Merged
merged 2 commits into from
Apr 8, 2019

Conversation

likemusic
Copy link
Contributor

@likemusic likemusic commented Mar 25, 2019

Description (*)

Set minimum qty 1 for values casted to int from float value.

Fixed Issues (if relevant)

  1. Exception on reorder from admin #21926: Exception on reorder from admin

Manual testing scenarios (*)

  1. See Exception on reorder from admin #21926

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @likemusic. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

Copy link
Contributor

@dmytro-ch dmytro-ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @likemusic,
thank you for your contribution!

Could you please check the minor CR recommendations?

Thank you!

@dmytro-ch
Copy link
Contributor

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

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

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, here is your new Magento instance.
Admin access: https://pr-21928.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@dmytro-ch
Copy link
Contributor

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

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

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, here is your new Magento instance.
Admin access: https://pr-21928.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@dmytro-ch
Copy link
Contributor

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

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

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, here is your new Magento instance.
Admin access: https://pr-21928.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, thank you for the review.
ENGCOM-4585 has been created to process this Pull Request

Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@likemusic please simplify implementation even more and squash changes into a single commit.

@@ -119,13 +119,13 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ
$result->setItemIsQtyDecimal($stockItem->getIsQtyDecimal());
if (!$stockItem->getIsQtyDecimal()) {
$result->setHasQtyOptionUpdate(true);
$qty = (int) $qty;
$qty = (int) $qty ?: 1;
/**
* Adding stock data to quote item
*/
$result->setItemQty($qty);
Copy link
Contributor

@orlangur orlangur Mar 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$result->setItemQty($qty);
$result->setItemQty((int)$qty ?: 1);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orlangur $qty variable used below in file many times. I think it should contain already fixed value, isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@likemusic it is casted to int only here within condition. Please don't forget to squash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orlangur I think all other validation should by with casted value.
Assume $qty = 0.1 and $stockItem->getMinSaleQty() is 1. In $result we have 1.
Look at line 130 if ($stockItem->getMinSaleQty() && $qty < $stockItem->getMinSaleQty()) {

If here $qty == 1 will not add error message to $result. If $qty == 0.1 here, we will add error message to $result.
In latest case finaly we will have result with $qty = 1 but with massage that 'The fewest you may purchase is 1.'. It's not logical. Imho all validation with $qty variable in this method should be done with cased to int value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@likemusic ok, agree, assignment should still be there and $result->setItemQty($qty = (int)$qty ?: 1); would look awkward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made:

git rebase -i 2.3-develop
git push -f

Is it right way to squash commits in pull-request?

$qty = $this->getNumber($qty);
$origQty = (int) $origQty;
$origQty = $this->getNumber($origQty);
$origQty = (int) $origQty ?: 1;
$result->setOrigQty($origQty);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$result->setOrigQty($origQty);
$result->setOrigQty((int)$this->getNumber($origQty) ?: 1);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@likemusic great! This is exactly what was needed.

@magento-engcom-team
Copy link
Contributor

Hi @orlangur, thank you for the review.
ENGCOM-4585 has been created to process this Pull Request

@VasylShvorak
Copy link
Contributor

@magento-engcom-team give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @VasylShvorak. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @VasylShvorak, here is your new Magento instance.
Admin access: https://pr-21928.instances.magento-community.engineering/admin
Login: admin Password: 123123q

@VasylShvorak
Copy link
Contributor

✔️ QA passed

@m2-assistant
Copy link

m2-assistant bot commented Apr 8, 2019

Hi @likemusic, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@meker12
Copy link
Contributor

meker12 commented Jun 3, 2019

Release note"

Catalog

Magento no longer throws a divide by zero exception if a product configuration specifies the Minimum Qty Allowed in Shopping Cart as a decimal value less than one, and sets the Qty Uses Decimals attribute to No .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants