2

Is there a way to set a "Maximum Order Total" for PayPal, similarly to the one you can set on other payment methods (without editing core files)?

Edit: Here is the solution if anyone else is wondering how to do this.

I manned up and made a small module for this, following a tutorial and grabbing a few code snippets from different threads on here. This Module will hide the PayPal option if the cart total is above 5000 (Currency).

1. First create "app/etc/modules/PPlimit_Module.xml" with this content:

<?xml version="1.0"?>
<config>
    <modules>
        <PPlimit_Module>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Payment/>
            </depends>
        </PPlimit_Module>
    </modules>
</config>

2. Create "app/code/local/PPlimit/Module/etc/config.xml" containing:

<?xml version="1.0"?>
<config>
<modules>
    <PPlimit_Module>
        <version>0.0.1</version>
    </PPlimit_Module>
</modules>

<global>
    <models>
        <PPlimit_Module>
            <class>PPlimit_Module_Model</class>
        </PPlimit_Module>
    </models>
    <events>
        <payment_method_is_active>
            <observers>
                <pplimit_module>
                    <type>singleton</type>
                    <class>PPlimit_Module/Observer</class>
                    <method>paymentMethodIsActive</method>
                </pplimit_module>
            </observers>
        </payment_method_is_active>
    </events>
</global>

</config>

3. Create "app/code/local/PPlimit/Module/Model/Observer.php" with this code:

 <?php

class PPlimit_Module_Model_Observer
{
    public function paymentMethodIsActive($observer)
    {
        $instance = $observer->getMethodInstance();
        $result = $observer->getResult();


        if ($instance->getCode() == "paypal_express" || $instance->getCode() =="paypal_standard") {         //Payment Method

        $total = $observer->getQuote()->getGrandTotal();

            if ($total<=5000) {                                 //Payment Limit
                $result->isAvailable = true;
            } else {
                $result->isAvailable = false;
            }
        }
    }

  }

?>

That's it, tell me if you find a bug!

2 Answers 2

1

What you need to do is create an extension that listens to an event before the sale is complete and check whether the order total meets your requirement for Paypal orders. There are tutorials on how to do these things in details, but here are the general steps.

  1. Set up an extension.
  2. Create an observer that listens to sales_order_place_before.
  3. In this observer, you'll have the order object available. From the order object, you can get the payment method code with something like $order->getPayment()->getMethod().
  4. Check the method string amd determine if it's Paypal. If it is, check the order total ($order->getGrandTotal()).
  5. If the grand total exceeds the maximum, throw an exception of some sort (throw new Exception('Order amount is too much...').
  6. When this exception is thrown, you'll get a popup message at checkout with this message, and the order will not go through.

You can hardcode the conditions, or you can create a system configuration interface for the admin to set up conditions for specific payment methods. Again, there are many tutorials out there to do this.

8
  • Thought as much. How "bad" would it be, if I hid the option with a JavaScript snippet if the total order amount exceeds a limit?
    – Aardi
    Commented Mar 16, 2016 at 15:50
  • 1
    Option to place the order? I think this will be "bad" in a sense that it's not a solution that will prevent me from placing the order, if I knew about the Javascript. It would be a superficial solution, but I suppose it will work most of the time.
    – laketuna
    Commented Mar 16, 2016 at 15:53
  • I'll do that as a workaround until I have the time and knowledge to build the extension, thanks!
    – Aardi
    Commented Mar 16, 2016 at 15:56
  • Do you have your Magento code base under source control with Git?
    – laketuna
    Commented Mar 16, 2016 at 16:45
  • No, seems like a good idea though.
    – Aardi
    Commented Mar 17, 2016 at 6:49
1

The module Aardi created works for me if I change line 13 in Observer.php with

$total = Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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