Jump to content

hide a price from a drop down if it is $0.00 ?


toolman

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.