Skip to main content

Posts

Showing posts from August, 2019

Magento 2: Disable Payment method on checkout page programatically

We could disable particular payment method on checkout page using following event: payment_method_is_active we need to create two files in our extension for the same: first one is events.xml : and following is the code of events.xml: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">     <event name="payment_method_is_active">         <observer name="packagename_payment_filter_module" instance="packagename\Modulename\Observer\Observerfilename"/>     </event> </config> second one is Observerfilename.php : and following is the code of Observerfilename.php, and we have to put this code inside execute function: $event = $observer->getEvent(); $code = $event->getMethodInstance()->getCode(); $checkResult = $observer->getEvent()->getResult(); if($code == "casho...

Magento 2: Get product categories on product page

To get the product categories on product page use following code: $_product = $block->getProduct(); $categories = $_product->getCategoryIds(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); foreach ($categories as $category) {   $cat = $objectManager->create('Magento\Catalog\Model\Category')->load($category);   echo $cat->getId()."<br/>"; }