Let’s initiate a discussion!!
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.
1 2 3 4 5 6 |
<?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="Magemonkeys\Customshipping\Observer\AddCheckoutLayoutUpdateHandleObserver" /> </event> </config> |
And you can copy the below code for add the layout handle in Observer class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
<?php namespace Magemonkeys\Customshipping\Observer; use Magento\Catalog\Model\Category as CategoryModel; use Magento\Framework\Event; use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Registry; use Magento\Framework\View\Layout as Layout; use Magento\Framework\View\Layout\ProcessorInterface 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( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Model\Session $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.
[crayon-641fa52b45857773181005/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.