0

I want to display more than 4 products in the related products block. I've tried some solutions like overriding the core Related.php class and using methods:

$this->_itemCollection->setPageLimit(6), 
$this->_itemCollection->getSelect()->limit(6). 

Also, changed the $limit variable to 6 in the related.phtml file, but none of these worked.I want to increase the products count here: enter image description here

Any kind of help would be appreciated

10
  • Please check for number of products assigned as related products. – Rahul Barot May 11 at 10:31
  • Could you specify where to check? – Toma Margishvili May 11 at 10:33
  • Check in the backend for product which you are checking. Catalog -> Product -> Related Products section. – Rahul Barot May 11 at 10:34
  • I want to display more than 4 on all products and I can't see anything I can change to increase the count to more than 4 in .phtml nor Related.php – Toma Margishvili May 11 at 10:35
  • Have you checked in backend? more than 4 products are assigned as related products. – Rahul Barot May 11 at 10:44
0

There is no fixed limit on how many related products magento shows on your product page. Depending on the screen width it will allow you no navigate throug them or show them all at once.

Please on your back end go to CATALOG => PRODUCTS. Edit the product you want to add related products to. Scroll down until you find this section "Related Products, Up-Sells, and Cross-Sells ". Expand it and and now you can add as many products as you wich :)

enter image description here

0

Edit below code

  1. vendor/magento/module-catalog/Block/Product/ProductList/Related.php

    $this->_itemCollection->setPageSize(6);

protected function _prepareData()
    {
        $product = $this->getProduct();
        /* @var $product \Magento\Catalog\Model\Product */

        $this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect(
            'required_options'
        )->setPositionOrder()->addStoreFilter();

        if ($this->moduleManager->isEnabled('Magento_Checkout')) {
            $this->_addProductAttributesAndPrices($this->_itemCollection);
        }
        $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
        $this->_itemCollection->setPageSize(6);
        $this->_itemCollection->load();

        foreach ($this->_itemCollection as $product) {
            $product->setDoNotUseCategoryId(true);
        }

        return $this;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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