Skip to content
This repository has been archived by the owner on Aug 1, 2018. It is now read-only.

Commit

Permalink
Add feature request #23 - Regions limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Jul 11, 2017
1 parent 5d567af commit aad8ce6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
17 changes: 17 additions & 0 deletions Model/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,28 @@
class Payment extends AbstractMethod
{
const CODE = 'msp_cashondelivery';
const XML_PATH_EXCLUDE_REGIONS = 'payment/msp_cashondelivery/exclude_regions';

protected $_code = self::CODE;

protected $_formBlockType = 'Magento\OfflinePayments\Block\Form\Checkmo';
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;
}
}
9 changes: 7 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@
<label>Payment from Specific Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
</field>
<field id="min_order_total" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<field id="exclude_regions" translate="label" type="multiselect" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Exclude Specific Regions</label>
<source_model>Magento\Directory\Model\Config\Source\Allregion</source_model>
<can_be_empty>1</can_be_empty>
</field>
<field id="min_order_total" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Minimum Order Total</label>
<comment>Leave empty to disable limit</comment>
</field>
<field id="max_order_total" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<field id="max_order_total" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Maximum Order Total</label>
<comment>Leave empty to disable limit</comment>
</field>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MSP_CashOnDelivery" setup_version="1.1.4">
<module name="MSP_CashOnDelivery" setup_version="1.1.5">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down

0 comments on commit aad8ce6

Please sign in to comment.