Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Is there a way to change the order of the shipping services? I have several flat rate services and i'd like to change the order.
Comment | File | Size | Author |
---|---|---|---|
Screen Shot 2012-04-17 at 4.03.40 PM.png | 53.21 KB | eswiderski |
Comments
Comment #1
googletorp CreditAttribution: googletorp commentedAre you talking about the order in the backend?
Comment #2
googletorp CreditAttribution: googletorp commentedAre you talking about the order in the backend?
Comment #3
BWPanda CreditAttribution: BWPanda commentedI too would like the ability to change the order the shipping services appear in on the checkout form.
I have two shipping options, standard and express. As the standard option is cheaper, I'd like it to appear first as the default, but it seems they're listed in alphabetical order and so standard appears last...
Adding those drag 'n drop weight things (found on most other Drupal forms) to the form from the screenshot above would be perfect.
Comment #4
googletorp CreditAttribution: googletorp commentedHave you tried using the rules weight system to do sorting?
Comment #5
BWPanda CreditAttribution: BWPanda commentedI looked for some weights in Rules to change originally (and again just now), but I can't seem to find anything... There's only one Rule for shipping, and the two shipping services (express and standard) are implemented as Rules Components which don't have weights...
Could you help point me in the right direction?
Comment #6
googletorp CreditAttribution: googletorp commentedSounds like this is a flaw in the way the 2.x branch has organized the Rules, since this is possible in the 1.x. I'll assign Ryan to this, since he made the most of this and knows why it was built the way it was.
Comment #7
Summit CreditAttribution: Summit commentedHi,
What I can see that the services are placed in alphabet from a-z as a workaround for now.
Off course +1 for Weight possibility on Shipping Services!
Greetings, Martijn
Comment #8
FAAREIA CreditAttribution: FAAREIA commentedHi people, if anyone has large amount of services here is a link to make them in a select box. Plus an incomplete (i'm not a programmer so i can't figure it out how to complete the sort function) code of a callback sort function.
Comment #9
rszrama CreditAttribution: rszrama commentedAs with the core Tax module, the Shipping 2.x branch abstracts the calculation of shipping services for an order through a single rule with an action that collects all the available rates for services of each method. If you look at your Rules list, you'll see the
Collect rates: [Shipping method]
rules in there for each shipping method module you've enabled. The action on that rule will loop over all shipping services for the given method and manually execute the rule components for each one to determine if it should be on the order or not. Inside that action, we can't change the execution order of components, as they're governed by the service's weight, but what could happen is you simply remove the default action and replace it with the necessary actions to manually call your various service rules components.That said, on testing, it didn't matter if I split it out, flat rate services were still ordered alphabetically. What we could do is change the checkout form code to respect the order these things were added to the array, but I'm not sure that's the easiest solution. It seems it would be easier to add a "sort order" weight to flat rate services, which would be a simple feature request to that module rather than something the Shipping module itself needs to take care of. Perhaps a hybrid approach would be the best, as it would be most flexible.
So the task for this issue:
Update the checkout pane so it displays shipping services in the order in which they were added to the order's data array.
Comment #11
juan.pompa CreditAttribution: juan.pompa commentedRyan,
I agree with you. We have the same problem here, as we have 7 different shipping services. Adding a sort order "weight" to flat rate services would be very helpfull. It would allow to present them to the client in a particular order.
Thanks a lot for your work. There are many of us using your insights and comments.
Cheers.
juan
Comment #12
olegel CreditAttribution: olegel commentedHi, guys!
I have faced with the same problem, that I couldn't sort shipping services in the way Id like to. I've read all above comments and didn't understand clearly what means update checkout pane (what to change there). Then I started to experiment and I found out the order is being changed if to write machine names of the shipping services in alphabetical order. So I deleted all my services and added them again with respect to machine's names alphabetical order. I had to delete them first since I couldnt edit machine names. So it can help to those who cant programm and write sorting functions!
Comment #13
kingandy CreditAttribution: kingandy commentedBy the time the shipping services are passed to hook_commerce_shipping_service_info_alter, they have been assigned a 'weight' property. This weight appears to be based solely on the order the various modules return their methods (commerce_shipping_services() steps through each module that implements the hook, then each of the shipping services, and sets each weight to "$weight++"). I guess this means the 'Commerce Shipping' part of this issue, as described by Ryan in #9 above, is complete. I'm moving it over to Commerce Flat Rate so we can actually tackle the issue eswiderski originally raised.
FWIW it looks like this should be fairly trivial - just add a 'weight' integer field to the commerce_flat_rate_service table, create some way of editing those weights (either on individual forms or using the tabledrag method), and respect those weights inside the commerce_flat_rate_commerce_shipping_service_info function instead of just
'SELECT * FROM {commerce_flat_rate_service}'
.In the meantime I've used this hook to re-order my shipping rates manually by simply overriding the weight property:
Comment #14
Memes11 CreditAttribution: Memes11 commentedwhat if we have more than 20 rates? how to order them properly as weight is only from -10 to 10.
I have many shipment rates as there is no module (known to me) for HK post and I am setting up a shop for worldwide shipment and the weight base rule is not suitable, I end up having one rate for each country and each 500g section from 0 to 20kg. I do not want to take any shortcut as I do not want my customer to get over charged for transportation.
Thanks
Comment #15
rszrama CreditAttribution: rszrama commentedIn that case you'd need to alter them via code I suppose. Weights don't have to be integers, but only integers can be set via the UI.
Comment #16
maxchock CreditAttribution: maxchock commentedi am also in the middle of the limitation. I need to run a Shipping calculation after another 2 shipping calculation..
Comment #17
Infinitee CreditAttribution: Infinitee commentedkingandy, where exactly did you add the hook?
Thanks,
Update: I really don't like hacking modules but, to get my preferred shipping set as the selected default, I added: 'weight' => -10, to line 70 of...
\profiles\commerce_kickstart\profiles\commerce_kickstart\modules\commerce_kickstart\commerce_kickstart_product\commerce_kickstart_product.features.inc
Of coarse this only works for Commerce Kickstart but, you can search your flat rate module for express_shipping to find what you may be looking for.
Comment #18
marktheshark CreditAttribution: marktheshark commented+1 for being able to reorder within flat shipping rates. I currently have premium listed before standard shipping which is quite inconvenient for the visitor...
Comment #19
kingandy CreditAttribution: kingandy commented@Infinitee, I think I made a new module just to introduce the hook. Either that or I used an existing custom "site-specific utilities" type of module...
Comment #20
iwant2fly CreditAttribution: iwant2fly commentedThis seems to be an issue for the FedEx shipping module as well (http://drupal.org/node/1955574) It seems to me that this ability to sort the displayed rates by price should probably be a feature in the overall Commerce Shipping module rather than in some of the various shipping method modules. Thoughts?
Comment #21
marktheshark CreditAttribution: marktheshark commentedUsed the approach in #13 as well, thanks for sharing!
Comment #22
mesch CreditAttribution: mesch commentedAs I see it there are two distinct goals discussed in this thread:
1. Sort services by name.
2. Sort services by price.
The two don't necessarily work together, since in many cases the rates depend on the order contents.
iwant2fly (post #20) sponsored a solution to #2. I'm posting it here for feedback and in case it is of use to others. In words the approach is to fetch the rates from the $order object, and then use that array to sort the $options displayed on the checkout pane.
This could be integrated into the commerce shipping module by adding a toggle switch somewhere in the UI to turn this sorting on/off.
Comment #23
2ndmile CreditAttribution: 2ndmile commentedNice one MEsch. Exactly what I was looking for.
Comment #24
mengi CreditAttribution: mengi commented#22 Works for me. Using only Flat Rate shipping services, and shipping options are listed by price now.
Being able to assign weights to the shipping options would definitely give greater control but ultimately I simply wanted the options ordered by price so I think this is a great solution.
Comment #25
MrPeanut CreditAttribution: MrPeanut commented#22 is working for me as well. I would second the request to assign weights for more control. (In my case, I'd like to show all USPS options first, sorted by price, then all UPS options, sorted by price.)
Comment #26
frost CreditAttribution: frost commentedno. 22 works for me, thanks!
Comment #27
lukasss CreditAttribution: lukasss commentedhook_form_alter
$form['commerce_shipping']['shipping_service']['shipping_1']['#weight'] = 0;
$form['commerce_shipping']['shipping_service']['shipping_2']['#weight'] = 1;
Comment #28
ShaneOnABike CreditAttribution: ShaneOnABike commentedI think that adding the above feature is pretty important. It makes it easier for the person (user) to recognize what price is what.. it's a bit all over the place right now with all the shipping items listed one after another (unless you have a favourite provider I can't see any reason to do it without sorting by price)
Comment #29
fhdrupal CreditAttribution: fhdrupal commentedMy problem is not exactly the same but somehow similar, if anyone have any idea, can share with me please.
Basically I need a condition in the calculation rules by product weight, to get the whole cart/order products weight and to compare it with maximum weight this rules is valid for. If the weight exceeds the limit, change shipping service.
Thanks in advance,
Comment #30
lukasss CreditAttribution: lukasss commentedYou can this through hook_form_alter. There you have to write your code and starting from change weight:
$form['commerce_shipping']['shipping_service']['shipping_1']['#weight'] = 0;
$form['commerce_shipping']['shipping_service']['shipping_2']['#weight'] = 1;
Sorry for bad england
Comment #31
faerykisses CreditAttribution: faerykisses commentedhi,
Has any progress been made with this issue? i am unsure where to implement the code in #22 as I am new to coding and drupal commerce . This issue however is causing me issues in that people keep choosing the most expensive option as default.
Many thanks
Trixie
Comment #32
heyehren CreditAttribution: heyehren commentedNo 22 works for me. Thanks to mesch
Comment #33
kevster CreditAttribution: kevster commentedExcellent - #22 works for, many thx @mesch
Comment #34
merauluka CreditAttribution: merauluka commentedMine is similar to #22, but I added an additional "multiplier" to my function to force International options to the bottom of the list.
Comment #36
rszrama CreditAttribution: rszrama commentedI had a need for this (combined with adding support for a default value), so I implemented it via a simple weight column on the commerce_flat_rate_service table that turns into the $service['weight'] property on load. Sorry it took so long to get this in. :-/
Commit diff: http://cgit.drupalcode.org/commerce_flat_rate/diff/?id=b667d27
Comment #37
Khumbu CreditAttribution: Khumbu commentedkudos...works like a charm...
Comment #39
kevster CreditAttribution: kevster commentedGood stuff - #22 worked a treat for me with a custom shipping module too - still ordered by price which is just what I wanted.