开发者

Modify php shopping cart to support multiple drop down menus

I have a shopping cart script that I am trying to modify to support multiple product selection. As it is now, the customer can select a product from a single drop down men开发者_StackOverflow社区u. Now, I would like to add multiple dropdown menus (all populated with the same options).

Here is the php that outputs the dropdown menu:

if($eshopoptions['options_num']>1){
            $opt=$eshopoptions['options_num'];
            $replace.="\n".'<label for="eopt'.$theid.'"><select id="eopt'.$theid.'" name="option">';
            for($i=1;$i<=$opt;$i++){
                $option=$eshop_product['products'][$i]['option'];
                $price=$eshop_product['products'][$i]['price'];
                if($option!=''){
                    if($price!='0.00')
                        $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).' @ '.sprintf( _c('%1$s%2$s|1-currency symbol 2-amount','eshop'), $currsymbol, number_format($price,2)).'</option>'."\n";
                    else
                        $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).'</option>'."\n";
                }


            }

Is there some really simple way of getting the code to output the menu say 3 times instead of once?


Unless you really need the redundancy, you can allow users to select multiple options by adding the multiple and, optionally, size attributes to your select tag:

if($eshopoptions['options_num']>1){
        $opt=$eshopoptions['options_num'];
        $replace.="\n".'<label for="eopt'.$theid.'"><select id="eopt'.$theid.'" name="option" multiple="multiple" size="'.$opt.'">';
        for($i=1;$i<=$opt;$i++){
            $option=$eshop_product['products'][$i]['option'];
            $price=$eshop_product['products'][$i]['price'];
            if($option!=''){
                if($price!='0.00')
                    $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).' @ '.sprintf( _c('%1$s%2$s|1-currency symbol 2-amount','eshop'), $currsymbol, number_format($price,2)).'</option>'."\n";
                else
                    $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).'</option>'."\n";
            }


        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜