답변:
배송 방법 "flatrate_flatrate"를 선택할 때 CashOnDelivery의 isAvailable 함수를 false로 설정하기 위해 사용자 정의 모듈의 플러그인을 사용합니다.
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;
}
}
과
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>
이것이 당신에게 도움이되기를 바랍니다! 궁금한 점이 있으면 언제든지 문의하십시오