私はmagento 1.7.0.2で代金引換支払い方法を使用しています。
この支払いオプションは、特定の郵便番号/暗証番号に対してのみ必要です。
誰でも助けることができますか?
私はmagento 1.7.0.2で代金引換支払い方法を使用しています。
この支払いオプションは、特定の郵便番号/暗証番号に対してのみ必要です。
誰でも助けることができますか?
app\design\frontend\base\default\template\checkout\onepage\payment\methods.phtml ファイルを開きます。
このファイルでは、引用オブジェクトから見積もりの配送先住所を取得できます。住所から郵便番号を取得しforeach ($methods as $_method):
、郵便番号と一致するかどうかを内部で確認してから$_method->getCode();
戻ります。メソッドコードはこちらから取得できます。
CODには機能があります
public function isAvailable($quote = null)
この最後の行の前にreturn $checkResult->isAvailable;
if条件if($checkResult->isAvailable)
呼び出しを配置します
$this->isZipCodeallowedForCod($zipCode,$quote)
この関数では、見積もりオブジェクトから請求先住所の郵便番号を取得し、許可された郵便番号のリストをチェックしてフラグを設定するロジックを適用します。
注 : これを変更する場合は、コア コードを変更しないでください。Magento の書き換えまたはオーバーライドの概念を使用してください。
私は次のことをしました
app\code\local\Mage\Payment\Model\Method\Cashondelivery.php 内
以下の機能を追加しました
public function getCODPincodes(){
$write = Mage::getSingleton('core/resource')->getConnection('core_read');
$query = "select pincode from `pincode`";
$results = $write->fetchAll($query);
foreach($results as $result){
$postcodes[] = $result['pincode'];
}
return $postcodes;
}
app\code\local\Mage\Payment\Block\Form\Container.php
protected function _canUseMethod($method){
...の下に次のコードを追加しました
次のブロックの後
if((!empty($minTotal) && ($total < $minTotal)) || (!empty($maxTotal) && ($total > $maxTotal))) {
return false;
}
追加
if($method->getCode() == "cashondelivery"){
$postcodes = Mage::getModel('payment/method_cashondelivery')->getCODPincodes();
$shippingPincode = $this->getQuote()->getShippingAddress()->getData('postcode');
if(!in_array($shippingPincode, $postcodes)){
return false;
}
}
ノート:
ピンコードと呼ばれるテーブルにすべてのピンコードがあります。
これは私の要件の簡単な修正であるため、これに関する小さなモジュールを開発します
必要なのは、ファイル /app/code/core/Mage/Payment/Model/Method/Cashondelivery.php を編集することだけです
それを開き、以下のコードをクラスの最後 (ファイルの最後の「}」の直前) に追加します。
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);
}