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

Fixes: Bundle product with only one product in required bundle option not being added to cart with bundle option. #38601

Closed
wants to merge 11 commits into from

Conversation

bhoopatparmar
Copy link

@bhoopatparmar bhoopatparmar commented Apr 10, 2024

Description (*)

Adding a bundle product to the cart from the product list widget doesn’t let the product be added properly with the bundle option. The bundle product options are not added within the parent product. It shows a warning message in minicart like ‘Please specify product option(s)’. It doesn’t fail in all the cases, it only fails in a certain case where a bundle product has been created with a required bundle option & the bundle option contains only one product with the ‘is_default’ checkbox selected.

Screenshot 1:
image
Here you can see in the screenshot a bundle product has been created with a bundle option containing only one product in it & the option is required and the product is default select.

Screenshot 2:
image
After creating a bundle product, a widget has been created with a type of Catalog Product List & a condition that matches the particular bundle product.

Screenshot 3:
image
As we have created a widget, a bundle product is visible on the home page in the widget.

Screenshot 4:
image
When we click on the add-to-cart button, the product seems to be added to the cart & it doesn’t throw any error. And then if you check in the mini-cart, you will come to see a warning message like “Please specify product option(s).”

The same thing works fine on a list page, but it fails while adding a product to the cart through the widget.

Manual testing scenarios (*)

  1. Create a bundle product that contains one or more bundle options & each bundle option is required and must contain only one product that is default selected. (see screenshot 1)
  2. Create a widget with the type ‘Catalog Product List’ with a condition that includes the newly created bundle product in the widget. (see screenshot 2)
  3. From the front end visit the widget & try to add the bundle product from the widget product list.(see screenshot 3)
  4. After clicking Add to Cart observe a warning message in minicart. (see screenshot 4).

Expected result (*)

The bundle product should be added to the cart with bundle options.

Actual result (*)

The bundle product isn’t being added to the cart with bundle options.

Additional Information (*)

File1: Magento/CatalogWidget/view/frontend/templates/product/widget/content/grid.phtml
File2: Magento/Catalog/view/frontend/templates/product/list.phtml

If we check in the above-given list.phtml, it gets the option by using the ViewModel & which works fine on the list page. (see screenshot 5).
Screenshot 5:
image

In the given grid.phtml file it doesn’t get the options data where the add-to-cart form is rendered for the particular product (see screenshot 6). As the options are not rendered, adding that product to the cart will only add the parent bundle product to the cart without any bundle options. So, we need to implement the same thing as list.phtml to get the data in grid.phtml.

Screenshot 6:
image

Solution (*)

We have to update the given phtml to get the bundle options in the add-to-cart form. We can get the bundle product options by using the Magento\Catalog\ViewModel\Product\OptionsData ViewModel. (see screenshot 7)

A separate function has been created in the block file of the grid.phtml (Magento\CatalogWidget\Block\Product\ProductsList) to get the ViewModel that returns the object of Magento\Catalog\ViewModel\Product\OptionsData.

Screenshot 7:
image

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)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Fixes: Bundle product with only one product in required bundle option not being added to cart with bundle option. #38605: Fixes: Bundle product with only one product in required bundle option not being added to cart with bundle option.

Related Pull Requests

https://github.com/magento-gl/magento2-page-builder/pull/84

Copy link

m2-assistant bot commented Apr 10, 2024

Hi @bhoopatparmar. Thank you for your contribution!
Here are some useful tips on 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

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@bhoopatparmar
Copy link
Author

@magento run all tests

@engcom-Hotel engcom-Hotel added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Apr 10, 2024
@engcom-Hotel
Copy link
Contributor

@magento create issue

@@ -74,6 +74,12 @@ use Magento\Wishlist\Helper\Data;
<?php if ($_item->isSaleable()): ?>
<?php $postParams = $block->getAddToCartPostParams($_item); ?>
<form data-role="tocart-form" data-product-sku="<?= $escaper->escapeHtml($_item->getSku()) ?>" action="<?= $escaper->escapeUrl($postParams['action']) ?>" method="post">
<?php $options = $block->getViewModel()->getOptionsData($_item); ?>
Copy link
Contributor

@Bashev Bashev Apr 10, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Same as here: https://github.com/magento/magento2-page-builder/pull/868/files#r1560503440
<?php $options = $block->getViewModel()->getOptionsData($_item); ?>
change it to
<?php if($options = $block->getViewModel()?->getOptionsData($_item)) : ?>
will prevent empty/not assigned viewModel

and ofc, close if, at the end of foreach.

Copy link
Author

Choose a reason for hiding this comment

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

@Bashev Thanks for your suggestion. I've updated the code as per your suggestion

Copy link
Contributor

@Bashev Bashev left a comment

Choose a reason for hiding this comment

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

Looks fine for me.

@engcom-Bravo
Copy link
Contributor

@magento run all tests

@engcom-Bravo
Copy link
Contributor

@magento give me test instance

Copy link

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

Copy link

Copy link
Contributor

@engcom-Bravo engcom-Bravo left a comment

Choose a reason for hiding this comment

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

Hi @bhoopatparmar,

Thanks for the collaboration & contribution!

❌ QA not Passed

Manual Scenario Steps

  • Create a bundle product that contains one or more bundle options & each bundle option is required and must contain only one product that is default selected. (see screenshot 1)
  • Create a widget with the type ‘Catalog Product List’ with a condition that includes the newly created bundle product in the widget. (see screenshot 2)
  • From the front end visit the widget & try to add the bundle product from the widget product list.(see screenshot 3)
  • After clicking Add to Cart observe a warning message in minicart. (see screenshot 4).

✔️ Expected result After Fix 

The bundle product should be added to the cart with bundle options

❌ Actual result After Fix

Screenshot 2024-04-15 at 16 50 16 Screenshot 2024-04-15 at 16 50 46

Bundle Products are still not adding to the cart with the Bundle options.

Could you please let us know if we are missing anything.

Thanks.

@engcom-Echo
Copy link
Contributor

@magento give me test instance

Copy link

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

@magento magento deleted a comment from magento-deployment-service bot Jul 1, 2024
@magento magento deleted a comment from magento-deployment-service bot Jul 1, 2024
@magento magento deleted a comment from magento-deployment-service bot Jul 1, 2024
@magento magento deleted a comment from magento-deployment-service bot Jul 1, 2024
Copy link

@engcom-Echo
Copy link
Contributor

@magento run all tests

@engcom-Echo
Copy link
Contributor

@magento run all tests

1 similar comment
@engcom-Echo
Copy link
Contributor

@magento run all tests

Copy link
Contributor

@engcom-Bravo engcom-Bravo left a comment

Choose a reason for hiding this comment

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

Hi @bhoopatparmar,

Thanks for Contribution!!.

Could you please resolve conflicts to proceed further with the PR.

Thanks.

@bhoopatparmar
Copy link
Author

Hi @engcom-Bravo
The solution has been merged in the dev branch by in this commit: d921385
Hence closing this PR
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Project: Community Picked PRs upvoted by the community
Projects
None yet
8 participants