Skip to content

A fix for issue #9265 #9266

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

Merged
merged 4 commits into from
Jul 12, 2017
Merged

A fix for issue #9265 #9266

merged 4 commits into from
Jul 12, 2017

Conversation

evgk
Copy link
Member

@evgk evgk commented Apr 15, 2017

Fixes issue #9265

Description

This line: $quantity = $quantity ?: 1;
in ./vendor/magento/module-catalog/Pricing/Price/TierPrice.php, line 75,
uses the ternary shorthand operator to set the quantity to 1 when
the quantity that is passed can be converted to false.
At this point, the quantity comes from the SaleableInterface item - the simple product model itself.
Note that the type signature for the getQty method in SaleableInterface indicates that it should always
return a float:

/**

  • Returns quantity of saleable item
  • @return float
    */
    public function getQty();

However, on the grouped-product page this item comes from this collection:
./vendor/magento/module-catalog/Model/ResourceModel/Product/Link/Product/Collection.php
(a collection of linked products). So the quantity that is set in the product model comes from the
"Default quantity" field which is stored as an attribute of the link(catalog_product_link_attribute_decimal) -
however, since neither Magento nor the underlying Zend libraries have any conversion from the MySQL to PHP types when loading the collections,
and MySQL client/server communication is done via a text-based protocol, this "qty" field ends up being a string in PHP.
Thus, the getQty function will return a string representation of a decimal value("0.0000000") in a clear violation of the SaleableInterface, and it leads to this issue with the tier price above(since the ternary shorthand operator will treat "0.000000" string as true, not setting the quantity to 1 as a result).
Suggested fix does a forceful conversion of the link-attributes with type=decimal to a PHP float-value on the link-product-collection afterLoad event.
It is possible to do the same for the integer type as well, but doing it just for the type=decimal seems least intrusive, and it would solve this interface-mismatch and tier-price issue.

Fixed Issues (if relevant)

  1. Tier price / grouped product issue #9265: Tier price / grouped product issue

Manual testing scenarios

  1. ...
  2. ...

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)

evgk added 4 commits April 16, 2017 03:00
This line: $quantity = $quantity ?: 1;
in ./vendor/magento/module-catalog/Pricing/Price/TierPrice.php, line 75,
uses the ternary shorthand operator to set the quantity to 1 when
the quantity that is passed can be converted to false.
At this point, the quantity comes from the SaleableInterface item - the simple product model itself.
Note that the type signature for the getQty method in SaleableInterface indicates that it should always
return a float:

/**
 * Returns quantity of saleable item
 *
 * @return float
 */
public function getQty();
However, on the grouped-product page this item comes from this collection:
./vendor/magento/module-catalog/Model/ResourceModel/Product/Link/Product/Collection.php
(a collection of linked products). So the quantity that is set in the product model comes from the
"Default quantity" field which is stored as an attribute of the link(catalog_product_link_attribute_decimal) -
however, since neither Magento nor the underlying Zend libraries have any conversion from the MySQL to PHP types when loading the collections,
and MySQL client/server communication is done via a text-based protocol, this "qty" field ends up being a string in PHP.
Thus, the getQty function will return a string representation of a decimal value("0.0000000") in a clear violation of the SaleableInterface, and it leads to this issue with the tier price above(since the ternary shorthand operator will treat "0.000000" string as true, not setting the quantity to 1 as a result).
Suggested fix does a forceful conversion of the link-attributes with type=decimal to a PHP float-value on the link-product-collection afterLoad event.
It is possible to do the same for the integer type as well, but doing it just for the type=decimal seems least intrusive, and it would solve this interface-mismatch and tier-price issue.
codacy fix
@vrann vrann self-assigned this Apr 17, 2017
@vrann vrann added this to the April 2017 milestone Apr 17, 2017
@evgk
Copy link
Member Author

evgk commented May 8, 2017

Hi,
I can see the PR wasn't processed in April. Do you need any additional information?

@okorshenko okorshenko modified the milestones: April 2017, May 2017 May 9, 2017
@okorshenko okorshenko modified the milestones: May 2017, June 2017 Jun 1, 2017
@okorshenko okorshenko assigned okorshenko and unassigned vrann Jun 9, 2017
@ishakhsuvarov
Copy link
Contributor

Hi @evgk
We have tried and could not reproduce the issue in question (#9265) on the latest code from the develop branch, may be it it specific to 2.1.x versions only?

@evgk
Copy link
Member Author

evgk commented Jun 16, 2017

Hi,
I have now tried to reproduce it on the latest codebase(before, I tested on 2.1.6) - and I can reproduce the bug. I'm attaching the screenshots.

root@manage /var/www/magento2/last_dev/magento2 # git log -n 1
commit bd22a2c
Merge: 397f87b 015424a
Author: Oleksii Korshenko okorshenko@magento.com
Date: Thu Jun 15 19:33:40 2017 -0500

Merge pull request #1201 from magento-engcom/develop-prs

Public Pull Requests

magento/magento2#9943
magento/magento2#9941

This is a screenshot of an incorrect product-page without the suggested fix:
price_without_patch

This is a screenshot of a correct product page with the suggested fix applied:
price_with_patch

Those are the settings for the grouped product:
grouped_product_settings

Those are the settings for the test2 product:
test2_product_settings

Tier price for the test2 product:
test2_product_tier_price

Do you have the same settings when testing and do you see the same in frontend?

@evgk
Copy link
Member Author

evgk commented Jun 16, 2017

The "Default Quantity" field in the "Grouped Products" section on the grouped product should be 0

Please note that this is essential to reproduce the bug.

magento-team pushed a commit that referenced this pull request Jul 12, 2017
 - reverted original fix due to broken logic in other parts or the system
 - added local fix for Tier Price
magento-team pushed a commit that referenced this pull request Jul 12, 2017
magento-team pushed a commit that referenced this pull request Oct 3, 2017
 - reverted original fix due to broken logic in other parts or the system
 - added local fix for Tier Price
magento-team pushed a commit that referenced this pull request Oct 3, 2017
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.

5 participants