Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Define Payment type per product


Guest

Recommended Posts

I have been looking through the forums but couldnt find anything on this.

 

I have two products in my store which I only want to be paid for using PayPal. The rest can be paid via authorise.net, money order and paypal.

 

Is there a way to define a specific payment type for certain products?

I'll need this option to be like an "if" statement.

 

Eg: if product 1 or 2 then only show PayPal as payment option. Else show all.

 

Can this be done?

 

Thanks

Link to comment
Share on other sites

what if 'they' put these produkts 1 & 2 in between a 'normal' online order,

did you think about that.

 

There is a MOD for using different paysystems for 1 order but i cant recall the name of that one :(

Robert

 

We all need to learn it once, how hard it may seem when you look at it, also you will master it someday ;)

Link to comment
Share on other sites

if they put these products between a normal order then only paypal is shown. I had already thought about this.

 

Let me rephrase my "if" statement

 

Eg: IF either product 1 or 2 exist in an order then only show paypal, ELSE show all

 

Robert, If you think of the name of that MOD please let me know

 

Thanks

Craig

Link to comment
Share on other sites

You write a function to test if either of the two products exist in the cart.

 

Then, on each of the payment modules you surround the $this->enabled line with the funciton in an if statement that returns true if the products are not in there and false if the products are in there.

 

On the paypal modules you write it the opposite way if you do not want it to show unless the products are in there ... or if you always want paypal then do not include the function

 

This will make the payment modules *hide* when the products are in the cart and show if the products are not in the cart.

Link to comment
Share on other sites

lol ... oh, I could ... but you'd lose half the fun, eh?

 

Actually, you can catch some samples of how this can be done in the Free Shipping and Payment Modules v5.0

 

I think there is a copy in the contributions as well as on my site.

 

NOTE: The function used in the modules is for a different test, but should give you an idea of what to do here.

 

NOTE: The shipping and payment modules in FSP v5.0 are OLDuse them

 

Let me know if you run into problems.

Link to comment
Share on other sites

Linda,

 

I have had a look at the free shipping and payments module but couldnt figure out what i was looking for.

 

Can i have some help... please?

 

Thanks

Craig

Link to comment
Share on other sites

Let's say you wanted to only accept Check or Money Order when the order was less than or equal to $1000

 

Edit /includes/modules/payment/moneyorder.php and find the line:

 

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

 

When this line evaluates to true, it means you have turned on the module in the Admin.

 

You can also use this to disable the module for other reasons, ie the order is great than $1000

 

First, you need to know how much is the order, this is obtain with $cart->show_total()

 

But to access the $cart->show_total() you need to make the $cart values available to this module.

 

So it would be edited to read:

 

// class constructor

   function moneyorder() {

     global $order, $cart;



     $this->code = 'moneyorder';

     $this->title = MODULE_PAYMENT_MONEYORDER_TEXT_TITLE;

     $this->description = MODULE_PAYMENT_MONEYORDER_TEXT_DESCRIPTION;

     $this->sort_order = MODULE_PAYMENT_MONEYORDER_SORT_ORDER;

if ($cart->show_total() <= 1000) {

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

}

 

If the IF statement evaluates as true, then the $this->enable will evaluate to true. If the IF statement evaluates to false, then the $this->enabled will evaluate to false as well, as if it was not turned on in the Admin ... so the moneyorders.php would not show on orders > $1000

 

You can either code the IF statement like I did here, or create a function that performs various evaluations of the cart and based on what you are checking for, would return a true or false.

 

I use a function as I can check the cart for all of the payment modules in one place, then decide which should show, be true, or not show, be false.

 

You can do the same thing on the shipping modules.

 

I use two functions one for shipping and one for payments as the conditions will be different for each one.

 

But the bottom line is, if the IF statement is true, then the module will show in the checkout and if the IF statement is false then it will hide.

Link to comment
Share on other sites

To test if a products_id is in the cart, say I want to know if products_id 64 is in the cart

 

function products_in_the_cart($test_product_id) {

 global $cart;

 if ($cart->in_cart($test_product_id) {

   return true;

 } else {

   return false;

 }

}

 

 

$my_products_id=64;

if (products_in_the_cart($my_products_id) {

 return true;

} else {

  return false;

}

 

Now using $my_products_id=64 may be a little limiting if you have more than one product to check, so you can either use a case statement for the various products_id numbers you need to test for, or you could add a field to the products table and evaluate that should the product be in the cart.

Link to comment
Share on other sites

Here is a sample of settings and functions using the cc.php payment module for the example:

 

In the catalog, add this function:

 

function tep_check_payment_modules() {

 global $cart;

  switch (true){ 

       case $cart->in_cart(547): 

       return false;

       break; 

       case $cart->in_cart(548): 

       return false;

       break; 

       case $cart->in_cart(549): 

       return false;

       break; 

       default: 

       return true;

       }

}

 

 

In the Admin add this function but with this code:

 

function tep_check_payment_modules() {

 return true;

}

 

In the module surround the $this->enable with:

 

if (tep_check_payment_modules()) {

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

}

Link to comment
Share on other sites

The functions get added to /catalog/includes/functions/general.php and and /admin/includes/functions/general.php

 

Then, in each payment module, you use the IF statement to surrount that payment modules $this->enabled = blah, blah

 

The functions have to be in both the Catalog to test should the module show for the current cart, and in the Admin so the modules always show.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...