Foxy Forum Status

We're no longer responding to questions via our forum, but we will keep it up for historical reasons. If you can't find the answer you're looking for, please visit our knowledge base or contact us. If there's enough interest in the future, we may bring the forum back.

How to create an infinite loop

Hi there,

I'm writing a custom shipping method on v2. The goal is to get custom shipping pricing on some products (specific categories) and use FedEx pricing on other products (other categories).

I've been trying to call the FC shipping API: - but it's causing an infinite loop because it's referencing my custom shipping script again.

Any suggestions on how I could use FC shipping API and avoid the infinite loop? I really don't want to have to go create a FedEx dev account and go that route!!!

  • brettbrett FoxyCart Team
    Hey @joelataylor
    Interesting. We'll discuss this and see if we can shine any light on things.

    Are you saying that your custom endpoint is calling the api_json, to get the live rates from Foxy? If so… hrm… I wonder if you could pass an extra parameter through so your custom endpoint doesn't re-request api_json if it's not needed, thus ending the loop.

    (Fwiw, our next improvement to the shipping will be allowing a custom endpoint that gets passed the shipping rates as configured in the store. Not here yet though.)
  • Hey Brett - yeh, I figured what I was doing was a lil "hacky" - in that I'm curling FC to get live FedEx rates on products in a specific category. In fact, I don't think it's going to work (at least the way I'm doing it) because I don't know the fcsid outside of Javascript.

    My only solution now is to use a mix of the Custom Shipping method + Javascript overrides.

    Or, I go find my own connection to FedEx (which I REALLY don't want to do).

    You're "coming soon" feature sounds perfect for my use case. ;)
  • fc_adamfc_adam FoxyCart Team

    Thanks for clarifying further. If I could ask another follow-up question, how would you handle the shipping costs if products from both categories are present? What rates are used then?
  • Hi @fc_adam - happy to help.

    We have the FC category setup for Flat Fee shipping at $0 for the products we have a custom calculation for. Our custom calculation takes into account the quantity ordered and the zip it's being shipped to.

    The other products have the FC Category setup for FedEx Live Shipping - that's how we're able to let FedEx only calculate the appropriate shipping rate.

    Make sense?
  • fc_adamfc_adam FoxyCart Team
    edited May 2017
    @joelataylor - that does help, but I think it might be worth us seeing your store set up for better clarification here. Could you confirm (and feel free to whisper if you'd prefer to keep it private) the store you're working with and have the custom shipping script included on?
  • fc_adamfc_adam FoxyCart Team

    Thanks for whispering. I think there is a way to achieve what you're after here without needing to do a custom integration with FedEx.

    To confirm with you about my earlier question - I understand that if you have only chairs, you calculate the shipping as a tiered flat rate, and if you have only accessories, then you use live FedEx results. If both are present though - could you clarify exactly what result you're after? Would it be just a single custom rate, with the total made up of the calculated custom rate, and then one of the returned live rates? If so - which live rate would you use? Or would you display all of the possible FedEx rates, but just increase them by the calculated rate?
  • fc_adamfc_adam FoxyCart Team

    Thanks for whispering those details (sorry for the issue posting yesterday).

    If I'm understanding your custom code you whispered previously, I think you can actually just update the javascript snippet to make this work. You're currently performing an AJAX request to get the rates again, in order to get the FedEx rate - but with how the live rate snippet works, that's actually just happened. You can then just get the FedEx rates returned from the JSON object. A quick change to the calculateAccessoryRate() function like this I believe will achieve what you're after?
    FC.customLiveShipping.calculateAccessoryRate = function(category_qty) {
    var price = FC.json.shipping_address.shipping_results[1].price;
    if ( category_qty.large_accessories ) price += 100;
    FC.customLiveShipping.accessory_rate = price;

    FC.customLiveShipping.final_rate = FC.customLiveShipping.chair_rate + FC.customLiveShipping.accessory_rate;
    FC.customLiveShipping.add(330, FC.customLiveShipping.final_rate, 'Standard', 'Delivery');
    You may need to actually loop through the FC.json.shipping_address.shipping_results object to find the specific rates you're after, like one of the FedEx rates for example.

    Would that work?

    As an aside - are you concerned about the chair based products increasing the weight that is sent to FedEx for rate calculations? If so, there's a workaround you could take there too.
  • @fc_adam -- ooo, I'll try that out today. Thanks!

    I'm not worried about the chairs changing, that's the custom pricing anyway. And if the Accessories change in weight, that'll be passed to FedEx for accurate shipping costs.

    Thanks again, I'll keep you posted.
  • @fc_adam - your suggestion worked. Thank you!
  • fc_adamfc_adam FoxyCart Team

    Awesome! I'm glad that worked for you!
Sign In or Register to comment.