Is there any way to sort the shipping methods by cheapest cost first to highest last during checkout?
Is there any way to sort the shipping methods by cheapest cost first to highest last during checkout?
First question to ask would be what if a given shipping method has multiple costs made available? USPS, UPS, and Fedex each offer such options and there may be others. How would such a situation/condition be expected to be handled?
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
The question was to encourage consideration of what the desired outcome would be based on knowing how some shipping modules operate. Right now, it appears that if any of the three modules identified above (which were used purely as examples) were used, then you already have determined which should be first, second and third at *all* times. But, then decided to throw in yet another variable to consider. So not only is it desired to sort the options presented to the customer by price, but it sounds like proposed delivery date also should be a factor.
I would then ask, in what sequence should the options be displayed if there is no delivery date provided?
The reason for the questions is two fold. What result(s) would satisfy your needs and what truly are your needs?
For example, if a shipping module offered three prices, say a super low, a medium and a high price. Another offered three prices all less than the mediume price but more than the super low price, then of the two modules which should be listed first? What if the super low price sometimes took a month for delivery and all other prices always took less than a week?
If, however, a module is "always" known to cost more than others, there is a sort order that is available so that the modules could always be displayed in the order setup originally.
While I haven't looked over the code section that "sorts" the modules, it may be possible to sequence them during display based on whatever criteria is developed and met.
Other than setting the sort order in the admin, almost any other adjustment is going to require coding or using something that already takes those factors into account.
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
I guess I have opened a can of worms. Bottom line what happens frequently is that since "UPS" and "USPS" names are similar i have customers just not paying attention. "UPS" is always more expensive and usually double the cost of "USPS". They just go on threw the checkout and usually don't notice until later that their shipping charges are so expensive. Then I give them a refund. Do you have any idea how we might be able to bring attention to the cost before they commit with the payment?
In a default install, the cheapest overall shipping option should be default selected when the customer first arrives at the checkout_shipping page. That is at least provided the "cheapest" shipping isn't identified as storepickup. This is initiated in includes/modules/pages/checkout_shipping/header_php.php, using code in includes/classes/shipping.php to determine the cheapest setting and as necessary/where activated there is a notifier in the shipping class: NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST that may be "hijacking" this situation and preventing the real cheapest method from being selected. There's other places something like that could be done as well, but these are the "most likely" locations.
Some of the payment methods also support selecting the cheapest shipping method such as when using PayPal Express.
The checkout_confirmation page should be shown and also reflect the chosen shipping rate, but the question at that point is how does that rate compare to others... Sure could do some sort of data collection at the checkout_shipping page to then be (again) presented on the confirmation page, whether it is something like: there are cheaper shipping rates available (not sure you want to send your customer back through the checkout process on purpose as they may just get up and leave), show the various rates, bold the shipping rate regardless of which they pick (again may cause concern to customer and cause them to cycle through), double check their selection when making it on the checkout_shipping page.
Could expand the letters USPS and/or UPS and/or add an image next to each if not already present, place the sort order so that the predominantly cheaper option is listed first (recommend if doing this that all shipping modules have a value greater than 0).
Understand the issue of not only going through the exercise of providing refunds, but also the resulting loss of fees, the aggravation of the return customer or customer that was thinking of returning, etc.
And yes, shipping has (or is) its own "can of worms". :)
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
Printing the shipper logo beside the text might do the trick. At least probably a least cost fix.
mc presents some good points on this issue. how your shipping costs get displayed to the customer is very dependent on your template and i see some potential problems.
that said, if you want to try something, you create a function in an extra_configures file, such as:
PHP Code:
function sortShippingQuotes($quotes)
{
$sortedArray = [];
foreach ($quotes as $quote) {
unset($flatElement);
$flatElement = $quote;
unset($flatElement['methods']);
foreach ($quote as $key => $value) {
if ($key == 'methods') {
foreach ($quote['methods'] as $key => $method) {
$flatElement['methods'][$key] = $method;
$flatElement['sort'] = $method['cost'];
$sortedArray[] = $flatElement;
unset($flatElement['methods']);
}
}
}
}
$sort = array_column($sortedArray, 'sort');
array_multisort($sort, SORT_ASC, $sortedArray);
return $sortedArray;
}
then in includes/modules/pages/checkout_shipping/header_php.php
you can do a change like so:
then you can see how your template displays the shipping options on the page.PHP Code:
// from:
// get all available shipping quotes
$quotes = $shipping_modules->quote();
//to:
// get all available shipping quotes
$quotes = $shipping_modules->quote();
$quotes = sortShippingQuotes($quotes);
i would do some testing first; as there is a bit of a change to the structure of the array; but i think it could be workable.
hope that helps.
Bookmarks