cancel
Showing results for 
Search instead for 
Did you mean: 

In Magento 2 how to disable offline payment method for downloadable product

In Magento 2 how to disable offline payment method for downloadable product

In Magento 2 how to disable offline payment method for downloadable product Can any one help me to solve the situation .

6 REPLIES 6

Re: In Magento 2 how to disable offline payment method for downloadable product

HI @rina_test 

 

Try the below solution:

 

https://magento.stackexchange.com/a/154158

 

I hope it will help you!

Re: In Magento 2 how to disable offline payment method for downloadable product

Hi @Vimal Kumar 

 

I have already tried the solution ,

but in checkout nothing reflect ,

path: app/code/Cloudways/EventsObservers/etc/frontend/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="CloudwaysProductData" instance="Cloudways\EventsObservers\Observer\Product\Data" />
</event>
</config>

 

path : app/code/Cloudways/EventsObservers/Observer/Product/Data.php

<?php

namespace Cloudways\EventsObservers\Observer\Product;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Event\Observer;
use Psr\Log\LoggerInterface as Logger;

class Data implements ObserverInterface
{

protected $_logger;

public function __construct(
Logger $logger
) {
$this->_logger = $logger;

}

/**
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(Observer $observer)
{

 

$result = $observer->getEvent()->getResult();
$method_instance = $observer->getEvent()->getMethodInstance();
$quote = $observer->getEvent()->getQuote();

if(null !== $quote){
/* Disable All payment gateway exclude Your payment Gateway*/
if($method_instance->getCode() =='cashondelivery'){
$items= $quote->getAllVisibleItems();
foreach ($items as $eachitem) {
if($eachitem->getProductType()=='downloadable'):
$result->setData('is_available', false);
break;
endif;

}

}
}

}

}

 

 

For testing I have enable   COD and ChkMo  these two payment method in my site .

But after integrating the above as module , COD not disappear for "downloadable" product .

 

 you please share what was the wrong in the above .

 

Thanks

Re: In Magento 2 how to disable offline payment method for downloadable product

@rina_test Have you flush the cache after this.

 

If not please flush the cache and check if everything is working.

 

Also run the below command and check whether your module is not disabled if it is then please enable it.

 

php bin/magento module:status

Thanks

Re: In Magento 2 how to disable offline payment method for downloadable product

Hih @Rahul Gupta 

 

Yes I have checked carefully , the plugin is enabled and after creating this module I have run cache clean command and setup:upgrade and setup:di:compile command , still it not reflecting in checkout .

Can you please install the above module in your setup , and can you please inform is that reflect at your end or not .

 

Thanks

Re: In Magento 2 how to disable offline payment method for downloadable product

@rina_test sure i will install it and let you know.

Re: In Magento 2 how to disable offline payment method for downloadable product

Hi @rahul Gupta ,

Thanks for reply , Please inform in the same process is the COD disable for downloadable product or not .

 

Thanks