Jump to content



Latest News: (loading..)

- - - - -

Remove the product attribute drop-down box if only one attribute


This topic has been archived. This means that you cannot reply to this topic.
21 replies to this topic

#-19   JNKeil

JNKeil
  • Members
  • 3 posts

Posted 07 January 2009 - 03:27 PM

Hi.

Please help.
I will like to remove the product attribute drop-down box if there is only one attribute.
When only one attribute is listed, the attribute, will be shown as normal text.!

#-18   spooks

spooks
  • Members
  • 7,017 posts

Posted 07 January 2009 - 04:51 PM

Use tep_db_num_rows & dont use drop if = 1
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#-17   JNKeil

JNKeil
  • Members
  • 3 posts

Posted 07 January 2009 - 07:28 PM

Hi Sam.

Will you please tell me where and what to change in this line.
<?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?>

I believe that this is here I have to change something... :-)


View Postspooks, on Jan 7 2009, 05:51 PM, said:

Use tep_db_num_rows & dont use drop if = 1


#-16   spooks

spooks
  • Members
  • 7,017 posts

Posted 07 January 2009 - 08:01 PM

yes, loop around with
if (tep_db_num_rows ($products_options_query) != 1)

Edited by spooks, 07 January 2009 - 08:15 PM.

Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#-15   johny_boy

johny_boy
  • Members
  • 1 posts

Posted 20 February 2009 - 02:19 PM

View Postspooks, on Jan 7 2009, 09:01 PM, said:

yes, loop around with
if (tep_db_num_rows ($products_options_query) != 1)


Hy Sam
i made this line
<?php if (tep_db_num_rows ($products_options_query) != 1){ echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); } ?>

but now all my text disappears , can you help me?

#-14   davidrus

davidrus
  • Members
  • 4 posts

Posted 24 February 2009 - 09:17 PM

View Postjohny_boy, on Feb 20 2009, 02:19 PM, said:

Hy Sam
i made this line
<?php if (tep_db_num_rows ($products_options_query) != 1){ echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); } ?>

but now all my text disappears , can you help me?


Not sure if you found the answer yet, but if you didn't, I think I can help.

I'm assuming if there is only one attribute, you want to display it, just not in a drop-down box.

This is what I did (although it might not be the best way, it works):

Go to catalog > includes > functions > html_output.php

Paste this function at the bottom of the page, right before the ?>

  function tep_draw_not_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
    global $HTTP_GET_VARS, $HTTP_POST_VARS;

    if (tep_not_null($parameters)) $field .= ' ' . $parameters;
    
    if (empty($default) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
      if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
        $default = stripslashes($HTTP_GET_VARS[$name]);
      } elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
        $default = stripslashes($HTTP_POST_VARS[$name]);
      }
    }

    for ($i=0, $n=sizeof($values); $i<$n; $i++) {
      $field .= tep_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => ''', '<' => '&lt;', '>' => '&gt;'));
    }

    if ($required == true) $field .= TEXT_FIELD_REQUIRED;

    return $field;
  }

Now go to product_info.php

Find:

<td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>
              <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>

Replace with:

<td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>
              <?php if (tep_db_num_rows ($products_options_query) != 1) { ?>
              <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>
              <?php } else { ?>
  <td class="main"><?php echo tep_draw_not_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>
              <?php } ?>


Now, if there is only 1 option associated with an attribute, it won't display the drop-down, but if there is more than one, it will.

Hope this helps.

#-13   ruan

ruan
  • Members
  • 2 posts

Posted 26 February 2009 - 10:28 AM

View Postdavidrus, on Feb 24 2009, 09:17 PM, said:

Go to catalog > includes > functions > html_output.php

Paste this function at the bottom of the page, right before the ?>

  function tep_draw_not_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
    global $HTTP_GET_VARS, $HTTP_POST_VARS;

    if (tep_not_null($parameters)) $field .= ' ' . $parameters;
    
    if (empty($default) && ( (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) || (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) ) ) {
      if (isset($HTTP_GET_VARS[$name]) && is_string($HTTP_GET_VARS[$name])) {
        $default = stripslashes($HTTP_GET_VARS[$name]);
      } elseif (isset($HTTP_POST_VARS[$name]) && is_string($HTTP_POST_VARS[$name])) {
        $default = stripslashes($HTTP_POST_VARS[$name]);
      }
    }

    for ($i=0, $n=sizeof($values); $i<$n; $i++) {
      $field .= tep_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => ''', '<' => '&lt;', '>' => '&gt;'));
    }

    if ($required == true) $field .= TEXT_FIELD_REQUIRED;

    return $field;
  }

Hi David,

I tried adding the code but it generates an SQL from this piece of code. I think this line is the problem.    

$field .= tep_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => ''', '<' => '&lt;', '>' => '&gt;'));

Can you have a look and see if it's as you have it in your site?

cheers,

ruan

#-12   davidrus

davidrus
  • Members
  • 4 posts

Posted 26 February 2009 - 06:34 PM

View Postruan, on Feb 26 2009, 11:28 AM, said:

Hi David,

I tried adding the code but it generates an SQL from this piece of code. I think this line is the problem.    

$field .= tep_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => ''', '<' => '&lt;', '>' => '&gt;'));

Can you have a look and see if it's as you have it in your site?

cheers,

ruan


Can you copy and paste the error your getting for me? I don't get an error on my site. Thanks.

#-11   ruan

ruan
  • Members
  • 2 posts

Posted 27 February 2009 - 09:13 AM

View Postdavidrus, on Feb 26 2009, 06:34 PM, said:

Can you copy and paste the error your getting for me? I don't get an error on my site. Thanks.

hey, thanks for the reply :)

when i look at the code in dreamweaver I can see that all of this :

'));
}

if ($required == true) $field .= TEXT_FIELD_REQUIRED;

return $field;
}
  
?>

is in red, not black and blue with a bit of red.

henc my comment about this line maybe having an error:

{
$field .= tep_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => ''', '<' => '&lt;', '>' => '&gt;'));
}

Also, the actual error points to the line above.

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in Shop\includes\functions\html_output.php on line 347

cheers

r

Edited by ruan, 27 February 2009 - 09:16 AM.


#-10   davidrus

davidrus
  • Members
  • 4 posts

Posted 27 February 2009 - 04:35 PM

View Postruan, on Feb 27 2009, 10:13 AM, said:

hey, thanks for the reply :)

when i look at the code in dreamweaver I can see that all of this :

'));
}

if ($required == true) $field .= TEXT_FIELD_REQUIRED;

return $field;
}
  
?>

is in red, not black and blue with a bit of red.

henc my comment about this line maybe having an error:

{
$field .= tep_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => ''', '<' => '&lt;', '>' => '&gt;'));
}

Also, the actual error points to the line above.

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in Shop\includes\functions\html_output.php on line 347

cheers

r

I see what the problem is. The post isn't displaying the html correctly. Not sure how to fix that.

The correct line is this:

for ($i=0, $n=sizeof($values); $i<$n; $i++) {
      $field .= tep_output_string($values[$i]['text'], array('"' => '&quot;', '\'' => '&_#_0_3_9;', '<' => '&lt;', '>' => '&gt;'));
    }

Remove the underscores from &_#_0_3_9; and you should be good to go.

If anyone can tell me the proper way to display code without the browser trying to interpret it, I would be most appreciative.

#-9   apephoto222

apephoto222
  • Members
  • 34 posts

Posted 05 April 2011 - 09:27 PM

Im trying to do the same thing. Have you found anything out about how to do it?

#-8   vmjarala

vmjarala
  • Members
  • 129 posts

Posted 28 December 2011 - 10:07 PM

I know this is pretty old, but I wonder if anyone still following this topic has found a solution. I have tried everything recommended and it did not work. I have v2.3.1 and found the code does not look exactly as stated above, but I made all the necessary adjustments (I think.) Let me know if anyone has found a solution! Thanks!

#-7   foxp2

foxp2

    strong as a Twig

  • Members
  • 303 posts

Posted 29 December 2011 - 08:07 AM

another way to do it (no need to create a function)
change (in product_info.php) :
	  <?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?>
with :
	  <?php echo (sizeof($products_options_array) == 1 ) ? tep_draw_radio_field('id[' . $products_options_name['products_options_id'] . ']', $products_options_array[0]['id'], true) . $products_options_array[0]['text'] :  tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?>
^_^

Edited by foxp2, 29 December 2011 - 08:07 AM.

-------------------

#-6   vmjarala

vmjarala
  • Members
  • 129 posts

Posted 29 December 2011 - 05:17 PM

That's great!  Merci, Laurent!

However, if I can do without the radio button, that would be even better. I made a little tweak to your code and erased the 'text' (' '), so all I have is a radio button... so much better than before.

Any other thoughts?

Merci beaucoup!

#-5   foxp2

foxp2

    strong as a Twig

  • Members
  • 303 posts

Posted 29 December 2011 - 05:50 PM

View Postvmjarala, on 29 December 2011 - 05:17 PM, said:

However, if I can do without the radio button, that would be even better.

yes, it's possible. tep_draw_hidden_field is the key :

	  <?php echo (sizeof($products_options_array) == 1 ) ? tep_draw_hidden_field('id[' . $products_options_name['products_options_id'] . ']', $products_options_array[0]['id']) . $products_options_array[0]['text'] :  tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?>

-------------------

#-4   vmjarala

vmjarala
  • Members
  • 129 posts

Posted 29 December 2011 - 06:37 PM

BEAUTIFUL!!!!!!!!!!!!!!!!! Thanks!!!!!!!!!!
Yikes, I can't believe it was that easy...

#-3   patrickluursema

patrickluursema
  • Members
  • 41 posts

Posted 22 January 2012 - 11:33 AM

Works like a charm!
Regards,

Patrick Luursema

#-2   MishaB

MishaB
  • Members
  • 24 posts

Posted 25 January 2012 - 04:53 AM

Help! I need a charm, too ...  :rolleyes:

I have a similar wish, but the solution above doesn't work for me.

I have 6 attributes in the drop-down field, but don't want to show them to customers.
What do I need to do that always the first attribut is selected and no drop-down menu is shown?

I would be thankful for any help or ideas!

#-1   DunWeb

DunWeb

    The Censored One

  • Members
  • 12,728 posts

Posted 25 January 2012 - 05:51 AM

@MishaB,

Your scenario is a bit confusing.  Why do you have 6 attributes but the customer is only allowed to choose 1 ?  If there is only 1 to be selected, then remove the other 5 !




Chris
:|: Was this post helpful ? Click the LIKE THIS button :|:

See my Profile (click here)

#0   MishaB

MishaB
  • Members
  • 24 posts

Posted 25 January 2012 - 06:01 AM

@DunWeb:
I didn't wanted to write a novel (which I usually do when I want to explain something) ... :)

The customer always receive 6 different download links at the end of the purchase. I wanted to give them a lot of options and they can choose by themselfes in the end what works best for them. I didn't wanted to put every file in a zip-folder, so I created 6 different options which are all available at the checkout_success.php.

Now, I just don't want to confuse the customer before buying (because you see - there is no need for it!)

I want to make everything as customer friendly as possible ... :)

Edited by MishaB, 25 January 2012 - 06:02 AM.