toolman Posted January 14, 2011 Share Posted January 14, 2011 Hi there, I have an ecommerce script that displays product prices in a drop down. I have modified the script to display prices in the drop down for other options, such as size, color etc. At the moment, the prices in the drop down display the total price of the product including any other product options. If I apply a product option to a product that does not have an additional cost, it displays Product Option ($0.00) For example, if I have a hat that is priced $3.00, it will display $3.00 in the drop down. If I apply a product option for an XL size and add $2.00, it will display $5.00 in the drop down. However, if I add a product option that does not have an option that effects the price, it will display something like: Hat RED ($0.00). The reason for this happening is because the Red option does not add an addition cost to the product. What I want to do is to hide all prices that have $0.00. I will paste my code below, but I wondered if there is an easy way using PHP that will allow me to do something like: if price == 0.00 then hide 0.00 I am new to PHP and can think the logic, but cannot work out the code. This is my code: <?php $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name"); while ($products_options_name = tep_db_fetch_array($products_options_name_query)) { $products_options_array = array(); $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'"); while ($products_options = tep_db_fetch_array($products_options_query)) { $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']); //if ($products_options['options_values_price'] != '0') { if ($products_options['price_prefix']=='+') { $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $currencies->display_price($products_options['options_values_price']+$product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') '; } else if ($products_options['price_prefix']=='-') { $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $currencies->display_price($product_info['products_price'] - $products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') '; } else { $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') '; } //} } if (is_string($HTTP_GET_VARS['products_id']) && isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) { $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']]; } else { $selected_attribute = false; } ?> <strong><?php echo $products_options_name['products_options_name'] . ':'; ?></strong><br /><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?><br /> <?php } ?> If anyone could help me out, that would be great! Thanks P.S Sorry if this message sounds confusing. Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/ Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 Add a condition in the query that selects the items and check for price. AND pa.products_price > 0.00 Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159407 Share on other sites More sharing options...
toolman Posted January 14, 2011 Author Share Posted January 14, 2011 Many thanks for your reply. I have tried to add it into my query, but it is giving an error. This is what I have done: $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' AND pa.products_price > 0.00 and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name"); Have I placed it in the wrong place? Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159422 Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 What's the error? Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159426 Share on other sites More sharing options...
toolman Posted January 14, 2011 Author Share Posted January 14, 2011 Hi, This is the error I receive: 1054 - Unknown column 'pa.products_price' in 'where clause' select distinct popt.products_options_id, popt.products_options_name from products_options popt, products_attributes patrib where patrib.products_id='36' AND pa.products_price > 0.00 and patrib.options_id = popt.products_options_id and popt.language_id = '1' order by popt.products_options_name Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159428 Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 1054 - Unknown column 'pa.products_price' in 'where clause' Oh, I wasn't sure exactly what the column name or the table name was. I just assumed the product's price would reside in the product attribute table (pa). You may have to find the correct table and column name. Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159431 Share on other sites More sharing options...
toolman Posted January 14, 2011 Author Share Posted January 14, 2011 I am using oscommerce. I have taken a screen shot of the tables in the product attribute table: I have also tried the following: AND pa.options_values_price > 0.00 but it didn't work Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159435 Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 I think you want this: AND patrib.options_values_price > 0.00 The column name feels weird but it's the only one that the price could possibly be. Is options_values_price the price you're trying to check? Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159453 Share on other sites More sharing options...
toolman Posted January 14, 2011 Author Share Posted January 14, 2011 Thanks It doesn't produce any errors now. The thing is, the drop down is still showing the $0.00 I guess I need to do something else to tell the drop down not to show the $0.00? Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159461 Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 Thanks It doesn't produce any errors now. The thing is, the drop down is still showing the $0.00 I guess I need to do something else to tell the drop down not to show the $0.00? Then that may not be the column/table you need to be checking. Which table has the product price in it? Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159462 Share on other sites More sharing options...
toolman Posted January 14, 2011 Author Share Posted January 14, 2011 There is a products table: The products attributes table posted earlier is the table I thought the modified prices would be in. Quote Link to comment https://forums.phpfreaks.com/topic/224439-hide-a-price-from-a-drop-down-if-it-is-000/#findComment-1159464 Share on other sites More sharing options...
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.