Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Can I restrict certain payment methods for certain products?

Can I restrict certain payment methods for certain products?

Locked

Views: 17,250

Results 1 to 20 of 28
This thread is locked. New replies are disabled.
13 Feb 2009, 6:58 PM
#1
one_tall_man avatar

one_tall_man

Zen Follower

Join Date:
Feb 2009
Posts:
125
Plugin Contributions:
0

Can I restrict certain payment methods for certain products?

For example, if I sell some products prohibited by Paypal, can I specify that Paypal cannot be selected as a method for those, but can for the rest of products?

14 Feb 2009, 6:04 AM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

You could test if a Product is in the shopping cart and if so, disable the payment module by controlling the $this->enabled ...

When set to false, the module will not show ...

14 Feb 2009, 9:50 PM
#3
one_tall_man avatar

one_tall_man

Zen Follower

Join Date:
Feb 2009
Posts:
125
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

That went over my head.

15 Feb 2009, 4:14 AM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

Let's say you wanted to make the Check/Money Order payment module moneyorder.php hide or not show when products_id 27 was in the cart ...

Currently, there is a line for the $this->enabled that reads:

      $this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'True') ? true : false);

Further down in the code, in the function update_status you will also see the $this->enabled referenced ...

You could check to see if the products_id 12 was in the shopping cart and if so, make this false, so even if the payment module is installed, it will hide or be disabled when the product is there ...

There is a function in the shopping_cart class to test values on what's in the cart ...

   * $check_what is the fieldname example: 'products_is_free'
   * $check_value is the value being tested for - default is 1
   * Syntax: $_SESSION['cart']->in_cart_check('product_is_free','1');
   *
   * @param string product field to check
   * @param mixed value to check for
   * @return integer number of items matching restraint
   */
  function in_cart_check($check_what, $check_value='1') {

So, using the following:

$_SESSION['cart']->in_cart_check('products_id','12')

This can be done with the following code that changes the function update_status to read:

// class methods
    function update_status() {
      global $order, $db;

      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_MONEYORDER_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_MONEYORDER_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
            $check_flag = true;
            break;
          }
          $check->MoveNext();
        }

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }

// disable if products_id 12 is in the cart
      if ($_SESSION['cart']->in_cart_check('products_id','12') > 0) {
          $this->enabled = false;
      }

    }
16 Feb 2009, 12:05 AM
#5
one_tall_man avatar

one_tall_man

Zen Follower

Join Date:
Feb 2009
Posts:
125
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

Oh, you meant altering the source code! Thanks, but no, thanks.

16 Feb 2009, 12:15 AM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

Customizations requires custom code ...

If you are not keen on coding you could always post for help in the Commercial Help Wanted ... :smile:

5 Feb 2010, 11:16 PM
#7
gamestuff avatar

gamestuff

New Zenner

Join Date:
Jun 2009
Posts:
12
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

I hate to bump an old thread but this one closely relates to what i want. I have done the following suggested above and its working great, but i tried switching to 'categories_id' to limit the payment on an entire category in place of 'products_id'.

When going through checkout with this switched i get:

1054 Unknown column 'categories_id' in 'field list'
in:
[select categories_id as check_it from products where products_id='286' limit 1]

not quite sure what this means so im hoping its a simple fix, otherwise i will be pumping in alot of product id's

thanks in advance!

6 Feb 2010, 6:25 AM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

The Master Categories ID field in the products table is called:
master_categories_id

This is the Product's categories_id ... if using Linked Product, then this will be the "main categories_id" or the "master categories_id" or the Category that "owns" the Product ...

6 Feb 2010, 9:49 AM
#9
gamestuff avatar

gamestuff

New Zenner

Join Date:
Jun 2009
Posts:
12
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

Brilliant!!! Thank you!!

Works like a charm!

6 Feb 2010, 1:45 PM
#10
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

Thanks for the update that you were just using the wrong field name in your select statement ... fussy the way the code works with MySQL ... :cool:

7 Feb 2010, 7:52 PM
#11
gamestuff avatar

gamestuff

New Zenner

Join Date:
Jun 2009
Posts:
12
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

Hmm seems my troubles arent quite over yet :P

When i try to edit an order now, i am getting the following error:

Fatal error: Call to a member function in_cart_check() on a non-object in /includes/modules/payment/paypalwpp.php on line 259

This is the line where i added my code:

		// disable if category 6 items are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','6') > 0) {
          $this->enabled = false; 
      }		

Basically i am disabling paypal when certain items are in the cart. Everything seems to be working with the expection of trying to update said orders afterwords.

7 Feb 2010, 8:00 PM
#12
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

See if surrounding you IF statement with an IF using:

  if (IS_ADMIN_FLAG == false) {
// your IF HERE
  }

doesn't help as the Admin doesn't know about the cart ...

7 Feb 2010, 9:29 PM
#13
gamestuff avatar

gamestuff

New Zenner

Join Date:
Jun 2009
Posts:
12
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

I dont think so, this is what i have right now:

Works fine except for updating orders through the admin panel. Porbably a better way out there of handling mutliple categories but this works so far.

      if (!$check_flag) {
        $this->enabled = false;
      }

      // module cannot be used for purchase > $10,000 USD
      $order_amount = $this->calc_order_amount($order->info['total'], 'USD');
      if ($order_amount > 10000) $this->enabled = false;
    }
		// disable if *** are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','6') > 0) {
          $this->enabled = false; 
      }		
		// disable if *** are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','82') > 0) {
          $this->enabled = false; 
      }
		// disable if *** are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','24') > 0) {
          $this->enabled = false; 
      }
		// disable if *** are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','9') > 0) {
          $this->enabled = false; 
      }
  }

I'm stumped right now.. :(

7 Feb 2010, 11:37 PM
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

Try using:

  if (IS_ADMIN_FLAG == false) {
		// disable if *** are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','6') > 0) {
          $this->enabled = false; 
      }		
		// disable if *** are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','82') > 0) {
          $this->enabled = false; 
      }
		// disable if *** are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','24') > 0) {
          $this->enabled = false; 
      }
		// disable if *** are in the cart
      if ($_SESSION['cart']->in_cart_check('master_categories_id','9') > 0) {
          $this->enabled = false; 
      }
    }
8 Feb 2010, 9:02 PM
#15
gamestuff avatar

gamestuff

New Zenner

Join Date:
Jun 2009
Posts:
12
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

Ajeh:

Try using:

if (IS_ADMIN_FLAG == false) {
// disable if *** are in the cart
if ($_SESSION['cart']->in_cart_check('master_categories_id','6') > 0) {
$this->enabled = false;
}
// disable if *** are in the cart
if ($_SESSION['cart']->in_cart_check('master_categories_id','82') > 0) {
$this->enabled = false;
}
// disable if *** are in the cart
if ($_SESSION['cart']->in_cart_check('master_categories_id','24') > 0) {
$this->enabled = false;
}
// disable if *** are in the cart
if ($_SESSION['cart']->in_cart_check('master_categories_id','9') > 0) {
$this->enabled = false;
}
}


that did the trick, Can now update orders and the script still functions when customers checkout! great!
8 Feb 2010, 11:43 PM
#16
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

Thanks for the update that the customized module was able to run in both the Catalog and the Admin when you added the IS_ADMIN_FLAG around the conditions for the Catalog that were causing errors in the Admin ...

17 Feb 2011, 4:12 AM
#17
dw08gm avatar

dw08gm

Totally Zenned

Join Date:
Sep 2008
Location:
DownUnder, overlooking South Pole.
Posts:
1,017
Plugin Contributions:
2

Re: Can I restrict certain payment methods for certain products?

OK I have managed to disable Paypal on the payment method page using the following coding in \includes\modules\payment\paypalwpp.php at line 216:

// disable for categories in cart
    if (IS_ADMIN_FLAG == false) {
      if (($_SESSION['cart']->in_cart_check('master_categories_id','4') > 0) ||
          ($_SESSION['cart']->in_cart_check('master_categories_id','5') > 0) ||
          ($_SESSION['cart']->in_cart_check('master_categories_id','6') > 0)  {
          $this->enabled = false;
      }
    }

// module cannot be used for purchase > $10,000 USD OR > $500 AUD
    $order_amount = $this->calc_order_amount($order->info['total'], 'AUD');
    if ($order_amount > 500) $this->enabled = false;
    if ($order->info['total'] == 0) $this->enabled = false;
    }
  }

and the following coding in includes\modules\payment\paypal\tpl_ec_button.php from line 46

// disable for categories in cart
  if (IS_ADMIN_FLAG == false) {
    if (($_SESSION['cart']->in_cart_check('master_categories_id','4') > 0) ||
        ($_SESSION['cart']->in_cart_check('master_categories_id','5') > 0) ||
        ($_SESSION['cart']->in_cart_check('master_categories_id','6') > 0) {
      $paypalec_enabled = false;
    }
  }

  // PayPal module cannot be used for purchase > $10,000 USD or 5500 GBP or $500 AUD
//  if ( ($_SESSION['currency'] == 'USD' && $currencies->value($_SESSION['cart']->total, true, 'USD') > 10000)
//    || ($_SESSION['currency'] == 'GBP' && $currencies->value($_SESSION['cart']->total, true, 'GBP') > 5500) ) {
  if ( ($_SESSION['currency'] == 'AUD' && $currencies->value($_SESSION['cart']->total, true, 'AUD') > 500) ) {
    $paypalec_enabled = false;
  }
}

However, I now need to disable paypal express checkout in \includes\templates\MyTemplate\templates\tpl_login_default.php lines 24-31 viz

<!-- ** BEGIN PAYPAL EXPRESS CHECKOUT ** -->
<?php if ($ec_button_enabled) { ?>
<div class="information"><?php echo TEXT_NEW_CUSTOMER_INTRODUCTION_SPLIT; ?></div>
<div class="center"><?php require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/tpl_ec_button.php'); ?></div>
<hr />
<?php echo TEXT_NEW_CUSTOMER_POST_INTRODUCTION_DIVIDER; ?>
<?php } ?>
<!-- // ** END PAYPAL EXPRESS CHECKOUT **  -->

I am thinking to replace this line

<?php if ($ec_button_enabled) { ?>

with something like

<?php if ($ec_button_enabled && $paypalec_enabled = false) { ?>

and have tried a few other variations, but while I can get the paypal ec_button to disappear, the associated text and <hr/> remain.

eg TEXT_NEW_CUSTOMER_INTRODUCTION_SPLIT

So the question is: "What needs to be done?"

Thanks in advance.

5 Apr 2011, 1:48 PM
#18
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

I wonder if there's a way to adapt the code in this thread to suit my needs? I need to hide a payment option from the customers based on their cart value, not on the product ID. I need to hide the Nochex payment module when their cart reaches a certain amount.

At the moment, we're using Nochex as our card payment gateway, but they have a set limit on the maximum payment amount in any one transaction. At the moment it's only £420.00 which is embarrassing when a customer tries to pay by card and their cart is over this amount and they get a message telling them that their payment exceeds our maximum receive limit.

Google Checkout doesn't have this problem and as far as I can see and neither does PayPal it seems. So, I'm just curious if there's a way to disable the nochex module when the cart value exceeds £420.00? There's nothing in the admin control, so maybe some PHP treaking?

Looking at the code in this thread I am in way over my head. I can see that I need to add a line to /includes/modules/payment/nochex_apc.php........ but my PHP is pretty limited and I'm wondering if any of the guru's have a spare ten minutes for a cuppa coffee??

5 Apr 2011, 4:57 PM
#19
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Can I restrict certain payment methods for certain products?

I do not use this module, but you if this were the Check/Money Order I would add the code:

      $this->enabled = ((MODULE_PAYMENT_MONEYORDER_STATUS == 'True') ? true : false);

// bof: disable based on Order Amount
// use $order->info['subtotal'] or $order->info['subtotal']
      if (!IS_ADMIN_FLAG && $order->info['subtotal'] > 420.00) {
        $this->enabled = false;
      }
//echo 'I SEE ' . 'Subtotal: ' . $order->info['subtotal'] . ' Total: ' . $order->info['total'] . '<br>';
// eof: disable based on Order Amount

Just pick if you want this based on Total or Subtotal ...

5 Apr 2011, 5:13 PM
#20
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Can I restrict certain payment methods for certain products?

Perfect!!

I just added your snippet of code below:

$this->enabled = ((MODULE_PAYMENT_NOCHEX_STATUS == 'True') ? true : false);

Works like a charm!!

$this->enabled = ((MODULE_PAYMENT_NOCHEX_STATUS == 'True') ? true : false);
// bof: disable based on Order Amount
// use $order->info['subtotal'] or $order->info['subtotal']
if (!IS_ADMIN_FLAG && $order->info['subtotal'] > 420.00) {
$this->enabled = false;
}
//echo 'I SEE ' . 'Subtotal: ' . $order->info['subtotal'] . ' Total: ' . $order->info['total'] . '<br>';
// eof: disable based on Order Amount