Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to hide a payment method based on grand total ? 
 
cybermaniak
Member
 
Total Posts:  31
Joined:  2011-11-30
 

Well I have some payments methods..  But I need to hide one when the amount of cart (including shipping) is greater than $3000

The method i need to hide is based on this one..
http://www.excellencemagentoblog.com/magento-create-custom-payment-method

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

In order to filter the payment method based on some condition, you can observe the event called ‘payment_method_is_active’
For more details please check the following tutorial:
http://www.blog.magepsycho.com/how-to-filter-payment-method-in-onepage-checkout/

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
cybermaniak
Member
 
Total Posts:  31
Joined:  2011-11-30
 

Thanks I have been reading your blog all day..  But I really don’t know how to apply this to filter based on amount..  My programming skills are none..  but I can follow tutorials.. 

I guess your code

<?php
/**
 * @category   MagePsycho
 * @package    MagePsycho_Paymentfilter
 * @author     magepsycho@gmail.com
 * @website    http://www.magepsycho.com
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
    */
class MagePsycho_Paymentfilter_Model_Observer {
 
    
public function paymentMethodIsActive(Varien_Event_Observer $observer{
        $event           
$observer->getEvent();
        
$method          $event->getMethodInstance();
        
$result          $event->getResult();
        
$currencyCode    Mage::app()->getStore()->getCurrentCurrencyCode();
 
        if( 
$currencyCode == 'USD'){
            
if($method->getCode() == 'paypal_standard' ){
                $result
->isAvailable true;
            
}else{
                $result
->isAvailable false;
            
}
        }
    }
 
}

Should be… something like this..  where i put ???  is what i need to change, but to what… lol.

<?php
/**
 * @category   MagePsycho
 * @package    MagePsycho_Paymentfilter
 * @author     magepsycho@gmail.com
 * @website    http://www.magepsycho.com
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
    */
class MagePsycho_Paymentfilter_Model_Observer {
 
    
public function paymentMethodIsActive(Varien_Event_Observer $observer{
        $event           
$observer->getEvent();
        
$method          $event->getMethodInstance();
        
$result          $event->getResult();
        
$grandtotalAmount    Mage::app()->getStore()->????????();
 
        if( 
$grandtotalAmount == '>the amount I want '){
            
if($method->getCode() == 'my_payment' ){
                $result
->isAvailable false;
            
}else{
                $result
->isAvailable true;
            
}
        }
    }
 
}

But really don’t know what should be the correct codes.. 

On a side note, Also tried your tutorial on send attachments with the “contact us” form..  And even it shows to browse the file, the file is never been sent :(

Thanks for the comment..

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

In order to get the grand total you can use the following code:

$grandtotalAmount Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()
and you use this variable to check against some threshold value.

Hope this helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cybermaniak
Member
 
Total Posts:  31
Joined:  2011-11-30
 

Thanks exactly what i found on my search..  however i don’t know on how to interpret les than 2000 then show my pay_oxxo module..  that function is correct ??  if( $grandtotal == ‘< 2000’)

$grandtotal        =  Mage::getSingleton('checkout/cart')->getQuote()->collectTotals()->getGrandTotal(); 
 
   
 
        if( 
$grandtotal  == '< 2000'){
            
if($method->getCode() == 'pay_oxxo' ){
                $result
->isAvailable true;
            
}else{
                $result
->isAvailable false;

Thank you very much I really appreciate your help

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

Replace:

if( $grandtotal  == '< 2000'){
by
if( $grandtotal  <= ' 2000'){
 
Magento Community Magento Community
Magento Community
Magento Community
 
cybermaniak
Member
 
Total Posts:  31
Joined:  2011-11-30
 

Thanks any idea on why I’m getting this log

a:5:{i:0;s:68:"Mage registry key “_singleton/paymentfilter/observer” already exists";i:1;s:2172:"#0 /html/app/Mage.php(222): Mage::throwException(’Mage registry k...’)
#1 /html/app/Mage.php(476): Mage::register(’_singleton/paym...’, false)
#2 /html/app/code/core/Mage/Core/Model/App.php(1316): Mage::getSingleton(’paymentfilter/o...’)
#3 /html/app/Mage.php(447): Mage_Core_Model_App->dispatchEvent(’payment_method_...’, Array)

the module is loading fine on backend

my file under /app/etc/modules is like this

<config>
    <
modules>
        <
MagePsycho_Paymentfilter>
            <
active>true</active>
            <
codePool>local</codePool>
        </
MagePsycho_Paymentfilter>
    </
modules>
</
config>

the config file under html/app/code/local/MagePsycho/Paymentfilter/etc

<?xml version="1.0" encoding="utf-8"?>
<config>
 <global>
       <
modules>
             <
MagePsycho_Paymentfilter>
                  <
version>0.1.0</version>
             </
MagePsycho_Paymentfilter>
       </
modules>
    <
events>
        <
payment_method_is_active>
            <
observers>
                <
paymentfilter_payment_method_is_active>
                    <
type>singleton</type>
                    <class>
paymentfilter/observer</class>
                    <
method>paymentMethodIsActive</method>
                </
paymentfilter_payment_method_is_active>
             </
observers>
         </
payment_method_is_active>
    </
events>    
  </global>
</
config>
 
Magento Community Magento Community
Magento Community
Magento Community
 
cybermaniak
Member
 
Total Posts:  31
Joined:  2011-11-30
 

Uhm even changing the config.xml from Paymentfilter/etc to this..

<config>
  <global>
       <
events>
        <
payment_method_is_active>
            <
observers>
                <
paymentfilter_payment_method_is_active>
                    <
type>singleton</type>
                    <class>
paymentfilter/observer</class>
                    <
method>paymentMethodIsActive</method>
                </
paymentfilter_payment_method_is_active>
            </
observers>
        </
payment_method_is_active>
    </
events>    
  </global>
</
config>

Isn’t working..  I’m using CE 1.7.0.2

 
Magento Community Magento Community
Magento Community
Magento Community
 
cybermaniak
Member
 
Total Posts:  31
Joined:  2011-11-30
 

Ok now I manage to “fix” the config.xml for paymentfilter/etc and now it doesn’t give me the error, and is being loaded on backend even using the extension module lists. says

Name:  MagePsycho_Paymentfilter
Active: true
Version: 0.1.0
Path:  /app/code/local/MagePsycho/Paymentfilter
Path Exists:  yes
Found confix.xml?:  yes

Is this correct ??
[

<?xml version="1.0" encoding="utf-8"?>
<config>
   <
modules>
        <
MagePsycho_Paymentfilter>
            <
version>0.1.0</version>
        </
MagePsycho_Paymentfilter>
    </
modules>
    <global>
        <
models>
            <
paymentfilter>
                <class>
MagePsycho_Paymentfilter_Model</class>
            </
paymentfilter>
        </
models>
        <
events>
            <
payment_method_is_active>
                <
observers>
                    <
paymentfilter_payment_method_is_active>
                        <
type>singleton</type>
                        <class>
paymentfilter/observer</class>
                        <
method>paymentMethodIsActive</method>
                    </
paymentfilter_payment_method_is_active>
                </
observers>
              </
payment_method_is_active>
            </
events>
         </global>
</
config>

But hidding the method is not working..

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top