Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
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

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;
        }
I have been able to include the 'checkbox' option for the list items. I got it wrong with else statement preceding the code for the checkbox. I have corrected that with the 'else_if' statement.

As for the 'file' input type, I have added a line to accept <input> type = file in the option_type_handler code. But I am yet to the code to accept and display as an option value.

Thank you.
Hello all, an update on what I was able to do and where further help is needed.

I have been able to include a file upload option to product variant list. All I did was to include a modifier to accommodate an <input> type=file to the pp_option_handler of the addons/cart/cart.php file

Code: Select all
                           
      if( $opt['modifier']=='#'){ // textbox
                        $html .= '<input type="file" name="os'.$y.'" accept=".jpg, .jpeg,.png, .cdr" multiple >';
                    }


This ensures I have the option to select a file for upload. I can also include a submit button but once this option is added, the add to cart button doesn't respond to call action.

How do I resolve this problem, so clients and buyers can upload external (desktop) items e.g. images to the Cart.

Thank you.
Hi Toheeb,

I appreciate your trying so hard to make the cart module fit your use-case.
Unfortunately, I don't think it would be possible to add the file attachment feature in a secure manner easily - type 'securefile' came much after the cart module so it will require some effort to make it fit into the existing cart setup.

I am sorry but I won't be able to find the time needed to do that at the moment.
I'll definitely keep this requirement in mind though for future development.
sell apparels and souvenirs and would want clients to be able to upload designs to be printed on the products

I find KK's answer might be a bit disappointing for you. You are clearly looking for the best desired user experience. But there is a way out, hopefully.

I think you should stay focused on your task and not the modding the CMS.

- let clients add a new option for the same product as a separate product = all via existing known how-tos.
- let clients buy first and, once the purchase confirmed, automatically create a login/password for them to enter their client area, where they can safely upload the designs = all via existing known how-tos.

While focusing, clients may need to go one small extra step to fit in the current CMS feature-set. However, if you think about it further, you may find it very suitable for development and customer management.
Hi KK and Trendoman,

thanks for this advise and encouragement, I'll drop my ambition and follow the suggestion of trendoman to achieve the objective through other means.

Although, trendoman, I seem lost on what you're trying to suggest on your last line.

I'll be sharing with the house what I was able to do. If I need help as well, I'll pop-in.

Thank you.
Lest I forget KK, Trendoman or anybody,

Recall that the CouchCart option variants only permits radio-button, dropdowns and texts, I was able to include a checkbox option as well. This permits that multiple selections can be made for a variant option set to be so.

I, however discovered that, of the multiples selected (through the checkbox), only one does appear on the couchcart, despite that I set it to accept 'multiple'.

What inclusion and where, do I need to make on the couch options_handling_script, for the selected multiples to display on the couchcart.

Thank you.
7 posts Page 1 of 1

Who is online

In total there are 7 users online :: 0 registered, 0 hidden and 7 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 7 guests