0

I have made a custom module. But block rendered twice.

My local system is working fine. But on Production is getting the error.

Anyone help me with this.

Controller

<?php

namespace Codism\Configurator\Controller\Index;

class Builtcatcollection extends \Magento\Framework\App\Action\Action
{
    protected $__coreRegistry;
    protected $_resultPageFactory;


    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Framework\View\Result\PageFactory $pageFactory)
    {
        $this->_coreRegistry = $coreRegistry;
        $this->_resultPageFactory = $pageFactory;
        parent::__construct($context);
    }

    public function execute()
    {
        $itemid = $this->getRequest()->getParam('itemid');
        $this->_coreRegistry->register('itemid', $itemid);
        $resultPage = $this->_resultPageFactory->create();
        return $resultPage;
        //$this->_redirect('csr/index/find');
    }
}

Block

<?php


namespace Codism\Configurator\Block\Index;

class Categorycollection extends \Magento\Framework\View\Element\Template
{
    protected $_cart;
    protected $_coreRegistry;
    protected $_productRepository;
    protected $_category;
    protected $_categoryFactory;
    protected $_categoryHelper;
    protected $_categoryRepository;
    protected $listProductBlock;
    protected $_isScopePrivate;

    /**
     * Constructor
     *
     * @param \Magento\Framework\View\Element\Template\Context  $context
     * @param array $data
     */

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Catalog\Model\ProductRepository $productRepository,
        \Magento\Checkout\Model\Cart $cart,
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Catalog\Model\CategoryFactory $categoryFactory,
        \Magento\Catalog\Model\CategoryRepository $categoryRepository,
        \Magento\Catalog\Helper\Category $categoryHelper,
        \Magento\Catalog\Block\Product\ListProduct $listProductBlock,
        array $data
    )
    {
        parent::__construct($context, $data);
        $this->_cart = $cart;
        $this->_productRepository = $productRepository;
        $this->_coreRegistry = $coreRegistry;
        $this->_categoryFactory = $categoryFactory;
        $this->listProductBlock = $listProductBlock;
        $this->_isScopePrivate = true;

    }

    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }


    /**
     * Get category object
     * Using $_categoryFactory
     *
     * @return \Magento\Catalog\Model\Category
     */
    public function getCategory($categoryId)
    {
        $this->_category = $this->_categoryFactory->create();
        $this->_category->load($categoryId);
        return $this->_category;
    }

    public function getProductId()
    {
        return $this->_coreRegistry->registry('itemid');
    }

    public function getProductById($productId)
    {
        /*$productId = $this->_coreRegistry->registry('itemid');*/
        return $this->_productRepository->getById($productId);
    }

    public function getProductCol($categoryId, $product)
    {
        $products = $this->getCategory($categoryId)->getProductCollection();
        $products->addAttributeToSelect('*');
        $products->addAttributeToFilter('sku', array('neq' => $product->getSku()));
        $products->addAttributeToFilter('outdoor_brands', array('eq' => $product->getOutdoorBrands()));
        $products->setOrder('price', 'ASC');
        $products->setPageSize(1);
        $products->setCurPage(12);
        return $products;
    }

    public function getBrandProductAction()
    {
        return $this->getUrl('configurator/index/builtproductcollection', ['_secure' => true]);
    }
}

Layout

<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Codism\Configurator\Block\Index\Categorycollection" name="index.builtcollection" template="Codism_Configurator::index/builtcatcollection.phtml"/>
        </referenceContainer>
    </body>
</page> 

Block rendered twice Block rendered twice

  • what error, you get ? – Anas Mansuri Jul 3 at 12:53
  • Block rendered twice. Check in image data rendered two times @AnasMansuri – Masud Shaikh Jul 3 at 13:07
  • @MasudShaikh, can you share complete code of your module? – Mohit Kumar Arora Jul 3 at 16:50
  • How can I share you code? @MohitKumarArora – Masud Shaikh Jul 3 at 18:00
  • I have added the code. Please check @MohitKumarArora – Masud Shaikh Jul 3 at 18:35

Your Answer

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

Browse other questions tagged or ask your own question.