diff --git a/Model/Payment.php b/Model/Payment.php
index 95cbb20..f2382ef 100644
--- a/Model/Payment.php
+++ b/Model/Payment.php
@@ -25,6 +25,7 @@
class Payment extends AbstractMethod
{
const CODE = 'msp_cashondelivery';
+ const XML_PATH_EXCLUDE_REGIONS = 'payment/msp_cashondelivery/exclude_regions';
protected $_code = self::CODE;
@@ -32,4 +33,20 @@ class Payment extends AbstractMethod
protected $_infoBlockType = 'MSP\CashOnDelivery\Block\Info\CashOnDelivery';
protected $_isOffline = true;
+
+ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
+ {
+ if (!parent::isAvailable($quote)) {
+ return false;
+ }
+
+ $excludeRegions = explode(',', $this->_scopeConfig->getValue(static::XML_PATH_EXCLUDE_REGIONS));
+ foreach ($quote->getAllShippingAddresses() as $shippingAddress) {
+ if (in_array($shippingAddress->getRegionId(), $excludeRegions)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index f186cf3..087c014 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -46,11 +46,16 @@
Magento\Directory\Model\Config\Source\Country
-
+
+
+ Magento\Directory\Model\Config\Source\Allregion
+ 1
+
+
Leave empty to disable limit
-
+
Leave empty to disable limit
diff --git a/etc/module.xml b/etc/module.xml
index ed0f864..b176c14 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -21,7 +21,7 @@
-->
-
+