CUSTOM SHIPPING ENDPOINT: mixing live rates and flat rates

We are setting up for the custom shipping end point (php), and we need to show some (FedEx and USPS ) live rates in some cases; and some flat rates in other cases.

In the admin--> shipping panel we set up for fedex , USPS and custom shipping end points; and in the relevant product categories, for live shipping.

in cases where we need flat rates, the custom end point does it job and adds the flat rates, but we can not get rid of the Fedex/UPSS rates even though we have a
$rates->hide('FedEx');

where we would need it.

I guess this means the the live rates are pulled in parallel with the custom shipping endpoint rates, and we would need to call the Fedex / USPS rates from within the custom shipping end point to be able to manipulate them - if that can be done ? or is there some other way to achieve this ?
Comments
  • fc_adamfc_adam FoxyCart Team
    @Philippe,

    Your assumption there is correct - the custom shipping endpoint is treated just like a normal live rate shipping provider, and all fetched at the same time. As such, the custom shipping endpoint can't impact those other live rates - the different functions available from the custom shipping endpoint helper are just there for altering the custom rates in your endpoint logic.

    What you'd want to do instead is make use of the live rate shipping modification snippet to hide returned rates in the different scenarios you need. You'd still use the custom shipping endpoint to create your custom rates - and just use the live rates snippet to hide the rates you don't need displayed. Details on the snippet are available here: https://wiki.foxycart.com/v/2.0/snippets/live_rate_shipping_modification
  • PhilippePhilippe Member
    Hi, I have a situation where
    - some product categories are shipped using live shipping rates
    - others are shipped using the custom end point.

    I need to complement my custom shipping logic with a snippet that will hide the live shipping rates, if any product of those categories are present - Can you please help me write the condition statement in line 2 below, ?

    Thanks,


    if (FC.json.locale_code == 'en_US' || FC.json.locale_code == 'es_US' || FC.json.locale_code == 'fr_US' || FC.json.locale_code == 'it_US') {

    if (at least 1 product of category x,y,z is present ) {

    FC.customLiveShipping.hide('FedEx ');
    FC.customLiveShipping.hide('USPS ');
    FC.customLiveShipping.hide('Customer Pickup');
    }
    }
  • fc_adamfc_adam FoxyCart Team
    @Philippe,

    Thanks for posting. We actually have a new option we've just added (and will be announcing more details on soon) which provides the custom shipping endpoint functionality, but run after the existing native live rates.

    On the shipping page in your store's admin, you'll see a new option at the bottom for a custom endpoint "with native rates". You can enable that option, and paste in the exact same endpoint URL as the existing option, and then disable the previous custom endpoint.

    Your custom shipping endpoint will also require a small change - just grabbing the latest version of the "ShippingResponse.php" file from https://github.com/Foxy/foxy-shipping-endpoint-php.

    After making those two changes - your custom shipping endpoint will have all of the native rates passed to it to begin with. This will mean that you can hide any of the native rates from your custom endpoint logic - removing the need for the live rates javascript snippet.

    For what you're describing, in your custom shipping endpoint (assuming you're using PHP), it would look something like this:
    $hasCategoryA = false;
    $hasCategoryB = false;
    foreach($cart_details['_embedded']['fx:items'] as $item) {
    switch ($item['_embedded']['fx:item_category']['code']) {
    case "CategoryA":
    $hasCategoryA = true;
    break;
    case "CategoryB":
    $hasCategoryB = true;
    break;
    }
    }
    if ($hasCategoryA || $hasCategoryB) {
    $rates->hide("fedex");
    $rates->hide("ups");
    $rates->hide("customer pickup");
    }
  • PhilippePhilippe Member
    That greatly simplifies the process, as all the logic in the custom end point - without having to have some complementary additional kludged stuff in the configuration.

    Yes, we use php, so I will implement the above in the next few days, and remove the other existing kludges from the config, and rewrite them in the end point...

    Thanks,
  • brettbrett FoxyCart Team
    @Philippe, let us know how it goes. This is brand new for us (but we've got it in production for a larger user already), and we're pretty excited about it. (Well, more excited about the next step, which will be to allow you to add your own custom serverside logic from within the Foxy admin, so you won't need your own endpoint. We're working on that currently.)

    We've also got a Serverless Framework bit of code to make deploying a custom endpoint to AWS Lambda super easy, but if you're using PHP, that's not necessary.
Sign In or Register to comment.