Magento2: Cannot add bundled products to cart if bundle has a special price

Created on 1 Apr 2019  路  17Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.2.8
  2. PHP 7.1.27 (In our case - may or may not be a factor - we are running in php-fpm)
  3. MariaDB 10.3.13-1.el7.centos (In our case - may or may not be a factor)
  4. Bundle product with a special price attached

Steps to reproduce

  1. Create 2 simple products
  2. Create a bundle with the simple products, and add a Special Price from the advanced pricing page
  3. Go to the front end, and add to cart

Expected result

  1. Adds to cart successfully

Actual result (*)

  1. PHP eats up to max_memory limit, and then dies, generating a 500 to the user
  2. Navigate to home page, and then directly to the cart - fails with the same as 1, above.
  3. note the minicart does not load.
  4. Remove the special price from the back end
  5. Cart now loads successfully

This issue did NOT manifest itself in 2.2.7.

Bundle dmcdindia1 imagine2019 Format is valid

Most helpful comment

For our projects we fixed this bug as followed:

Make an override for vendor/magento/module-catalog/Model/Product/Attribute/Backend/Tierprice.php line 171. Change it from:

if ($specialPrice && ($object->getPrice() > $object->getFinalPrice())) {
to
if ($specialPrice && ($object->getPrice() > $specialPrice)) {

Tested using bundles containing customer group prices and special price and correct price is used.

If you want to be even more specific you could also change it to only be different for bundle products. To do so use :

$isBundleProduct = $object->getTypeId() === \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE; if ( ( ! $isBundleProduct && $specialPrice && ($object->getPrice() > $object->getFinalPrice()) ) || ( $isBundleProduct && $specialPrice && ($object->getPrice() > $specialPrice) ) ) {

Not sure if this is the intended solution but this does work for us.

All 17 comments

Hi @justinharris1986. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

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

@justinharris1986 do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

@magento-engcom-team give me 2.2-develop instance

Hi @justinharris1986. Thank you for your request. I'm working on Magento 2.2-develop instance for you

Hi @justinharris1986, here is your Magento instance.
Admin access: https://i-22095-2-2-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@magento-engcom-team - Yes I was able to reproduce this in 2.2. Not sure if it matters or not, but i disabled "Dynamic Price" and manually set a price in the bundle.
image

2nd - with our theme, we get a 500, however, with the default Luma, it just sits there on "adding". I am presuming it will eventually time out. This was the add request after letting it sit for 3 minutes after clicking add to cart:
image

More screenshots to hopefully help:
Simple product 1 configs (nothing touched under advanced pricing here):
image

Simple product 2 configs (nothing touched under advanced pricing here):
image

Bundle config:
image

image

and the advanced config for the bundle, this is what breaks:
image

if you remove the 5% from there, and save the product, you can then add the product to the cart

Hi @Jitheesh. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [x] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [x] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. 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_!

  • [ ] 5. 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

We're experiencing the same issue since upgrading a site from 2.2.7 to 2.2.8. We have also found that removing the Special Price (% value) from the bundled product and saving allows us to successfully navigate to the cart/checkout page. When this field has a value, the cart/checkout process is broken entirely.

I have done some digging based on the files @Jitheesh provided. What we can see is that the following behaviour:

_vendor/magento/module-bundle/Model/Product/Price.php_

We can see that its getting the Bundle options and getting the selection final total price which leads to calling the _applyTierPrice($product, $qty, $finalPrice) function in the same file noted above.

Locally, where I can recreate the issue I set a breakpoint on the "$tierPrice = $product->getTierPrice($qty);" line within this function and noted the results.

We can see that when the cart loads, it calls this _applyTierPrice() function which then calls the "getTierPrice()" function, in this instance its located in:

_vendor/magento/module-catalog/Model/Product.php_

This then returns the getTierPrice function based on whats returned from getPriceModel(). This then runs the getTierPrice() function in:

_vendor/magento/module-bundle/Model/Product/Price.php_

Following the trace along, it triggers the "$attribute->getBackend()->afterLoad($product);" call where $prices are null. The afterLoad() function in:

_vendor/magento/module-catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php_

Does some further processing to return the final price which ends up calling the __applyTierPrice() function in

_vendor/magento/module-bundle/Model/Product/Price.php_

Which is where the process started. As this is where the process started and it is calling the exact same "__applyTierPrice()" function, it is going through the exact same files calling the exact same functions and inevitably ending up in an infinite loop.

See screenshot below for more clarity on the above.

download

Same issue on Magento 2.2.8 CE, MariaDB, Nginx
After trying to add a bundle product to the cart - site will crash after a few minutes on "waiting ...." and the issue will remain for any other (even simple) products. Restarting server and clearing browser cache on the client does help until the next try with bundle product .

Removing Special price does not help in our case.

Any tip on how to patch it will be appreciated.

For our projects we fixed this bug as followed:

Make an override for vendor/magento/module-catalog/Model/Product/Attribute/Backend/Tierprice.php line 171. Change it from:

if ($specialPrice && ($object->getPrice() > $object->getFinalPrice())) {
to
if ($specialPrice && ($object->getPrice() > $specialPrice)) {

Tested using bundles containing customer group prices and special price and correct price is used.

If you want to be even more specific you could also change it to only be different for bundle products. To do so use :

$isBundleProduct = $object->getTypeId() === \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE; if ( ( ! $isBundleProduct && $specialPrice && ($object->getPrice() > $object->getFinalPrice()) ) || ( $isBundleProduct && $specialPrice && ($object->getPrice() > $specialPrice) ) ) {

Not sure if this is the intended solution but this does work for us.

I am working on this at #dmcdindia1

Hi @mallikaverma. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. 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_!

  • [ ] 5. 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


@magento-engcom-team give me 2.3-develop instance

imagine2019

@magento-engcom-team Is there a patch for this for 2.2.9? We are seeing this issue as well on Magento Cloud.

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento 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_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hello @justinharris1986

Thank you for contribution and collaboration!

We are not able to reproduce this issue on the lates 2.3-develop branch by provided steps.

We are closing this issue due to branch 2.2-develop was closed and

Magento no longer accepts pull requests and issues to the v2.2 release lines to focus all development efforts on v2.3.

See Accepted pull requests and ported code for more details

If you still faced this issue on 2.3 please create a new Issue with all required details according to Issue reporting guidelines

Thanks for your report!

Was this page helpful?
0 / 5 - 0 ratings