The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Added script for shipping, now no taxes!

debradebra Member
in Help edited February 2009
Hi:

I added some code (modified from something I found in this forum) to my checkout page so I could calculate shipping based on order amount:

<script type="text/javascript">
function calculateShipping(amount) {
if (amount < 25.01) {
return 7.95;
}
if (amount > 25.00 && amount <= 50.00) {
return 9.95;
}
if (amount > 50.00 && amount <= 100.00) {
return 12.95;
}
if (amount >100.00 && amount <= 165.00) {
return 17.95;
}
if (amount >165.00) {
myprice = amount * .105;
return myprice;
}
}

$j(document).ready(function() {
FC.checkout.override("updatePrice","myUpdatePrice");
FC.checkout.config.orderShipping = calculateShipping(fc_json.total_price);
FC.checkout.updatePriceDisplay();
});

var myUpdatePrice = function() {
FC.checkout.updatePaymentDisplay();
}
</script>

It works perfectly. However, the cart is no longer calculating tax. If I take it out, it does. I have tried moving it to the <head>, above and below ^^checkout^^, but its location makes no difference.

Any help? Clues? Advice?
Comments
  • lukeluke FoxyCart Team
    I'd recommend not messing with that code unless you've got a really good handle on the guts of what's going on under the hood. The FC.checkout.override method is undocumented and you may accidentally override some core functionality you need (such as taxes, in this case). You'd have to pry open the checkout javascript pretty deeply to figure it all out and it could probably be overhauled as it is. In a nutshell the updatePrice method does all kinds of things including getting the price from the selected shipping rate item (which you're wanting to override).

    Are you on 050? Are you using multiship? If not, you might be able to add this to your myUpdatePrice function:

    config.orderTaxes = FC.checkout.getTaxes(-1);

    That may or may not work... I probably shouldn't have posted the override example that in the forum since it's not something we'll be able to support going forward.
  • I'm not on 050, because it looks like a beta.

    All I basically want is to set up a shipping table based on the total amount of the order, which most cart applications do. I was surprised not to see it in the site setup...i.e., if the order is less than $25, shipping is X, if 25.01-50.00, it's y, 50.01-75.00, it's z, etc.

    If there's a better, built-in way to set that up, do tell!
  • brettbrett FoxyCart Team
    Shipping tiers are definitely one of those things that seems to be so basic you'd just assume we'd support it, but unfortunately you'd be wrong (at this point). We definitely have plans to add support for this type of shipping calculation, but if you could vote and comment here (under the Super Ship item):
    http://requests.foxycart.com/
    we'd greatly appreciate it.

    Luke might be able to chime in on the missing piece to your puzzle.
  • lukeluke FoxyCart Team
    Debra, did you try adding the line to your myUpdatePrice function?

    The main reason we didn't build a shipping table matrix right from the start is that our experience with them was rather frustrating. No matter how "smart" you try to make them, the orders don't usually fit what the real shipping charges are. If someone buys something from Alaska, for example, and you only do a calculation based on the order cost, you'll be out some money.
  • Luke (and Brett):

    Thanks for helping.

    Yes, I tried adding:
    config.orderTaxes = FC.checkout.getTaxes(-1);

    like this:

    $j(document).ready(function() {
    FC.checkout.override("updatePrice","myUpdatePrice");
    FC.checkout.config.orderShipping = calculateShipping(fc_json.total_price);
    config.orderTaxes = FC.checkout.getTaxes(-1);
    FC.checkout.updatePriceDisplay();
    });

    and like this:

    $j(document).ready(function() {
    FC.checkout.override("updatePrice","myUpdatePrice");
    FC.checkout.config.orderShipping = calculateShipping(fc_json.total_price);
    FC.checkout.config.orderTaxes = FC.checkout.getTaxes(-1);
    FC.checkout.updatePriceDisplay();
    });

    I also tried adding it in the bottom part, since I wasn't too clear as to exactly where you were telling me to stick it:

    var myUpdatePrice = function() {
    config.orderTaxes = FC.checkout.getTaxes(-1);
    FC.checkout.updatePaymentDisplay();

    ...I've pretty much stuck it everywhere, and still, no taxes.

    Re: your comment about shipping costs, say, from Alaska...that's not really my deal as the designer/developer. It's for my client to decide. They've had their shipping table for like nine years now, and it seems to work fine for them. They make adjustments to it every once in a while, but overall, it keeps things simple.

    If I could get the taxes squared away, I think FoxyCart would be a nice solution for them. Except for one other item that I'll probably need help with. One thing at a time, though!
  • lukeluke FoxyCart Team
    Sorry, put FC.checkout.config.orderTaxes = FC.checkout.getTaxes(-1); in your myUpdatePrice method. Looks like you were almost there, I just gave you the wrong code.

    config alone will be undefined, but FC.checkout.config.orderTaxes should be ok.
  • Here's what I have:

    <script type="text/javascript">
    function calculateShipping(amount) {
    if (amount < 25.01) {
    return 7.95;
    }
    if (amount > 25.00 && amount <= 50.00) {
    return 9.95;
    }
    if (amount > 50.00 && amount <= 100.00) {
    return 12.95;
    }
    if (amount >100.00 && amount <= 165.00) {
    return 17.95;
    }
    if (amount >165.00) {
    myprice = amount * .105;
    return myprice;
    }
    }

    $j(document).ready(function() {
    FC.checkout.override("updatePrice","myUpdatePrice");
    FC.checkout.config.orderShipping = calculateShipping(fc_json.total_price);
    FC.checkout.config.orderTaxes = FC.checkout.getTaxes(-1);
    FC.checkout.updatePriceDisplay();
    });

    var myUpdatePrice = function() {
    FC.checkout.updatePaymentDisplay();

    }
    </script>

    It doesn't calculate the tax. Have I made a mistake? I've put it in the <head> but also in the body, before the ^^checkout^^. Doesn't seem to matter.
  • lukeluke FoxyCart Team
    var myUpdatePrice = function() {
    FC.checkout.config.orderTaxes = FC.checkout.getTaxes(-1);
    FC.checkout.updatePaymentDisplay();
    }

    Give that a try.
  • nope! :(
  • Has there been a solution on this? We have the same thing happening. We built a script usinbg JSON to extrapolate the NYS and NJ county tax codes (from a flat file) and it works just fine. However when I confirm the order, the tax zeroes out.
  • lukeluke FoxyCart Team
    This is what I get for posting unsupported code... We've got a lot going on, but I will try to take a look and see what I can come up with.
  • lukeluke FoxyCart Team
    Ok, give this a shot. I had to use yet another undocumented function... the overload method. I guess I should document these since they are proving to be useful.
    <script type="text/javascript">
    function calculateShipping(amount) {
    if (amount < 25.01) {
    return 7.95;
    }
    if (amount > 25.00 && amount <= 50.00) {
    return 9.95;
    }
    if (amount > 50.00 && amount <= 100.00) {
    return 12.95;
    }
    if (amount >100.00 && amount <= 165.00) {
    return 17.95;
    }
    if (amount >165.00) {
    myprice = amount * .105;
    return myprice;
    }
    }
    
    $j(document).ready(function() {
    	FC.checkout.overload("updatePriceDisplay","myCustomShipping",null);
    });
    
    var myCustomShipping = function() {
    	FC.checkout.config.orderShipping = calculateShipping(fc_json.total_price);
    }
    </script>
    

    The "overload" function lets you specify a method to run before and a method to run after a given method is run. In this case, before we run the price display update, we fire off some code to inject a calculated shipping price. Just use the "Shipped using a flat rate fee" delivery option in your category and the code above and you should be good to go.
  • zerognyzerogny Member
    edited March 2009
    Hey Luke,
    No good deed goes unpunished ;)

    Can this feature work the same with taxes? And do we need to be on 050 in order to do it? We're generating shipping AND taxes dynamically using JSON

    Tnx
    Chuck
  • zerognyzerogny Member
    edited March 2009
    And if we do upgrade to 050, what are the ramifications? I can not locate upgrade notes in the wiki for 050.
  • debradebra Member
    Gee, I had given up on this. Thanks, zerogny for bumping, and thanks Luke, for providing a solution that works!
  • lukeluke FoxyCart Team
    You don't need 050, and it should work with taxes (since that was the point). :)

    If you want to check out the changelog, go ahead and change your settings for your store to 050 and they'll show up there. Our plan (shhh!!) is to officially launch 050 this weekend. It's solid (from what we can tell) and just needs some more documentation and upgrade notes. We've been using it ourselves for a couple weeks and the new subscription system is huge improvement for anyone doing subscriptions.

    Enjoy. Tell your friends about how people at FoxyCart love their customers. :)
Sign In or Register to comment.