cinolas Posted January 18, 2014 Posted January 18, 2014 Hi, I'm installing a contribution and I need to make a small modification to the php code for it to work as I need it to. I don't know php enough to make this work. Consider these here loops: for ($i = 0; $i < sizeof($quotes); $i++) { for ($j = 0; $j < sizeof($quotes[$i]['methods']); $j++) { if ( ($quotes[$i]['methods'][$j]['cost'] > 0) && ($order->content_type != 'virtual') ) { $quotes_array[] = array('id' => $quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'], 'text' => $quotes[$i]['module'].' '.$quotes[$i]['methods'][$j]['id']); //fixer un choix par defaut $default_quotes_array[] = $quotes[$i]; if ( $_GET['shippingselected'] != '' ) { $default_shipping_module = str_replace("'", "", $_GET['shippingselected']); } elseif ( $quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'] == DEFAULT_MODE_DELIVRY_SC ) { $default_shipping_module = DEFAULT_MODE_DELIVRY_SC; } // envoyé le module selctionné (shippingselected ou DEFAULT_MODE_DELIVRY_SC) if ( ($quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id'] == $default_shipping_module) ) { $calcul_fdp_scart = $quotes[$i]['methods'][$j]['cost']; $tax_fdp = $quotes[$i]['tax']; $titre_shipping = $quotes[$i]['module'].' ('.$quotes[$i]['methods'][$j]['title'].')'; } elseif ( ($quotes[$i]['id'].'_'.$quotes[$i]['methods'][$j]['id']) == ($default_quotes_array[0]['id'].'_'.$default_quotes_array[0]['methods'][0]['id']) ) { $calcul_fdp_scart = $quotes[$i]['methods'][$j]['cost']; $tax_fdp = $quotes[$i]['tax']; $titre_shipping = $quotes[$i]['module'].' ('.$quotes[$i]['methods'][$j]['title'].')'; } } } } It's cycling through the various active shipping modules, and methods offered by each module, to build a drop down menu. It's also choosing a default module/method. I want this code to choose the method with the lowest 'cost' from the default module, I only have one active shipping module. It looks to me as though the last elseif simply selects the first option in the menu, method 0, as the default. If that's the case, can I instead modify this so that it somehow selects the method with the smallest cost, which should also be the one with the biggest ID of the array (since the methods are sorted from most expensive to least expensive). Thanks for the help! I've tried the support thread for this contribution but it's dead... I figured this cold be easily solved by anyone who knows php better than I do. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.