gtilflm Posted June 14, 2010 Posted June 14, 2010 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? Quote
♥kymation Posted June 14, 2010 Posted June 14, 2010 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 Quote See my profile for a list of my addons and ways to get support.
gtilflm Posted June 15, 2010 Author Posted June 15, 2010 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. Quote
Jack_mcs Posted June 15, 2010 Posted June 15, 2010 The products_id variable is not declared. Quote Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
gtilflm Posted June 15, 2010 Author Posted June 15, 2010 My php skills are.... limited, so I'm not sure what you mean by "declared". Is there a way to tell the class what "products_id" is? Thanks. Quote
Jack_mcs Posted June 15, 2010 Posted June 15, 2010 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. Quote Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
gtilflm Posted June 15, 2010 Author Posted June 15, 2010 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? Quote
gtilflm Posted June 15, 2010 Author Posted June 15, 2010 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. Quote
KevinACrider Posted October 4, 2010 Posted October 4, 2010 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? Quote
KevinACrider Posted October 4, 2010 Posted October 4, 2010 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.