setting up multiple flat rate shipping by category

SparkySparky Member
in Help edited July 2014
Hi there!

I am trying to figure out the code for setting up multiple flat rate shipping based on category. The examples are good but I'm not a developer so would appreciate a little guidance. =)

The store is at www.SparkplugCoffee.com and is Foxycart v. 1.1

I want to offer 2 shipping options
1 = "Free Basic Mail"
2 = "Express Tracked"

If ONLY the Category "COFFEE" shipping is included
I want to add the option of Express Tracked if product size is "750cc"
and remove all options if product size is "2 Pounder" (Express Tracked is included)

for all other Product Categories (there are 2 - "MAKE_COFFEE" and "SERVE_COFFEE") including purchases that include "COFFEE" plus another Category

Option 1 (basic mail) is available if product weight is < .25 lb
Price for Option 2 (express tracked) is based on the value of the products. $10 if total price is less than $38; $5 if total price is under $65; free if total price is over $65

Here is what I have. Before I try it out, how does it look? Am I missing anything? Do I have the order correct -first adding the options and price rules, then the category exceptions?

Thanks!

_________________________

addShippingOption(1,0,'Lettermail','Free Basic Mail')
addShippingOption(2,10,'Expedited','Express Tracked')

if (fc_json.total_price ]]> 37.99) {
updateShippingOptionCost(2, 5);}
else if (fc_json.total_price ]]> 64.99) {
updateShippingOptionCost(2, 0);
}
if (fc_json.weight ]]> .25) {
removeShippingOption(1);
}


var hasCOFFEE = false;
var hasMAKE_COFFEE = false;
var hasSERVE_COFFEE = false;
for (p in fc_json.products)
{
switch (fc_json.products[p].category)
{
case "COFFEE":
hasCOFFEE = true;
break;
case "MAKE_COFFEE":
hasMAKE_COFFEE = false;
break;
case "SERVE_COFFEE":
hasSERVE_COFFEE = false;
break;
}
}
if (fc_json.size ]] "2Pounder")
{
removeCustomShippingContainer();
}




Tagged:
Comments
  • fc_adamfc_adam FoxyCart Team
    @Sparky,

    Based on what you've described there, that isn't quite right. I haven't tested this, but the following should work - give this a try:
    var hasCOFFEE = false;
    var hasMAKE_COFFEE = false;
    var hasSERVE_COFFEE = false;
    
    for (p in fc_json.products) {
    	switch (fc_json.products[p].category) {
    		case "COFFEE":
    			hasCOFFEE = true;
    		break;
    		case "MAKE_COFFEE":
    			hasMAKE_COFFEE = false;
    		break;
    		case "SERVE_COFFEE":
    			hasSERVE_COFFEE = false;
    		break;
    	}
    }
    
    addShippingOption(1,0,'Lettermail','Free Basic Mail')
    
    if (hasCOFFEE && !hasMAKE_COFFEE && !hasSERVE_COFFEE) {
    	// Only has COFFEE
    	for (p in fc_json.products) {
    		if (fc_json.products[p].size == "750cc") {
    			addShippingOption(1, 10, "Expedited", "Express Tracked");
    		} else if (fc_json.products[p].size == "2Pounder") {
    			removeCustomShippingContainer();
    		}
    	}
    } else {
    	// Has at least one of the other categories
    
    	if (fc_json.total_weight >= .25) {
    		removeShippingOption(1);
    	}
    
    	addShippingOption(2,10,'Expedited','Express Tracked');
    
    	if (fc_json.total_price >= 37.99) {
    		updateShippingOptionCost(2, 5);
    	} else if (fc_json.total_price >= 64.99) {
    		updateShippingOptionCost(2, 0);
    	}
    }
    
  • SparkySparky Member
    thanks! I will give this a try!
Sign In or Register to comment.