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

Fix mass product update with group min cart qty #19095

Merged
merged 3 commits into from
Jan 26, 2019

Conversation

pmclain
Copy link
Contributor

@pmclain pmclain commented Nov 7, 2018

Description (*)

Resolves warning when using the product edit mass-action after configuring
global group cart min qty

Fixed Issues (if relevant)

  1. Mass attribute update fails with E_WARNING #17592 Mass attribute update fails with E_WARNING

Manual testing scenarios (*)

  1. Add some values to System > Configuration > Catalog > Inventory > Product Stock Options > Minimum Qty Allowed in Shopping Cart
  2. Clean config cache
  3. Go to the Catalog > Products
  4. Select some products in the list
  5. Select "Update attributes" mass-action

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 @pmclain. 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

@@ -132,7 +132,7 @@
<div class="field">
<input type="text" class="input-text validate-number" id="inventory_min_sale_qty"
name="<?= /* @escapeNotVerified */ $block->getFieldSuffix() ?>[min_sale_qty]"
value="<?= /* @escapeNotVerified */ $block->getDefaultConfigValue('min_sale_qty') * 1 ?>"
value="<?= /* @escapeNotVerified */ (int) $block->getDefaultConfigValue('min_sale_qty') * 1 ?>"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get this. How original implementation produces a non-numeric value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the store config allows you to set this value at the customer group level, something that is not supported at the individual product level. something that is visible when editing the inventory config at the product level.
Product inventory using store config
screenshot 2018-11-07 at 01 28 11

Product inventory after un-checking use default
screenshot 2018-11-07 at 01 28 26

The error occurs because from multiplying json, from the store config, by 1.

Copy link
Contributor

Choose a reason for hiding this comment

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

So after the fix some JSON string is casted to 0?

Copy link
Contributor Author

@pmclain pmclain Nov 7, 2018

Choose a reason for hiding this comment

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

yes, should it be 1 instead? that's the value if no global config is set.

Copy link
Contributor

Choose a reason for hiding this comment

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

@pmclain yes, I think so. And also please preserve old logic instead of casting:
is_numeric(...) ? getConfig() * 1 : <DEFAULT GLOBAL VALUE>

Resolves warning when using the product edit mass-action after configuring
global group cart min qty

Fixes magento#17592
@magento-engcom-team magento-engcom-team added this to the Release: 2.3.1 milestone Nov 30, 2018
@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko, thank you for the review.
ENGCOM-3599 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.

Great @pmclain! I left a couple of comments but there is really no need to change anything.

$default = $this->stockConfiguration->getDefaultConfigValue('min_sale_qty');
if (!is_numeric($default)) {
$default = $this->serializer->unserialize($default);
$default = isset($default[GroupInterface::CUST_GROUP_ALL]) ? $default[GroupInterface::CUST_GROUP_ALL] : 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Get used to ?? ;)

@@ -132,7 +132,7 @@
<div class="field">
<input type="text" class="input-text validate-number" id="inventory_min_sale_qty"
name="<?= /* @escapeNotVerified */ $block->getFieldSuffix() ?>[min_sale_qty]"
value="<?= /* @escapeNotVerified */ $block->getDefaultConfigValue('min_sale_qty') * 1 ?>"
value="<?= /* @escapeNotVerified */ $block->getDefaultMinSaleQty() * 1 ?>"
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use @noEscape here.

@magento-engcom-team
Copy link
Contributor

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

$default = isset($default[GroupInterface::CUST_GROUP_ALL]) ? $default[GroupInterface::CUST_GROUP_ALL] : 1;
}

return (int) $default;
Copy link
Contributor

@valdislav valdislav Jan 3, 2019

Choose a reason for hiding this comment

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

@orlangur @pmclain Please be aware of the option when qty uses decimals, it would be better to use float.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@valdislav Please let me know if any additional changes are requested.

@magento-engcom-team
Copy link
Contributor

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

@ghost
Copy link

ghost commented Jan 26, 2019

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

@magento-engcom-team
Copy link
Contributor

Hi @pmclain. Thank you for your contribution.
We will aim to release these changes as part of 2.3.1.
Please check the release notes for final confirmation.

@sivaschenko
Copy link
Member

Hi @pmclain , unfortunately we had to revert changes introduced in this pull request as adding a public method getDefaultMinSaleQty to an API class where not approved by architects.

Adding public method to API classes may have negative effect for extensions that have plugins applied to original public method calls (that are replaced by new method calls).

I think that backward compatible approach in this case could be modifying the getDefaultConfigValue method

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.

6 participants