How To

How to Change Cross-Sell Product Limit in Magento 2?

Hello Magento Friends,

Today I am here with another Magento solution on How to Change the Cross-Sell Product Display Limit in Magento 2?

Cross-selling products are supplements of the products added to the shopping cart. In Magento 2, Cross-sell products will be displayed on the Shopping Cart page.

Learn How to Setup Cross-Sell Products in Magento 2.

Also, Get Cross Sell Products Collection using Root Script in Magento 2.

In default Magento, only four Cross-sell products will be displayed on the cart page. If you want to increase or decrease the Cross-sell Product display limit on the cart page, you need to modify the core cross-sell.php file. Let’s understand deeply.

Steps to Change Cross-Sell Product Limit in Magento 2:

Step 1: First, you must create a di.xml file in the path below.

app/code/Vendor/Extension/etc/frontend/di.xml

Then, add the code as follows.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Checkout\Block\Cart\Crosssell" type="Vendor\Extension\Block\Cart\Crosssell" />
</config>

Step 2: After that, you must create a Block file in the path below.

app/code/Vendor/Extension/Block/Cart/Crosssell.php

Now add the following code snippet.

<?php

namespace Vendor\Extension\Block\Cart;

use Magento\CatalogInventory\Helper\Stock as StockHelper;

class Crosssell extends \Magento\Checkout\Block\Cart\Crosssell
{
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Catalog\Model\Product\Visibility $productVisibility,
        \Magento\Catalog\Model\Product\LinkFactory $productLinkFactory,
        \Magento\Quote\Model\Quote\Item\RelatedProducts $itemRelationsList,
        \Magento\CatalogInventory\Helper\Stock $stockHelper,
        array $data = []
    ) {
        parent::__construct(
            $context,
            $checkoutSession,
            $productVisibility,
            $productLinkFactory,
            $itemRelationsList,
            $stockHelper,
            $data
        );

        $this->_maxItemCount = 7; // here set your product limit 
    }
}

Step 3: After that, run the below commands.

php bin/magento setup:di:compile
php bin/magento cache:flush

Conclusion:

Hence, accordingly, you can update the number of cross-selling products displayed on the shopping cart page in Magento 2. If you have any difficulty implementing the above steps, let me know through the comment section without hesitation. I will be quick to revert you back with a proper solution. Moreover, share the tutorial with your friends and stay in the know for more.

Happy Coding!

Click to rate this post!
[Total: 0 Average: 0]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

20 hours ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

3 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

3 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

4 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

5 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago