Question

I have created two stores in Magento2. One is main website and the second one is retailer site. I need to remove the footer section and the navigation bar for my retailer site. I also need to remove the favorites section from the header only for my retailer site.

Please anyone guide me on this.

Any help would be appreciated.

Était-ce utile?

La solution

There is another way to can remove the block from the layout.

Create layout unique handle fro each store like store_en , store_retailer, where to assume that the retailer is the store code of your retailer store & `en is default store code.

Add custom layout handle using on layout_load_before.

Observer code

 <?php
namespace StackExchange\Magento\Observer\Frontend;

class LayoutLoadBefore implements \Magento\Framework\Event\ObserverInterface {

    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    private $storeManager;

    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ) {
        $this->storeManager = $storeManager;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $layout = $observer->getEvent()->getLayout();

        $handlecode ='store_'.strtolower($this->storeManager->getStore()->getCode());
        $layout->getUpdate()->addHandle($handlecode);
        return $this;
    }

}


        public function execute(\Magento\Framework\Event\Observer $observer)
        {

               $layout = $observer->getLayout();
           $handlecode = 'store_'. strtolower($this->_storeManager->getStore()->getCode());
               $layout->getUpdate()->addHandle($handlecode);

           return $this;
        }
    }

After adding this observer, you need to do Cache flush/Di compile.

Now. if you need to create a handler file at app/code/{Vendorname}/{Module Name}/view/frontend/layout/store_{retailerSITEStoreCode}.xml

<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="header.container" remove="true" />
        <referenceContainer name="footer" remove="true" />
    </body>
</page>

Autres conseils

I would recommend creating a child theme for your retailer site and remove elements accordingly.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top