Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

optional attribute


andy_1984

Recommended Posts

me again,

 

after much thought i have came up with a solution to my pizza toppings predicament.

 

using a quick and nasty method of figuring out if an attribute is a topping or not

 

in product_info.php bellow [<td class=main"><?php echo $products_options_name['products_options_name] . ':'; ?></td>] i have:

 

<td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>

 

 

 

 

<?php

if (!preg_match("/\btopping\b/i", $products_options_name['products_options_name']))

{

 

?>

<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_radio_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>

 

<?php

}

?>

 

 

 

i have then created each topping an individual attribute and have them displayed as radio buttons. the problem i came across with this method was the non existent ability to have that attribute as optional so i added a new attribute called none with the value as none also i modified this code to html_oputput.php:

 

 

function tep_draw_radio_menu($name, $values, $default = '', $parameters = '', $required = false) {

$field ='<table border="0" cellspacing="0" cellpadding="0"><tr><td class="main">';

if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);

 

for ($i=0, $n=sizeof($values); $i<$n; $i++) {

$value = tep_output_string($values[$i]['id']);

 

$field .= '<input type="radio" name="' . $name . '" value="20"> None';

$field .= '<input type="radio" name="' . $name . '" value="' . $value . '"';

if ($i == 0) $field .= ' checked';

 

$field .= '>' . tep_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '<br />';

}

$field .= '</td></tr></table>';

 

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

 

return $field;

}

the code highlighted in red is the modification, its basicly adding the attribute on the fly. i had experimented with several ways of doing this without the "none" radio button actualy needing an attribute to reference it all that would happen is that when clicking add to cart it wouldnt actualy add anything to the cart.

 

also each attribute needs to have the word topping in it so that my modified code in product_info.php knows that this attribute must be created as a radio button which isnt too bad as its the way i actualy want it displayed in product info

 

what i noticed though was the $required variable in the tep_draw_radio_menu function which i couldnt figure out what was actualy used for, i assume this is to do exactly what i have done by changing the code. if so im an idiot could someone please point out how i do this easily without the need to do what i have done.

 

also i do not like to have to add an attribute called none as i had to get the id of the value to use in the tep_draw_radio_menu function, is there another way of doing this without the need for another attribute ?

 

sorry if im not making much sense ive been working from 9am to 12am on the website and theres no coffee in the office

 

Respectfully,

 

Andy

Link to comment
Share on other sites

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...