Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

specific product to have specific payment option


frenchy128

Recommended Posts

Hello OSC Forums

 

I was unable to find the topic anywhere in the forums, and it was posted before I apologize and feel free to send me the link..

 

I have a OSC site running now for a small mom&pop flower shop here in town... They recently wrote a book, and wanted to offer it a a digital download thru there site. I've enabled the downloads, and all is good with the downloading aspect, but the payment type is an issue.

 

The user would like all ebook orders to have credit cards as the only payment option. Is there a contribution that will allow me to pick a specific payment type for a product on the site?

 

Thank you all for your help!

Frenchy

Link to comment
Share on other sites

What happens if the buyer purcashes both a download and a tangible in the same order?

 

If that's not a major issue, you could try making the payment methods "interactive" based on product id.

 

www.clubosc.com/interactive-modules-in-oscommerce.html will give you a start, and then use the in_cart part of the shopping cart class to determine if the given product_id is "in the cart" to enable os diable the module(s).

Link to comment
Share on other sites

What happens if the buyer purcashes both a download and a tangible in the same order?

 

If that's not a major issue, you could try making the payment methods "interactive" based on product id.

 

www.clubosc.com/interactive-modules-in-oscommerce.html will give you a start, and then use the in_cart part of the shopping cart class to determine if the given product_id is "in the cart" to enable os diable the module(s).

 

Thanks I'll give that a try in the next hour or so, and I'll post results.... Enjoy the beer donation.. :)

Link to comment
Share on other sites

What happens if the buyer purcashes both a download and a tangible in the same order?

 

If that's not a major issue, you could try making the payment methods "interactive" based on product id.

 

www.clubosc.com/interactive-modules-in-oscommerce.html will give you a start, and then use the in_cart part of the shopping cart class to determine if the given product_id is "in the cart" to enable os diable the module(s).

 

So I'm playing around with this, and I'm not sure if I interpreted the website properly.. To answer your question, at this point I'll accept the fact that, if the e-book is on the order, the whole order will be processed as CC only. I'm not picky.. :)

 

The product numbers I'd like to be restricted to CC only are 259 and 260.. I figured I'd start with one for now.. And I'll work with the COD module for now. Here's a copy of what I came up with, but it seems to block the payment module for all non-e-book products as well..

 

..in my cod.php

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

     if($products_id = 259) $this->enabled = false;

I did define the $products_id on the global line, but I'm not sure if it's required.. regardless with or without it, it still disables the module.

 

I'll keep poking at it, but I'll be checking back if you have any hints for me..

Link to comment
Share on other sites

Add $cart to the global scope, and then do this in each of your payment modules OTHER THAN your Credit Card module (as you want to turn off all payment modules other than CC):

 

if ( ($cart->in_cart(259)) || ($cart->in_cart(260)) ) $this->enabled = false;

 

Completely untested, but should work (in theory!!).

 

So, EXAMPLE, part of cod.php would change from this :

 

function update_status() {
  global $order;

  if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_COD_ZONE > 0) ) {
	$check_flag = false;
	$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_COD_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
	while ($check = tep_db_fetch_array($check_query)) {
	  if ($check['zone_id'] < 1) {
		$check_flag = true;
		break;
	  } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
		$check_flag = true;
		break;
	  }
	}

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


  }

// disable the module if the order only contains virtual products
  if ($this->enabled == true) {
	if ($order->content_type == 'virtual') {
	  $this->enabled = false;
	}
  }
}

 

To this:

 

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

  if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_COD_ZONE > 0) ) {
	$check_flag = false;
	$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_COD_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
	while ($check = tep_db_fetch_array($check_query)) {
	  if ($check['zone_id'] < 1) {
		$check_flag = true;
		break;
	  } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
		$check_flag = true;
		break;
	  }
	}

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


  }

  if ( ($cart->in_cart(259)) || ($cart->in_cart(259)) ) $this->enabled = false;

// disable the module if the order only contains virtual products
  if ($this->enabled == true) {
	if ($order->content_type == 'virtual') {
	  $this->enabled = false;
	}
  }
}

Link to comment
Share on other sites

you could also probably have done something with the content type, as I *think* (though cannot recall for certain) that there are three type of content;

 

virtual

physical

mixed

 

so you could do the enable/disable based on that. Possibly, like I say I can't remember exactly and cannot be arsed to check ;)

Link to comment
Share on other sites

you could also probably have done something with the content type, as I *think* (though cannot recall for certain) that there are three type of content;

 

virtual

physical

mixed

 

so you could do the enable/disable based on that. Possibly, like I say I can't remember exactly and cannot be arsed to check ;)

 

It's been a few days of trying and I still can't get this to work.. Do you have any information on how I could categorize my products to have physical and virtual products? I couldn't find any manual/document that has information on this.

Link to comment
Share on other sites

Add $cart to the global scope, and then do this in each of your payment modules OTHER THAN your Credit Card module (as you want to turn off all payment modules other than CC):

 

<?php
/*
 $Id: institutional_purchase.php,v 1.0 2005/08/11 17:23:08 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2003 osCommerce

 Released under the GNU General Public License

 Nicpon.NET Copyright © 2005 Michal Szapiel
*/
 class institutional_purchase {
   var $code, $title, $description, $enabled;
// class constructor
   function institutional_purchase() {
	global $order;
     $this->code = 'institutional_purchase';
     $this->title = MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_TITLE;
     $this->description = MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_DESCRIPTION;
     $this->email_footer = MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_EMAIL_FOOTER;
     $this->sort_order = MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_SORT_ORDER;
  $this->enabled = (( MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_STATUS == 'True') ? true : false);

  }
// class methods
   function selection() {
     global $order, $cart;
     $selection = array('id' => $this->code,
                        'module' => $this->title,
                        'fields' => array(array('title' => MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_ORDER_NUMBER,
                                                'field' => tep_draw_input_field('ip_order_no')),
                                          array('title' => MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_REQUESTED_BY,
                                                'field' => tep_draw_input_field('ip_requested_by')),
                                          array('title' => MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_CONTACT_PERSON,
                                                'field' => tep_draw_input_field('ip_contact_person'))));
     return $selection;
     if ( ($cart->in_cart(259)) || ($cart->in_cart(260)) ) $this->enabled = false;
   }
function javascript_validation() {
    $js = '  if (payment_value == "' . $this->code . '") {' . "\n" .
           '    var ip_order_no = document.checkout_payment.ip_order_no.value;' . "\n" .
           '    var ip_requested_by = document.checkout_payment.ip_requested_by.value;' . "\n" .
		'	 var ip_contact_person = document.checkout_payment.ip_contact_person.value;' . "\n" .
           '    if (ip_order_no == "") {' . "\n" .
           '      error_message = error_message + "' . MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_JS_ORDER_NUMBER . '";' . "\n" .'      error = 1;' . "\n" .
           '    }' . "\n" .
           '    else if (ip_requested_by == "" ) {' . "\n" .
           '      error_message = error_message + "' . MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_JS_REQUESTED_BY . '";' . "\n" .'      error = 1;' . "\n" .
           '    }' . "\n" .
		'	else if (ip_contact_person == "" ) {' . "\n" .
           '      error_message = error_message + "' . MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_JS_CONTACT_PERSON . '";' . "\n" .'      error = 1;' . "\n" .
           '    }' . "\n" .	
           '  }' . "\n";
     return $js;
   }
function pre_confirmation_check() {
	global $HTTP_POST_VARS;
	if(($HTTP_POST_VARS['ip_order_no'])){
	 $error = TEXT_ghhCCVAL_ERROR_INVALID_DATE;
		 }
   }
function confirmation() {
	global $HTTP_POST_VARS;
     $confirmation = array('title' => $this->title ,
                           'fields' => array(array('title' => MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_ORDER_NUMBER,
                                                'field' => $HTTP_POST_VARS['ip_order_no']),
                                          array('title' => MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_REQUESTED_BY,
                                                'field' => $HTTP_POST_VARS['ip_requested_by']),
                                          array('title' => MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_CONTACT_PERSON,
                                                'field' => $HTTP_POST_VARS['ip_contact_person'])));
     return $confirmation;
}
   function process_button() {
       global $HTTP_POST_VARS;
     $process_button_string = tep_draw_hidden_field('ip_order_no', $HTTP_POST_VARS['ip_order_no']) .
                              tep_draw_hidden_field('ip_requested_by', $HTTP_POST_VARS['ip_requested_by']) .
						   tep_draw_hidden_field('ip_contact_person', $HTTP_POST_VARS['ip_contact_person']);
     return $process_button_string;
   }
   function before_process() {
    global $HTTP_POST_VARS, $order;
 $order ->info['ip_order_no'] = $HTTP_POST_VARS['ip_order_no'];
 $order ->info['ip_requested_by'] = $HTTP_POST_VARS['ip_requested_by'];
 $order ->info['ip_contact_person'] = $HTTP_POST_VARS['ip_contact_person'];

 }
   function after_process() {
     return false;
   }
   function output_error() {
     global $HTTP_GET_VARS;
     $error = array('title' => MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_TEXT_ERROR,
                    'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));
     return $error;
   }
   function check() {
     if (!isset($this->check)) {
       $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_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 Institutional Purchase Payment', 'MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_STATUS', 'True', 'Do you want to accept Institutional Purchase Order payments?', '6', '0', '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, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0' , now())");
    }
   function remove() {
     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
     }
   function keys() {
     $keys = array('MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_STATUS','MODULE_PAYMENT_INSTITUTIONAL_PURCHASE_SORT_ORDER');
     return $keys;
   }
 }
?>

 

For this module, there is no function_update so I'm lost.. Any help?

Link to comment
Share on other sites

  • 1 month later...
Add $cart to the global scope, and then do this in each of your payment modules OTHER THAN your Credit Card module (as you want to turn off all payment modules other than CC):

 

if ( ($cart->in_cart(259)) || ($cart->in_cart(260)) ) $this->enabled = false;

 

Completely untested, but should work (in theory!!).

 

So, EXAMPLE, part of cod.php would change from this :

 

I tried this in order to disable the payment option "invoice" if product id "119" is in shopping cart.

 

In includes/modules/payment/invoice.php I have:

 

  class invoice {
var $code, $title, $description, $enabled;

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

  $this->code = 'invoice';
  $this->title = MODULE_PAYMENT_INVOICE_TEXT_TITLE;
  $this->description = MODULE_PAYMENT_INVOICE_TEXT_DESCRIPTION;
  $this->sort_order = MODULE_PAYMENT_INVOICE_SORT_ORDER;
  $this->enabled = ((MODULE_PAYMENT_INVOICE_STATUS == 'True') ? true : false);	  
  // do not show invoice payment option if product id "119" in cart
  if (($cart->in_cart(119)) $this->enabled = false;	 
  if ((int)MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID > 0) {
	$this->order_status = MODULE_PAYMENT_INVOICE_ORDER_STATUS_ID;
  }

  if (is_object($order)) $this->update_status();
}

 

Unfortunately, this leads to the following error:

PHP Fatal error: Call to a member function in_cart() on a non-object in /www/htdocs/eshop/includes/mne 28, referer: http://mydomain/eshop/checkout_shipping.ph...ahccuif6ovlqmo1

 

Any idea what I did wrong?

Thanks in advance!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...