Remove the product attribute drop-down box if only one attribute
#1
Posted 07 January 2009, 15:27
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.!
#2
Posted 07 January 2009, 16:51
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.
#3
Posted 07 January 2009, 19:28
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... :-)
spooks, on Jan 7 2009, 05:51 PM, said:
#4
Posted 07 January 2009, 20:01
if (tep_db_num_rows ($products_options_query) != 1)
Edited by spooks, 07 January 2009, 20:15.
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.
#5
Posted 20 February 2009, 14:19
spooks, on Jan 7 2009, 09:01 PM, said:
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?
#6
Posted 24 February 2009, 21:17
johny_boy, on Feb 20 2009, 02:19 PM, said:
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('"' => '"', '\'' => ''', '<' => '<', '>' => '>'));
}
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.
#7
Posted 26 February 2009, 10:28
davidrus, on Feb 24 2009, 09:17 PM, said:
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('"' => '"', '\'' => ''', '<' => '<', '>' => '>'));
}
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('"' => '"', '\'' => ''', '<' => '<', '>' => '>'));
Can you have a look and see if it's as you have it in your site?
cheers,
ruan
#8
Posted 26 February 2009, 18:34
ruan, on Feb 26 2009, 11:28 AM, said:
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('"' => '"', '\'' => ''', '<' => '<', '>' => '>'));
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.
#9
Posted 27 February 2009, 09:13
davidrus, on Feb 26 2009, 06:34 PM, 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('"' => '"', '\'' => ''', '<' => '<', '>' => '>'));
}
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.
#10
Posted 27 February 2009, 16:35
ruan, on Feb 27 2009, 10:13 AM, said:
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('"' => '"', '\'' => ''', '<' => '<', '>' => '>'));
}
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('"' => '"', '\'' => '&_#_0_3_9;', '<' => '<', '>' => '>'));
}
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.
#11
Posted 05 April 2011, 21:27
#12
Posted 28 December 2011, 22:07
#13
Posted 29 December 2011, 08:07
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.
osCommerce, Code With Passion
My Tools for Agile software development : About Me
#14
Posted 29 December 2011, 17:17
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!
#15
Posted 29 December 2011, 17:50
vmjarala, on 29 December 2011, 17:17, said:
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); ?>
osCommerce, Code With Passion
My Tools for Agile software development : About Me
#16
Posted 29 December 2011, 18:37
Yikes, I can't believe it was that easy...
#17
Posted 22 January 2012, 11:33
Regards,
Patrick Luursema
#18
Posted 25 January 2012, 04:53
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!
#19
Posted 25 January 2012, 05:51
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
:|: Click Here to learn how I can help you with custom coding, add ons, security and templates :|:
:|: Need an Area Calculator, Pre-Paid Account, Virtual Pin, Auction or Layaway Add on ? Click Here :|:
#20
Posted 25 January 2012, 06:01
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.














