问题描述
我们在magento 1.9.0中使用货到付款付款方式
we are using Cash On Delivery Payment method in magento 1.9.0
我们仅对某些邮政编码/PIN码需要此付款方式.
we need this payment option only for certain zip codes/pin codes.
有人在这里找到解决方法:
here someone got solution :
如何限制默认COD在magento中仅对某些邮政编码有效吗?
我真的无法通过一些想法来实现该解决方案.
i really can't able to implement that solution with some ideas.
谁能详细解释该解决方案.
can anyone explain me step by step in detail about that solution.
推荐答案
所有您需要编辑的文件/app/code/core/Mage/Payment/Model/Method/Cashondelivery.php
All you need is to edit the file /app/code/core/Mage/Payment/Model/Method/Cashondelivery.php
打开它,并将下面的代码添加到类的最后(恰好在文件中的最后一个}"之前):
Open it and add the code below to the very end of the class (just before the last "}" in the file):
public function isAvailable($quote = null)
{
if ($quote) {
// Here is the list of restricted Zip Codes
$restrictedZips = array(
'85001',
'87965'
);
$address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
$customerZip = $address->getPostcode();
if (in_array($customerZip, $restrictedZips)) {
return false;
}
}
return parent::isAvailable($quote);
}
P.S .:请注意,使用此解决方案,您将需要在代码中直接输入邮政编码.如果您想避免这种情况,并能够通过管理员面板输入邮政编码范围,请与我们联系以获取更多详细信息.
P.S.: Note, that with this solution you will need to enter zip-codes right in the code. If you would like to avoid this, and get the ability to enter zip ranges via the admin's panel, contact us for more detail.
这篇关于限制magento 1.9.0中某些邮政编码的默认货到付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!