Help with complicated shipping needs

sccr410sccr410 Member
in Help edited July 2012
Here is what I was just requested to setup:

Only ship to the US
Free ground shipping on all orders, regardless of what and how many

(1) PRODUCT A = $20 up charge for 2-day air
(2) PRODUCT A = $40 up charge for 2-day air
(3) PRODUCT A = $60 up charge for 2-day air
(So essentially $20 for every Product A ordered)

(1-12) PRODUCT B = $20 up charge for 2-day air
(13 – 24) PRODUCT B = $40 up charge for 2-day air
(Essentially $20 for every 12 of Product B )

I have successfully implemented the US only restriction thanks to http://wiki.foxycart.com/snippets/shipping/restricting_countries_from_the_checkout_form

Previously we were only doing two shipping options - Free Ground or $20 for 2nd day - which I was able to achieve using http://wiki.foxycart.com/snippets/shipping/multiple_flat_rates

Just no clue on where to start with this craziness.
Tagged:
Comments
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    I think what you'll want to do is to use example 3 of the multiple flat rate script and start adding to the base two-day upcharge as you cycle through each product. If it's Product A (you can check , then check fc_json.products[ p ].name or fc_json.products[ p ].code) then you multiple the quantity by 20 and add to your upcharge variable. Then do the same thing for B, just adding as you loop through products.

    Does that make sense?
  • In case someone hits this in the future...

    nzone = Product A referenced above
    wraptor = Product B referenced above

    Each product has many variations, hence the need for the array.

    Not sure if this is optimal code, but it appears to be working!
    var nzone = new Array("FB113005", "FB113007", "FB113009", "FB113011", "FB113013");
    	var wraptor = new Array("SA702501", "SA702503", "SA702505", "SA702507", "SA702509", "SA702511", "SA702001", "SA702003", "SA702005", "SA702007", "SA702009", "SA702011", "SA702001--M", "SA702003--M", "SA702005--M", "SA702007--M", "SA702009--M", "SA702011--M");
    	var code = '';
    	var nzone_count = 0;
    	var wraptor_count = 0;
    	for (var i = 0; i < fc_json.products.length; i++) {
    		code = fc_json.products[i].code;
    		quantity = fc_json.products[i].quantity;
    		if (jQuery.inArray(code, nzone) != -1)
    			nzone_count = nzone_count + quantity;
    		else if (jQuery.inArray(code, wraptor) != -1)
    			wraptor_count = wraptor_count + quantity;
    	}
    	var nzone_shipping = nzone_count*20;
    	var wraptor_shipping = Math.ceil(wraptor_count / 12)*20;
     	
     	addShippingOption(1, 0, '', 'Free Ground Shipping');
     	addShippingOption(2, nzone_shipping+wraptor_shipping, '', '2nd Day Air Shipping');
    
  • fc_adamfc_adam FoxyCart Team
    @sccr410,

    If it works for you as you expect it to, then that's awesome! Thanks for posting your solution.
Sign In or Register to comment.