We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    I’ve to add custom CSS for particular store on checkout page, so I’ve updated a layout using observer.

    Please follow the below method. you need to copy the below event in your module.

    <?xml version="1.0" encoding="UTF-8" ?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="layout_load_before">
            <observer name="magemonkeys_customshipping_addcustomcheckouthandle" instance="MagemonkeysCustomshippingObserverAddCheckoutLayoutUpdateHandleObserver" />
        </event>
    </config>

    And you can copy the below code for add the layout handle in Observer class.

    <?php
    
    namespace MagemonkeysCustomshippingObserver;
    
    use MagentoCatalogModelCategory as CategoryModel;
    use MagentoFrameworkEvent;
    use MagentoFrameworkEventObserver as EventObserver;
    use MagentoFrameworkEventObserverInterface;
    use MagentoFrameworkRegistry;
    use MagentoFrameworkViewLayout as Layout;
    use MagentoFrameworkViewLayoutProcessorInterface as LayoutProcessor;
    
    /**
     *  AddCheckoutLayoutUpdateHandleObserver
     */
    class AddCheckoutLayoutUpdateHandleObserver implements ObserverInterface
    {
       
        const LAYOUT_HANDLE_NAME = 'checkout_index_index_emp';
        const LAYOUT_HANDLE_NAME_CUSTOMER = 'customer_account_emp';
    
        public $storeManager;
    	public $customerSession;
    
        public function __construct(
            MagentoStoreModelStoreManagerInterface $storeManager,
    		MagentoCustomerModelSession $customer
        ) {
            $this->storeManager = $storeManager;        
            $this->customerSession = $customer;        
        }
    	
    	public function getStoreCode()
    	{
    		return $this->storeManager->getStore()->getCode();
    	}
    
        /**
         * @param EventObserver $observer
         *
         * @return void
         */
        public function execute(EventObserver $observer)
        {
            /** @var Event $event */
            $event = $observer->getEvent();
            $actionName = $event->getData('full_action_name');
    		
            if ($actionName === 'checkout_index_index') {
                /** @var Layout $layout */
                $layout = $event->getData('layout');
    
                /** @var LayoutProcessor $layoutUpdate */
                $layoutUpdate = $layout->getUpdate();
    
                // check if Category Display Mode is "Mixed"
                if($this->getStoreCode() == 'abc_store' && $this->customerSession->isLoggedIn())
    			{
                    $layoutUpdate->addHandle(static::LAYOUT_HANDLE_NAME);
                }
            }
        }
    }

    That’s it. Now you can use the checkout_index_index_emp.xml file in your view/frontend/layout directory and make the changes as per your requirement.

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote