Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

payments by product/category


Guest

Recommended Posts

Anyone done a mod to display payment modules depending on product or catagory?

 

I am using authorizenet and cod modules, with the new checkout procedure. I want authorize net to display at checkout for all products, but cod not to display if products in certain categories are in the cart.

 

 

Any Ideas?

Link to comment
Share on other sites

Just noticed that all the products I want excluded have weight, so I guess I could read the weight from the session to see if totalweight>0.

 

Sound like the right approach? I'm very new to php.

Link to comment
Share on other sites

You could add an IF statement on the cod payment module based on weight.

 

if ($cart->show_weight()>0) {

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

}

 

Basically what this does is disable it only when weight is > 0 and allows it to show when weight is 0

Link to comment
Share on other sites

That's what I thought, but I get an error saying the $cart variable is undefined. Is their a specific place i should put it on the page?

 

By the way, Linda, I'm using your free payment contribution.

 

Here is the code from my cod.php file:

<?php

/*

 $Id: cod.php,v 1.2 2002/12/02 20:11:49 wilt Exp $



 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2002 osCommerce



 Released under the GNU General Public License

*/

 class cod {

   var $code, $title, $description, $enabled;



// class constructor

   function cod() {

     global $order;



     $this->code = 'cod';

     $this->title = MODULE_PAYMENT_COD_TEXT_TITLE;

     $this->description = MODULE_PAYMENT_COD_TEXT_DESCRIPTION;

  

// Added by Mike Davis 

if ($cart->show_weight()>0) { 

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

}

// End Added by Mike Davis



// BOF: WebMakers.com Added: Free Payments and Shipping

if ( tep_get_free_charger($this->code) ) {

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

}

// EOF: WebMakers.com Added: Free Payments and Shipping



     if ( ($this->enabled == true) && (MODULE_PAYMENT_COD_ZONE != '0') ) {

       $check_flag = false;

       $check_query = tep_db_query("select zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_COD_ZONE . "'");

       while ($check = tep_db_fetch_array($check_query)) {

         if ($check['zone_country_id'] == $order->billing['country']['id']) {

           $check_flag = true;

           break;

         }

       }



       if ($check_flag == false) {

         $this->enabled = false;

       }

     }

   }



// class methods

   function javascript_validation() {

     return false;

   }



   function selection() {

     return array('id' => $this->code,

                  'module' => $this->title);

   }



   function pre_confirmation_check() {

     return false;

   }



   function confirmation() {

     return false;

   }



   function process_button() {

     return false;

   }



   function before_process() {

     return false;

   }



   function after_process() {

     return false;

   }



   function get_error() {

     return false;

   }



   function check() {

     if (!isset($this->_check)) {

       $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_COD_STATUS'");

       $this->_check = tep_db_num_rows($check_query);

     }

     return $this->_check;

   }



   function install() {

     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Cash On Delivery Module', 'MODULE_PAYMENT_COD_STATUS', 'True', 'Do you want to accept Cash On Delevery payments?', '6', '1', 'tep_cfg_select_option(array('True', 'False'), ', now());");

     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_COD_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");

   }



   function remove() {

     $keys = '';

     $keys_array = $this->keys();

     for ($i=0; $i<sizeof($keys_array); $i++) {

       $keys .= "'" . $keys_array[$i] . "',";

     }

     $keys = substr($keys, 0, -1);



     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");

   }



   function keys() {

     return array('MODULE_PAYMENT_COD_STATUS', 'MODULE_PAYMENT_COD_ZONE');

   }

 }

?>

Link to comment
Share on other sites

The $cart variables are not available right there then, so ...

 

Add a function to general.php

 

function test_weight() {

 global $cart;

 return $cart->show_weight;

}

 

Then use in the cod.php

 

if (test_weight() > 0) {

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

}

 

See if that doesn't work better.

Link to comment
Share on other sites

I just noticed you have both my old code and the new code I gave you in the file.

 

You need one (1) test on the IF statement that surrounds the code:

 

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

 

If this module should show, then you want that test on the IF statement to allow the above code to processes normally.

 

If this module should not show, then you want the test on the IF statement to prevent the above code from processing, basically producing a False condition had it been processed, which means don't show it.

 

If you look in the function tep_get_free_charger you will see how it is testing the cart weight and total to decide based on module what should come back as true or false.

 

Same holds true on the tep_get_free_shipper function.

 

Hope this helps

Link to comment
Share on other sites

  • 7 months later...

Do you know an easy way how to do the same but then not with weight but with total amount?

So, if total order amount > 1000, hide the cod payment method.

 

Thanks,

 

Tom

Link to comment
Share on other sites

Do you know an easy way how to do the same but then not with weight but with total amount?

So, if total order amount > 1000, hide the cod payment method.

 

Thanks,

 

Tom

 

3 files to change:

 

/catalog/includes/modules/payments/cod.php

// WebMakers.com Added: Validate total for display

   if (verify_show_total()) {

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

   }

 

/catalog/includes/functions/general.php ... add this function to the bottom before the ?>

////

// WebMakers.com Added: test cart total and hide if over $1000

// Validate totals for payments

function verify_show_total() {

 global $cart;

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

     // show

     return true;

   } else {

     // hide

     return false;

   }

 }

 

/admin/includes/functions/general.php add this before the ?>

////

// WebMakers.com Added: Validate modules for Admin

function verify_show_total() {

 return true;

}

 

Set the 1000 to the highest value you will accept COD for.

 

Hope this helps ... :D

Link to comment
Share on other sites

Hi Linda,

 

First of all, thanks for your response, helping me with this issue.

 

I think I'm doing something wrong because the COD still shows up for payments during checkout (checkout_payment.php)

I've included the code at the end of the general.php files and added the cod.php code around line 56 (just above // disable the module if the order only contains virtual products)

 

// WebMakers.com Added: Validate total for display

 

if (verify_show_total()) {

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

}

 

// disable the module if the order only contains virtual products

if ($this->enabled == true) {

if ($order->content_type == 'virtual') {

$this->enabled = false;

}

}

}

function javascript_validation() {

return false;

}

.......

 

Do I have to place it somewhere else to have the right effect?

I look at the earlier discussion, but I don't understand all of it to solve this myself.

 

Regards,

 

Tom

Link to comment
Share on other sites

Hi,

 

I know what I did wrong; It has to be placed around line 24:

 

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

 

if (verify_show_total()) {

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

}

 

 

Linda, thank you very much for the solution.

 

regards,

 

Tom

Link to comment
Share on other sites

Hi,

 

I know what I did wrong; It has to be placed around line 24:

 

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

 

if (verify_show_total()) {  

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

   }  

 

Linda, thank you very much for the solution.

 

regards,

 

Tom

 

You are most welcome, Tom. I am glad this solution to your problem worked for you. :D

Link to comment
Share on other sites

Hi y'all

 

First a big thank you for Linda from everyone i guess. Almost every topic i read i see her name pop up :D

 

Hope you can help me too..

 

My problem is the same as above (if orderamount is >? 750 the zones module should not show up)

yep zones..In Holland we have an option to pay when product is delivered, how higher the weight how higher the amaount for this will be.

I don`t use the payment module at all for what we call in holland "rembours"(the above), i renamed this "rembours" and skip the payment module. As you know the zones module (shipping) is based on weight. everything from the above doesnt help me because, i can`t just change the weight cause that won`t have any effect on the price.

 

to makes things simpler: how can i change zones.php, so that it won`t show up when total orderamount is above ? 750,--?

 

tricky one ha :lol:

 

i sure hope you, or anyone else ofcourse, can help me with this, and sorry for my bad English, as you know now i`m from Holland... :P

Link to comment
Share on other sites

Hi Dyon,

 

Why don't you use the payment module COD (=Onder Rembours) in combination with the table rate shipping module with Table method set on weight ? Then you can use the "Payment type charge" to put an amout on the COD.

This is how I work and you can also use the solution on this page to make COD dissapear for amounts > 750 .

 

Regards,

 

Tom

Link to comment
Share on other sites

Hi Tom,

 

I already use table for another payment type (pay in advance based on weight) the weightprices are different so there is no way i can combine that. I don`t use the payment modules at all , ans i am i bit afraid to turn everyting around again, cause my shop is Live already. Isn`t there a way to use "IF" in zones??

 

I use 3 shipping (payment for me) Methods:

 

1. Pickup.php (people pay when they pick up product in store)

2. Table.php (people pay in advance, when orderamount is in, products is send, different weight/price then the next)

3. Zones.php "rembours"(people pay at the theur door at the moment product is delivered)

 

With the last one, the problem is that when the customer pays, untill the money is on my bankaccount, there are more then 3 weeks passed. So i have to pay (to wherever I get the products), and after 3 weeks i have my money back...from the customer. The company that delivers the products keeps my money on their bankaccount over 3 weeks before they send it to me.

This is why i don`t want it to be too much..

 

thanks

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 years later...

I'm using these instructions to build a flat rate or hazmat rate shipping method. I've taken all of my items that belong in hazmat to 1.00 in products --> products_weight, everything that isn't hazmat has a value of 0.00 here.

 

In my /include/modules/shipping/hazmat.php

if ($total_weight > 0) {
     $this->enabled = ((MODULE_SHIPPING_HAZMAT_STATUS == 'True') ? true : false);
}

 

In my /include/modules/shipping/flat.php

if ($total_weight == 0) {
     $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);
}

 

But only the flat rate is showing up no matter what. I got $total_weight from the /checkout_shipping.php module. $cart->show_weight() causes the page to not be displayed. I'm new to this so I may just need to use more parenthesis or something.

 

David

Link to comment
Share on other sites

Got it working. Hadn't enabled $cart as a global

    function flat() {
     global $order, $cart;

 

I'm using these instructions to build a flat rate or hazmat rate shipping method. I've taken all of my items that belong in hazmat to 1.00 in products --> products_weight, everything that isn't hazmat has a value of 0.00 here.

 

In my /include/modules/shipping/hazmat.php

if ($total_weight > 0) {
     $this->enabled = ((MODULE_SHIPPING_HAZMAT_STATUS == 'True') ? true : false);
}

 

In my /include/modules/shipping/flat.php

if ($total_weight == 0) {
     $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);
}

 

But only the flat rate is showing up no matter what. I got $total_weight from the /checkout_shipping.php module. $cart->show_weight() causes the page to not be displayed. I'm new to this so I may just need to use more parenthesis or something.

 

David

Link to comment
Share on other sites

Got it working. Hadn't enabled $cart as a global

    function flat() {
     global $order, $cart;

 

So this code works fine in the shopping cart. But in the admin none of my shipping methods show up.

 

  class flat {
   var $code, $title, $description, $icon, $enabled;

// class constructor
   function flat() {
     global $order, $cart;

     $this->code = 'flat';
     $this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE;
     $this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER;
     $this->icon = '';
     $this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS;
     if ($cart->show_weight()==0) {
       $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);

 

PHP Fatal error: Call to a member function on a non-object in includes/modules/shipping/flat.php on line 26, referer: https://domain.com/admin/modules.php?set=sh...p;module=hazmat

 

Line 26 is the line "if ($cart->show_weight()==0) {" above in the code box.

 

If I remove the () then it works in admin, but not in the shopping cart.

 

David

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...