Skip to content

Fix for the issue #25675 #25711

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

Closed
wants to merge 6 commits into from
Closed

Conversation

sichensol
Copy link
Contributor

Description (*)

This pull request should fix issue #25675

Fixed Issues (if relevant)

  1. Unable add product to cart in Magento 2.3.3 backend when stock quantity is 1 - "The requested qty is not available" #25675: Unable add product to cart in Magento 2.3.3 backend when stock quantity is 1 - "The requested qty is not available"

Manual testing scenarios (*)

Described here #25675

@m2-assistant
Copy link

m2-assistant bot commented Nov 23, 2019

Hi @molneek. 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide 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 @molneek, thank you for your contribution!
Could you please drop a few words about the root reason of the issue and how the applied solution solves it? Unfortunately, it's not clear without performing an additional investigation.

Please, also note, due to Magento Definition of Done the changes should be covered by tests. Could you please cover your fix by an automated test?

Thank you!

@sidolov sidolov changed the base branch from 2.3-develop to 2.4-develop December 5, 2019 17:12
@sichensol
Copy link
Contributor Author

sichensol commented Dec 6, 2019

Hi @dmytro-ch, thank you for review. The root reason for the issue is that during checking a product inventory this method calls several times before item is saved to a DB and after. But the method uses item id to collect inventory information. And when an item is not saved to a DB but checked inventory for the product, we collect incorrect data, that in next checking will be added to current qty and corrupt the result.
E.g we have 1 qty of a product. We add to the cart this item. Magento checks inventory and stores that for itemId = null qty is 1, then during nex checking when the item is saved to DB Magento checks in the method if there is not a qty info for itemId (e.g 5) add this qty to currently used qty. But as qty stored for itemId = null this will always true and Magento adds unappropriate qty and corrupts data.
After that in the following checks, qty can't be matched with actual qty and Magento displays the error message "The requested qty is not available".

Also, this fix does not require additional automated tests, as all Magento current tests are good with this solution. And this solution fixes the process of corrupting data and does not change the method signature

@dmytro-ch
Copy link
Contributor

@molneek thank you for the details!

@dmytro-ch
Copy link
Contributor

@magento 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-25711.instances.magento-community.engineering/admin
Login: admin Password: 123123q

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.

@molneek, unfortunately, there is no test that covers the aforementioned case.
Please create at least a simple unit test (e.g. \Magento\CatalogInventory\Test\Unit\Model\Quote\Item\QuantityValidator\QuoteItemQtyListTest) which will make sure the quantity calculation logic is performed correctly, according to the scenario you've just described above.
It can be easily accomplished by calling the \Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList::getQty method with different sets of parameters and asserting the result.

Thank you!

@dmytro-ch
Copy link
Contributor

Hello @molneek, I'm closing this PR now due to inactivity.
Feel free to reopen and update if you wish to continue.
Thank you!

@dmytro-ch dmytro-ch closed this Jan 10, 2020
@m2-assistant
Copy link

m2-assistant bot commented Jan 10, 2020

Hi @molneek, 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.

@sichensol sichensol reopened this Feb 1, 2020
@m2-assistant
Copy link

m2-assistant bot commented Feb 1, 2020

Hi @molneek. 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@ghost ghost unassigned dmytro-ch Feb 1, 2020
@sichensol
Copy link
Contributor Author

Hello @dmytro-ch, I've added a unit test as you asked, please verify this merge request one more time

@sichensol
Copy link
Contributor Author

@dmytro-ch I close this PR due to open the new one for the 2.4 version #26650

@sichensol sichensol closed this Feb 2, 2020
@m2-assistant
Copy link

m2-assistant bot commented Feb 2, 2020

Hi @molneek, 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.

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.

4 participants