0

I want to split cart data based on product dropdown attributes.

I want to show multiple cart data data on cart page.

If anyone knows so please help me.

1 Answer 1

0

To split cart data based on product dropdown attributes in Magento 2, you will need to create a custom module with a plugin for the cart block class. Here are the steps you can follow:

Step 1: Create a custom module Create a custom module in your Magento 2 instance by following these steps:

  1. Create the module directory in app/code.
  2. Create the module registration file in app/code/{VendorName}/{ModuleName}/registration.php.
  3. Create the module configuration file in app/code/{VendorName}/{ModuleName}/etc/module.xml.

Step 2: Create a plugin for the cart block class In your custom module, create a plugin for the Magento\Checkout\Block\Cart class that will modify the cart items collection based on the selected product attribute. Here are the steps:

  1. Create a di.xml file in app/code/{VendorName}/{ModuleName}/etc/frontend/ and define the plugin in it.
  2. Create a PHP class for the plugin in app/code/{VendorName}/{ModuleName}/Plugin/Checkout/Block/Cart.php.
  3. In the plugin class, implement the afterGetItems method to modify the cart items collection based on the selected product attribute.

Step 3: Modify the cart template to show multiple cart data In your custom module, modify the cart template to show multiple cart data sections based on the selected product attribute. Here are the steps:

  1. Copy the cart template file from vendor/magento/module-checkout/view/frontend/templates/cart/items.phtml to app/code/{VendorName}/{ModuleName}/view/frontend/templates/cart/items.phtml.
  2. Modify the template to show multiple cart data sections based on the selected product attribute.

That's it! After you have completed these steps, you should be able to split cart data based on product dropdown attributes and show multiple cart data sections on the cart page.

1
  • Thanks for your reply.
    – Mr ND
    Commented Mar 9, 2023 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.