0

I am showing related products in magento2 in Product description page . And this is I guess due to these lines in code in catalog_product_view.xml

 <referenceBlock name="catalog.product.related" >
            <action method="setTemplate">
                <argument name="template" xsi:type="helper" helper="Infortis\Base\Helper\Template\Catalog\Product\View::getRelatedProductsTemplate" />

            </action>
        </referenceBlock>

And It is showing on front page like this related products

So I want now that Can I remove its slider and show only 2 products all time ?

How it is possible to do that ? I am using infornite theme

  • You have using Infotis theme,Please check it setting – Amit Bera Sep 21 '17 at 6:58
  • @AmitBera which settings ? – Learner Sep 21 '17 at 6:58
  • @AmitBera which files you are talking ? – Learner Sep 21 '17 at 7:03
1

There are two way to limit the upsell products on product view page :

  1. Overide the Magento_Catalog's Block using a custom module

Create a custom module and create a di.xml(CompanyName/ModuleName/etc/frontend/di.xml) file in it.

  <?xml version="1.0" encoding="UTF-8" ?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <type name="Magento\Catalog\Block\Product\ProductList\Related">
         <plugin name="CompanyName_ModuleName_plugin" type="CompanyName\ModuleName\Block\Plugin\Product\ProductList\Related" sortOrder="0" />
     </type>
 </config>

Create CompanyName/ModuleName/Block/Plugin/Product/ProductList/Related.php

 <?php
 namespace CompanyName\ModuleName\Block\Plugin\Product\ProductList;

 /**
  * Class Related
  *
  * @package CompanyName\ModuleName\Block\Plugin\Product\ProductList
  */
 class Related
 {
     /**
      * Add limit to related product collection if page_size argument is defined
      *
      * @param \Magento\Catalog\Block\Product\ProductList\Related $subject
      * @param $result
      *
      * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
      */
     public function afterGetItems(\Magento\Catalog\Block\Product\ProductList\Related $subject, $result)
     {
         $pageSize = 3;
         $collection = $result;

         if ($pageSize) {
             $collection->getSelect()->limit($pageSize);
         }

         return $collection;
     }
 }
  1. Second method is override the items.phtml file

Copy items.phtml into your theme like app/design/frontend/mypackage/mytheme/Magento_Catalog/templates/product/list/items.phtml

Line No. 62 replace below code:

 $limit = $block->getPositionLimit();
 to
 $limit = 3;

 and Line No. 82 replace below code:

 $limit = $block->getItemLimit('upsell'); 
 to
 $limit = 3;
  • is it for ultimo theme or luma ? – Learner Sep 21 '17 at 8:03
  • Either, its a method to override and get the result as needed – Envision Ecommerce Sep 21 '17 at 8:06
  • I think its for upsell ? ?? I want for related products actually – Learner Sep 21 '17 at 8:06
  • and items.phtml of which module I have to copy? – Learner Sep 21 '17 at 8:10
  • /vendor/magento/module-catalog/view/frontend/templates/product/list/items.phtml – Envision Ecommerce Sep 21 '17 at 8:18

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.