7

I am very new to the magento checkout process so forgive my lack of knowledge. Is there a way of displaying certain payment options for certain customer groups. For example i have changed the "purchase order number" to "30 day credit account" but this is only available to a certain customer group so I only want it to display when the user is logged in and is part of that customer group.

Again sorry for my lack of knowledge, if you can help you would be a life saver.

Thank you

1
  • upvote from me...
    – Amit Bera
    Commented Oct 29, 2014 at 14:24

5 Answers 5

10

you can do this using magento event observer,create an event on payment_method_is_active and depednds on customer group disable and enable payment method:

check this link: Implementing payment method per currency

and you need do on some change in observer.php I have trying to example and try to modify according to you

   public function filterpaymentmethod(Varien_Event_Observer $observer) {
        /* call get payment method */
        $method = $observer->getEvent()->getMethodInstance();
if(Mage::getSingleton('customer/session')->isLoggedIn()) {

 $roleId = Mage::getSingleton('customer/session')->getCustomerGroupId();
 $role = Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code');

      if($method->getCode()=='purchaseorder'){
            $quote = $observer->getEvent()->getQuote();

            if($role == $yourcustomergroupid){
              $result = $observer->getEvent()->getResult();   
              $result->isAvailable = true;
              return;
            }else{
               $result = $observer->getEvent()->getResult();   
               $result->isAvailable = false;
            }
        }

     if($method->getCode()=='checkmo'){
            $quote = $observer->getEvent()->getQuote();

            if($role == $yourcustomergroupid){
              $result = $observer->getEvent()->getResult();   
              $result->isAvailable = true;
            return;
            }else{
              $result = $observer->getEvent()->getResult();   
              $result->isAvailable = false;
            }
        }
}

}

Note: If you not getting customer group id from session then you need tp load customer by customer id(which is must get from session) for getting customer group from session try below:

https://stackoverflow.com/questions/9242390/showing-which-group-a-customer-belongs-to-in-magento http://xhtmlandcsshelp.blogspot.in/2010/12/get-customer-group-id-in-magento.html

Let me know if you have any confusion

8
  • do i put the observer in another directory called model?
    – Adam Allen
    Commented Aug 26, 2014 at 11:46
  • 1
    you need to create Observer.php at app/code/local/Bh/ZeroSubtotalpaymentmethod/Model/ ... and just change in filterpaymentmethod
    – Amit Bera
    Commented Aug 26, 2014 at 11:53
  • 1
    also create the config under /etc. do i need to create a new .xml file in app/etc/modules/ as well? Thank you for your patience as well :)
    – Adam Allen
    Commented Aug 26, 2014 at 11:58
  • config.xml under app/code/local/Bh>ZeroSubtotalpaymentmethod>etc.
    – Amit Bera
    Commented Aug 26, 2014 at 12:11
  • 1
    create Bh_ZeroSubtotalpaymentmethod.xml on app/etc/modules/
    – Amit Bera
    Commented Aug 26, 2014 at 12:11
4

You can use the extension and its working fine for customer group and also filter by product and its free:

http://www.magentocommerce.com/magento-connect/paymentfilter-for-products-and-customer-groups.html

4

In Magento 2

Let’s create a module. Step 1) Create folders like this.

app/code/Pits/PaymentMethod/etc/
app/code/Pits/PaymentMethod/Observer/

Step 2) Declare your module

app/code/Pits/PaymentMethod/etc/module.xml.

Paste the following code in the above file.

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Pits_PaymentMethod" setup_version="2.0.0" /></config>

Step 4 ) Create registration file. app/code/Pits/PaymentMethod/registration.php Paste the below code.

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Pits_PaymentMethod',
    __DIR__
);

Step 5)Run the below command in the command line

php bin/magento module:enable Pits_PaymentMethod

 php bin/magento setup:upgrade

Step 6)Lets create events.xml file

app/code/Pits/PaymentMethod/etc/events.xml

Paste the below code in it.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="payment_method_is_active">
        <observer name="Pits_PaymentMethod_DisabledPgByCustomergroup" instance="Pits\PaymentMethod\Observer\DisabledPgByCustomergroup" />
    </event>
</config>

Step 7)Lets create observer file

app/code/Pits/PaymentMethod/Observer/DisabledPgByCustomergroup.php.php



<?php
namespace Pits\PaymentMethod\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;
class DisabledPgByCustomergroup implements ObserverInterface
{
    public function __construct(\Psr\Log\LoggerInterface $logger)
    {
        $this->_logger = $logger;
    }
    /**
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $result          = $observer->getEvent()->getResult();
        $method_instance = $observer->getEvent()->getMethodInstance();
        $quote           = $observer->getEvent()->getQuote();
        $this->_logger->info($method_instance->getCode());
        /* If Cusomer  group is match then work */
        if (null !== $quote && $quote->getCustomerGroupId() != 4) {
            /* Disable All payment gateway  exclude Your payment Gateway*/
            if ($method_instance->getCode() == 'purchaseorder') {
                $result->setData('is_available', false);
            }
        }
        /*else{
        if($method_instance->getCode() =='purchaseorder'){
        $result->setData('is_available', true);

        }
        }*/
    }
}

Step 8)Run this in command line

php bin/magento setup:upgrade
1

You can check this extension :

http://amasty.com/shipping-payment-by-customer-group.html by @Amasty

Allow you filter payment methods and shipping methods by customer groups

0

This free extensions will help you out:

https://github.com/riconeitzel/PaymentFilter

Not the answer you're looking for? Browse other questions tagged or ask your own question.