Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Shipping Option: Cheapest Shipping Method Select by Default Rate Topic   - - - - -

 
  • grabbags
  • Senior Member
  • Members
  • Join Date: 14-Aug 07
  • 360 posts

Posted 08 December 2010 - 01:12 AM #1

Hello! I need the shopping to automatically select the cheapest available shipping option by default, rather than sorting by position. Is there a easy mod for this? Thanks in advance.

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12049 posts

Posted 08 December 2010 - 08:04 AM #2

You could change the fn.cart.php code to have it sort by "rate" after the rates are determined for the location.
Note: comment your changes so you can easily replace them since changes to the core files will most likely be overwritten by future upgrades.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • grabbags
  • Senior Member
  • Members
  • Join Date: 14-Aug 07
  • 360 posts

Posted 08 December 2010 - 06:43 PM #3

You could change the fn.cart.php code to have it sort by "rate" after the rates are determined for the location.
Note: comment your changes so you can easily replace them since changes to the core files will most likely be overwritten by future upgrades.


Thank you, tbirnseth.

I found the solution for old version in here:
http://forum.cs-cart...read.php?t=9320

However, I can't locate same portion of code in the 2.x version.
Unfortunately, I am not a programmer ...

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12049 posts

Posted 08 December 2010 - 09:22 PM #4

PM me if you'd like to arrange for me to do this for you.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • grabbags
  • Senior Member
  • Members
  • Join Date: 14-Aug 07
  • 360 posts

Posted 08 December 2010 - 11:37 PM #5

PM me if you'd like to arrange for me to do this for you.


Thanks. Another members helped me out free of charge already. ;)

 
  • colortone
  • Senior Member
  • Members
  • Join Date: 31-Jan 10
  • 368 posts

Posted 08 December 2010 - 11:42 PM #6

could you share the solution?

 
  • clips
  • Aged Resident Loon
  • Members
  • Join Date: 14-Jan 07
  • 1650 posts

Posted 09 December 2010 - 01:25 AM #7

Yes, can you please share the solution. This is a very logical setting for most customers.
Regards,
Jim

 
  • grabbags
  • Senior Member
  • Members
  • Join Date: 14-Aug 07
  • 360 posts

Posted 09 December 2010 - 02:15 AM #8

johnbol1 told me to add:

function compare($x, $y) {
if ( $x['rates'] == $y['rates'] )
return 0;
else if ( $x['rates'] < $y['rates'] )
return -1;
else
return 1;
}
usort($shipping_rates, 'compare');


BEHIND

$cart['shipping_failed'] = true;

in core/fncart.php

I tested it briefly, it works under 2.1.2. Don't know how it react with other environment or conditions.
Thanks!

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12049 posts

Posted 09 December 2010 - 02:23 AM #9

I would probably have used the hook they provided at the bottom of that function.
Look for the line like fn_set_hook('apply_cart_shipping_rates',....)

If you used a hook, you would not have to worry about your changes being in conflict with a future upgrade.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • grabbags
  • Senior Member
  • Members
  • Join Date: 14-Aug 07
  • 360 posts

Posted 13 December 2010 - 06:19 PM #10

I would probably have used the hook they provided at the bottom of that function.
Look for the line like fn_set_hook('apply_cart_shipping_rates',....)

If you used a hook, you would not have to worry about your changes being in conflict with a future upgrade.


Thanks for the suggestion, but I am not a programmer. Unsure how to do hook. Will spend time to look into it when time allows. Now, I need to manually resolve modified files for updating. Thanks!

 
  • plinkplink
  • Member
  • Members
  • Join Date: 25-Apr 10
  • 156 posts

Posted 15 February 2012 - 11:14 PM #11

This works great, but I have a "ship on your own account" option that defaults to $0.00. Now it shows free shipping as the cart default for everyone. Not good.

How could I make that code say "if it's not free shipping, then run this function" ?
My site: 3-Ring Binders and Organization at UniKeep.com.

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12049 posts

Posted 17 February 2012 - 02:59 AM #12

The logic in the shipping modules is that if a "method" returns zero for the cost, then it is considered free shipping. If the "method" is not returned then that "method" is considered not-available.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • plinkplink
  • Member
  • Members
  • Join Date: 25-Apr 10
  • 156 posts

Posted 17 February 2012 - 02:58 PM #13

Right, but the code snipped posted above still sorts the "method" with a cost of $0.00 as the default because it's the cheapest.

Customers see shipping: $0.00 in the cart and think, "hell yeah!, free shipping!" But when they get to step three in the checkout process they realize that it's not free; it's a method of "ship on your own account" and it requires them to fill in their personal or company shipping account details.

The cart sees it as free shipping because the cart doesn't handle the method except by passing their account details to the view-order screen. Our order-entry guys give the account details to the shipping guys and off it goes.

So my question is one of PHP. How do I make this:

function compare($x, $y) {
if ( $x['rates'] == $y['rates'] )
return 0;
else if ( $x['rates'] < $y['rates'] )
return -1;
else
return 1;
}
usort($shipping_rates, 'compare');

...ignore methods of $0.00 or put them at the end of the sort? I wish I knew more PHP.
My site: 3-Ring Binders and Organization at UniKeep.com.

 
  • YFinder
  • Advanced Member
  • Members
  • Join Date: 12-Nov 14
  • 72 posts

Posted 03 October 2015 - 10:51 PM #14

is this code solution working in 4.x.x?



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21796 posts

Posted 05 October 2015 - 09:04 AM #15

The following code is used to select first shipping method (app/functions/fn.cart.php)

foreach ($product_groups as $key_group => $group) {
                    if (!empty($group['shippings'])) {
                        $first_shipping = reset($group['shippings']);
                        $cart['chosen_shipping'][$key_group] = $first_shipping['shipping_id'];
                    }
                }

You can try to use the mentioned function in this part of code


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)