Good Morning KK and the development team.
I need your help with adding more option values to the option_value_handler script, and I'll be grateful to get a fruitful response from you. I am designing a website for myself to be to sell apparels and souvenirs and would want clients to be able to upload designs to be printed on the products. I want to ensure clients are able to select multiple sizes or colors when product quantities is more than one. In this vain, I intend to include a checkbox and a file-upload options to the option values available.
While I am not a scripting expert, I have tried to edit the handling the script myself but was not successful with the variations I intend to add to it. I was successful in changing the radio-button option to a checkbox though. However, I still want to retain the radio button alongside the checkbox for the 'list' options. I have also tried to add the file-upload <input> as alternative to the 'text' box also without success.
I am currently working on the couch code handed down in the tutorials and I'll test my output later to see if I can achieve my objective. I hope to share my success with the group.
Meanwhile, let me be upfront with this request from you as it would also enrich our couchcart options if we're able to achieve this result.
see the script being referred to below, also take note of the inclusions I tried to make and see if you can help resolve the issues there-in
I need your help with adding more option values to the option_value_handler script, and I'll be grateful to get a fruitful response from you. I am designing a website for myself to be to sell apparels and souvenirs and would want clients to be able to upload designs to be printed on the products. I want to ensure clients are able to select multiple sizes or colors when product quantities is more than one. In this vain, I intend to include a checkbox and a file-upload options to the option values available.
While I am not a scripting expert, I have tried to edit the handling the script myself but was not successful with the variations I intend to add to it. I was successful in changing the radio-button option to a checkbox though. However, I still want to retain the radio button alongside the checkbox for the 'list' options. I have also tried to add the file-upload <input> as alternative to the 'text' box also without success.
I am currently working on the couch code handed down in the tutorials and I'll test my output later to see if I can achieve my objective. I hope to share my success with the group.
Meanwhile, let me be upfront with this request from you as it would also enrich our couchcart options if we're able to achieve this result.
see the script being referred to below, also take note of the inclusions I tried to make and see if you can help resolve the issues there-in
- Code: Select all
function product_option_values_handler( $params, $node ){
global $CTX, $FUNCS, $CART;
// get the option object supplied by 'cms:pp_product_options' tag
$opt = &$CTX->get_object( 'selected_options', 'pp_product_options' );
$y = $CTX->get( 'k_count' ); // count index of parent 'pp_product_options' tag
if( is_array($opt) && is_array($opt['values']) ){
$html = '';
if( !count($node->children) ){ // used as a self-closing tag - return HTML of options dropdown
if( $CART->_is_option_text($opt) ){ // textbox
$html .= '<input type="text" name="os'.$y.'" maxlength="200">';
}
else{ // list
$sep = '';
for( $x=0; $x<count($opt['values']); $x++ ){
$value = $opt['values'][$x];
$str_option = $value['attr'];
$price = $value['price'];
if( ($price!=0) ){
$str_option .= ($price>0) ? ' [+'.$CART->get_config('currency_symbol') : ' [-'.$CART->get_config('currency_symbol');
$str_option .= abs( $price ) .']';
}
if( $opt['modifier']=='*' || $opt['modifier']=='**' ){ // radio buttons ('**' specifies all buttons in the same row)
if( $opt['modifier']=='*' ) $html .= $sep;
$html .= '<label class="radio-label">';
$html .= '<input type="radio" name="os'.$y.'" value="'.$x.'"';
if( $x==0 ) $html .= ' checked="true"';
$html .= '>'.$str_option;
$html .= '</label>';
}
else {
if( $opt['modifier']=='^' || $opt['modifier']=='^^' ){ // checkbox buttons ('**' specifies all buttons in the same row)
if( $opt['modifier']=='*' ) $html .= $sep;
$html .= '<label class="radio-label">';
$html .= '<input type="checkbox" name="os'.$y.'" value="'.$x.'"';
if( $x==0 ) $html .= ' checked="true"';
$html .= '>'.$str_option;
$html .= '</label>';
}
}
else{ // dropdown
$html .= '<option value="'.$x.'">'.$str_option.'</option>';
}
$sep = '<br>';
}
if( !($opt['modifier']=='*' || $opt['modifier']=='**') ){
$html = '<select name="os'.$y.'">' . $html . '</select>';
}
}
$html = '<input type="hidden" name="on'.$y.'" value="'.$opt['name'].'" style="display:none;">' . $html;
}
else{
for( $x=0; $x<count($opt['values']); $x++ ){
$value = $opt['values'][$x];
$str_option = $value['attr'];
$price = $value['price'];
if( $CART->_is_option_text($opt) ){ // textbox
// type textbox really shouldn't be called with 'cms:product_option_values' as it has no options
// but in case this is done, let us handle it
$CTX->set( 'k_count', $y ); // set k_count of parent (i.e. product_options)
$CTX->set( 'option_val', '' ); // don't make the '*TEXT*' available
}
else{
$CTX->set( 'k_count', $x ); // set k_count of its own
$CTX->set( 'option_val', $str_option );
}
$CTX->set( 'option_price', abs( $price ) );
$CTX->set( 'option_price_sign', ( $price>=0 ) ? '+' : '-' );
foreach( $node->children as $child ){
$html .= $child->get_HTML();
}
}
}
}
return $html;
}