How to change CrossSell product limit in Magento 2?

Magento 2, Cross-sell product will be display in Shopping Cart page. By Native Magento, Only four Cross-sell product will be display in cart page. If you want to increase or decrease the Cross-sell Product display limit in cart page you need to modify Core Crosssell.php file.

Native file location for CrossSell Product, Magento\Checkout\Block\Cart\Crosssell

You can check the hardcoded product limit by protected $_maxItemCount = 4;

If you want to change the limit you need to override $_maxItemCount variable.

Never modify the core file in Magento.

To override variable you need to create a module for changes.

I have kept Rbj as Packagename and CrossSell as Module name.
Create a Module called Rbj_CrossSell.
Create registration.php and module.xml to declare our module.
File Path, app/code/Rbj/CrossSell/registration.php

File Path, app/code/Rbj/CrossSell/etc/module.xml  We have added the dependency on Native CrossSell module.

Create di.xml file for an override core file,

File: app/code/Rbj/CrossSell/etc/frontend/di.xml

Now Create Block file,
Create app/code/Rbj/CrossSell/Block/Cart/Crosssell.php

Run Command to Install Our module from a root of your Magento instance,

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *