我想为某些用户群启用或显示现金支付。用户组=“A”例如?
答案 0 :(得分:0)
您可以通过使用Magento Event/Observer
配置文件
<?xml version = "1.0"?>
<config>
<modules>
<Package_Cashondelivery>
<version>0.1.0</version>
</Package_Cashondelivery>
</modules>
<events>
<payment_method_is_active>
<observers>
<paymentfilter_payment_method_is_active>
<type>singleton</type>
<class>Package_Cashondelivery_model_observer</class>
<method>filterpaymentmethod</method>
</paymentfilter_payment_method_is_active>
</observers>
</payment_method_is_active>
</events>
</config>
observer.php
class Package_Cashondelivery_Model_Observer {
public function filterpaymentmethod(Varien_Event_Observer $observer) {
/* call get payment method */
$method = $observer->getEvent()->getMethodInstance();
$role = "Retailer"; // you can create an array if there are multiple group
/* get Quote */
$quote = $observer->getEvent()->getQuote();
/* Disable Your payment method for adminStore */
if ($role == "Retiler") { // check with in_array for multiple group
$result = $observer->getEvent()->getResult();
$result->isAvailable = true;
}
}
}
答案 1 :(得分:0)
您的解决方案激活所有付款方式,这不是我想要的!
所以我找到了那些想要为用户组启用现金支付的解决方案。
/app/etc/modules/Amir_ActiveCashPaiement.xml
<?xml version="1.0"?>
<config>
<modules>
<Amir_ActiveCashPaiement>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Payment/>
</depends>
</Amir_ActiveCashPaiement>
</modules>
</config>
/app/code/local/Amir/ActiveCashPaiement/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Amir_ActiveCashPaiement>
<version>0.0.1</version>
</Amir_ActiveCashPaiement>
</modules>
<global>
<models>
<Amir_ActiveCashPaiement>
<class>Amir_ActiveCashPaiement_Model</class>
</Amir_ActiveCashPaiement>
</models>
<events>
<payment_method_is_active>
<observers>
<Amir_ActiveCashPaiement>
<type>singleton</type>
<class>Amir_ActiveCashPaiement/Observer</class>
<method>paymentMethodIsActive</method>
</Amir_ActiveCashPaiement>
</observers>
</payment_method_is_active>
</events>
</global>
</config>
/app/code/local/Amir/ActiveCashPaiement/Model/Observer.php
<?php
class Amir_ActiveCashPaiement_Model_Observer
{
public function paymentMethodIsActive($observer)
{
$instance = $observer->getMethodInstance();
$result = $observer->getResult();
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
//Get customer Group name
$group = Mage::getModel('customer/group')->load($groupId);
//get the name of method payment cashondelivery
if ($instance->getCode() == "cashondelivery") {
if ($group->getCode()== "yourgroupname") {
$result->isAvailable = true;
} else {
$result->isAvailable = false;
}
}
}
}
//think to disable the cash paiement in the backend,
and this module will active this method when the user group log.
?>