Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Why can't I get this value out of the database?


gtilflm

Recommended Posts

Hello. I'm using the following addon: http://addons.oscommerce.com/info/5461

 

Basically, it let's you charge an extra fee on certain products. I would like it to not display Extra Fee: $0.00 if there's no extra fee. So, I had the idea of setting the enabled status to false if the extra fee value was 0. The relevant code is...

 

// Next two lines added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010.
 $extra_charge_query = tep_db_query("select products_extra_charge from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");
 $extra_charge_query_value = mysql_fetch_array($extra_charge_query);


 class ot_extra_charge {
   var $code, $title, $description, $icon, $enabled, $output;

   function ot_extra_charge() {

     $this->code = 'ot_extra_charge';
     $this->title = MODULE_ORDER_TOTAL_EXTRA_CHARGE_TEXT_TITLE;
     $this->description = MODULE_ORDER_TOTAL_EXTRA_CHARGE_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_ORDER_TOTAL_EXTRA_CHARGE_SORT_ORDER;
     $this->icon = '';

  // Next three lines added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010. 
  if ($extra_charge_query_value == 0.0000) {
  	  $this->enabled = false;
  } else {

  	  $this->enabled = ((MODULE_ORDER_TOTAL_EXTRA_CHARGE_STATUS == 'true') ? true : false);
// Next line added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010. 
   }
     $this->output = array();
   }


 

 

It's not working and is always returning false. I tried doing a test of the mysql code I'm using and I can't even echo $extra_charge_query_value.

 

Any ideas on where I've gone wrong?

Link to comment
Share on other sites

Several errors that I see:

1. You are declaring a class, then trying to check a value that is declared outside the class. You need to move your query inside the class.

 

2. You are trying to check $extra_charge_query_value (which is an array) as a float. Change that to $extra_charge_query_value['products_extra_charge'} to check the value.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Jim,

 

Thanks for the reply. I applied the changes and currently have....

 



 class ot_extra_charge {
   var $code, $title, $description, $icon, $enabled, $output;

   function ot_extra_charge() {

     $this->code = 'ot_extra_charge';
     $this->title = MODULE_ORDER_TOTAL_EXTRA_CHARGE_TEXT_TITLE;
     $this->description = MODULE_ORDER_TOTAL_EXTRA_CHARGE_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_ORDER_TOTAL_EXTRA_CHARGE_SORT_ORDER;
     $this->icon = '';


// Next two lines added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010.
 $extra_charge_query = tep_db_query("select products_extra_charge from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
 $extra_charge_query_value = mysql_fetch_array($extra_charge_query);

  // Next three lines added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010. 
  if ($extra_charge_query_value['products_extra_charge'] == 0.0000) {
  	  $this->enabled = false;
  } else {

  	  $this->enabled = ((MODULE_ORDER_TOTAL_EXTRA_CHARGE_STATUS == 'true') ? true : false);
// Next line added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010. 
   }
     $this->output = array();
   }

 

 

 

 

It's still not working. Also, I tried the echo test again by placing the following in checkout_payment...

 

 $extra_charge_query = tep_db_query("select products_extra_charge from " . TABLE_PRODUCTS . " where products_id = '" . tep_db_input($products_id) . "'");
 $extra_charge_query_value = mysql_fetch_array($extra_charge_query);

 echo $extra_charge_query_value['products_extra_charge'];

 

and I'm not getting anything returned.

 

 

Could the problem be with tep_db_input($products_id)?

 

Thanks for any more ideas.

Link to comment
Share on other sites

The class has to be able to see the original variable or it can't use it. You can try changing this line

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

to

 var $code, $title, $description, $icon, $enabled, $output, $products_id;

If $products_id exists, that should work. Otherwise, you will have to figure out how to let the class know of it.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

I did that and it's still a no go. The current code is....

 


 class ot_extra_charge {
   var $code, $title, $description, $icon, $enabled, $output, $products_id;

   function ot_extra_charge() {

     $this->code = 'ot_extra_charge';
     $this->title = MODULE_ORDER_TOTAL_EXTRA_CHARGE_TEXT_TITLE;
     $this->description = MODULE_ORDER_TOTAL_EXTRA_CHARGE_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_ORDER_TOTAL_EXTRA_CHARGE_SORT_ORDER;
     $this->icon = '';


// Next two lines added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010.
 $extra_charge_query = tep_db_query("select products_extra_charge from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");
 $extra_charge_query_value = mysql_fetch_array($extra_charge_query);

  // Next three lines added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010. 
  if ($extra_charge_query_value['products_extra_charge'] == 0.0000) {
  	  $this->enabled = false;
  } else {

  	  $this->enabled = ((MODULE_ORDER_TOTAL_EXTRA_CHARGE_STATUS == 'true') ? true : false);
// Next line added by John to see if the extra charge value is 0.  If it is, then set the extra charge order total module to false.  if it does not = 0, then check to see if the admin setting has it set to true or false.  Not working as of June 14, 2010. 
   }
     $this->output = array();
   }

 

 

I've also tried putting "global products_id;" in there and it's still not happening.

 

Does anyone else have other thoughts?

Link to comment
Share on other sites

Actually, I think I got it working. In the order total module I changed a different function to not display the output. If it helps anyone, my code is below....

 

function process() {
     global $order, $cart, $currencies;

     $extra_charge_tot = $cart->get_extra_charge_total();

// The "if" and "else" statements were added by John to not display the the extra charge if the extra chrage value is 0.
         if ($extra_charge_tot == 0) {

         $order->info['total'] += $extra_charge_tot;
                 $this->output = array();

         } else {
         $order->info['total'] += $extra_charge_tot;

         $this->output[] = array('title' => MODULE_ORDER_TOTAL_EXTRA_CHARGE_TEXT_TITLE . ':',
                                 'text' => $currencies->format($extra_charge_tot, true, $order->info['currency'], $order->info['currency_value']),
                                 'value' => $extra_charge_tot);
         }
   }


 

 

Thanks to all who responded to this.

Link to comment
Share on other sites

  • 3 months later...

Actually, I think I got it working. In the order total module I changed a different function to not display the output. If it helps anyone, my code is below....

 

function process() {
     global $order, $cart, $currencies;

     $extra_charge_tot = $cart->get_extra_charge_total();

// The "if" and "else" statements were added by John to not display the the extra charge if the extra chrage value is 0.
         if ($extra_charge_tot == 0) {

         $order->info['total'] += $extra_charge_tot;
                 $this->output = array();

         } else {
         $order->info['total'] += $extra_charge_tot;

         $this->output[] = array('title' => MODULE_ORDER_TOTAL_EXTRA_CHARGE_TEXT_TITLE . ':',
                                 'text' => $currencies->format($extra_charge_tot, true, $order->info['currency'], $order->info['currency_value']),
                                 'value' => $extra_charge_tot);
         }
   }


 

 

Thanks to all who responded to this.

 

I'm using the same contribution, with the changes you've made already in place. When I go to my Order Totals page in the Admin section, I get the following error:

 

Fatal error: Cannot redeclare class ot_extra_charge in /home/content/01/6363701/html/britebills/includes/modules/order_total/ot_extra_charge.php on line 15

 

Any ideas?

Link to comment
Share on other sites

I'm using the same contribution, with the changes you've made already in place. When I go to my Order Totals page in the Admin section, I get the following error:

 

Fatal error: Cannot redeclare class ot_extra_charge in /home/content/01/6363701/html/britebills/includes/modules/order_total/ot_extra_charge.php on line 15

 

Any ideas?

 

I fixed the problem by deleting the (orig) backup file from the server. I have other problems but I will research them first before posting an answer.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...