Jawaban:
Saya menggunakan Plugin dalam modul khusus untuk mengatur fungsi isAvailable untuk CashOnDelivery menjadi false ketika metode pengiriman "flatrate_flatrate" dipilih.
file: <magento-root>/app/code/MyCompany/MyModule/Plugin/CashonDeliveryPlug.php
<?php
namespace MyCompany\MyModule\Plugin;
use Magento\Payment\Model\Method\AbstractMethod;
use Magento\Quote\Model\Quote;
class CashondeliveryPlug
{
/**
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;
/**
* Constructor
*
* @param \Magento\Checkout\Model\Session $checkoutSession
*/
public function __construct
(
\Psr\Log\LoggerInterface $logger,
\Magento\Checkout\Model\Session $checkoutSession
) {
$this->logger = $logger;
$this->_checkoutSession = $checkoutSession;
return;
}
public function aroundIsAvailable(\Magento\Payment\Model\Method\AbstractMethod $subject, callable $proceed)
{
$shippingMethod = $this->_checkoutSession->getQuote()->getShippingAddress()->getShippingMethod();
#$this->logger->debug($shippingMethod);
if ($shippingMethod == 'flatrate_flatrate') {
return false;
}
$result = $proceed();
return $result;
}
}
dan
file: <magento-root>/app/code/MyCompany/MyModule/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\OfflinePayments\Model\Cashondelivery">
<plugin name="cashondeliveryplug" type="MyCompany\MyModule\Plugin\CashondeliveryPlug" disabled="false" sortOrder="10"/>
</type>
</config>
Semoga ini bisa membantu Anda! Jangan ragu untuk bertanya