Picture of Dynamic Shipping Rates via Connect: Scripting

Dynamic Shipping Rates via Connect: Scripting

Learn how to leverage Infigo’s Connect Scripting plugin to programmatically control shipping rates and methods at checkout. This tutorial walks you through enabling the Connect Scripting module, creating and configuring a Megascript to define custom shipping rules (e.g., UK vs. international, conditional free click-and-collect), mapping your script outputs to delivery methods, and testing the dynamic options in action. With this approach, you can implement everything from static shipping rules to real-time API integrations for fully flexible, code-driven checkout shipping.

Tutorial Video Transcript

A transcript of our tutorial video, ensuring you can find exactly what you need, when you need it.

You can search this page to find the relevant time-stamp in the video. Also, this text can be used as part of the tutorial search feature.

0:00 In this video, we'll explore how to use the Connect Scripting plugin in Infigo to control shipping rates and methods during the checkout process.
0:10 This functionality allows you to set up dynamic, customized shipping options through code without relying on manual plugin configurations. Now, just a reminder, in order to use this functionality, you will need access to the Connect Scripting module.
0:27 If you haven't got access to that and would like to try it or would like to get your hands on it, please do contact your Customer Success Manager.
0:37 the Scripting plugin now supports the Shipping Plugin Endpoint, which was initially created for our PrintIQ integration. So this means that you can now create entirely custom shipping integrations just by using Megascript code.
0:53 This gives you the flexibility to define shipping rules precisely, such as domestic versus international options, conditional free shipping, or fetching real-time rates from third-party APIs.
1:07 So, the scripting integration ensures comprehensive access to essential data during the checkout process. This includes things like cart details, checkout attributes, user information, shipping and billing addresses.
1:20 And then when your script executes, it can return detailed shipping option information, which includes things like name or label of the method, unique codes, which are required for mapping to your storefront, price information, various descriptors, CSS classes for visual customization, delivery offset
1:44 days and various other bits and pieces of This robust structure allows for precise control over your shipping options so let's go through an example of this.
1:55 I've got an example, a very simple example, set up on one of my storefronts. The first thing I'm going to do is go to my Connect Settings screen.
2:04 And if it's available to you, you just want to make sure that you have the Connect Scripting plugin enabled. we need to go to the Connect Plugin screen.
2:18 find the connect scripting option and then click on configure next to that particular plugin. Now, we won't be able to fill it in quite at this stage, but what you're looking for is right down at the bottom of here.
2:30 This is basically various areas and various actions on your platform and on your storefront where you can assign certain mega scripts to action against it.
2:38 The one we're looking for in this case is this get shipping options down at the bottom here. And what we're going to be doing once you've created your script is to actually just select it from this dropdown.
2:49 So you can see I have in my example, if you haven't created your script yet, that won't be available to select.
2:56 So to actually get this available in here, we need to actually input our Megascript. So I'm going to go here.
3:01 To the Megascript management screen. We can either create a new Megascript or in this case, I've already got one, which I've created, which I've set to be enabled.
3:14 I'm going to go to edit and then we would input our Megascript into here. Now, this video is not about actually writing this particular Megascript.
3:22 We're just going to be utilizing a very simple example here. So this simple example just uses static information, there's no third-party API calls in here, and it's going to give us conditional options for our shipping.
3:37 So there's going to be three options available. One is going to be a UK standard shipping. So if a shipping address is input within the United Kingdom, then it will allow us to select this as a shipping option.
3:53 And you can see that will give us a certain rate, it will give us a certain delivery offset, and certain other associated information.
4:00 If we are not seeing something from the UK, so if a shipping address is input somewhere outside of the UK, UK in this example, it will not give us the option for UK shipping and instead it will show us this international shipping option, which will have a different rate, a different delivery offset.
4:21 And then different, uh, additional information. And then there will be a third option available, which is an always on, always available, click and collect fallback.
4:31 So that will be a free rate with no delivery offset, and there will be no conditions under how this is displayed.
4:38 So it will always be displayed every time somebody goes through the checkout. So, make sure that we've got that megascript saved.
4:50 And then before we can actually utilize that, we need to go to Megascript instances. this is making sure that our script runs at the appropriate event, and it also gives us the ability to actually keep track of when this script is being used as well.
5:05 So within the script, we can put various different bits of debug information, uh, so we can actually keep track of what's happening.
5:12 So, again, we can either create a new megascript instance based on the megascript we've created, or we can edit one that I've previously created.
5:22 All we need to do in this particular case is say that it needs to be enabled and it needs to run on an event.
5:28 So this will be when a certain event is hit, the script will run. need to do to get this to work is to create some reference mappings between elements that we've got in our script and our actual delivery methods.
5:45 So they actually display during our checkout process. So for this, I'm going to go to our delivery method screen. There's other information in the Infigo Academy on how to, uh, utilize delivery methods like this.
5:59 But in this particular case, all I've done is created three new delivery methods using this add new button up here.
6:06 And all I've specified is the name. And I can give that whatever name I like. The critical element here is that we need to actually reference it against something which is in our script.
6:17 So I can just go to this connect link button here. Select the connect plugin that I want to link it with, which in this case is connect scripting.
6:27 and then put the external ID that we specified in our script. So in this case they're called good can collect international shipping and you can pay standard shipping.
6:37 Those are named within our script. And I'm just going to put them as external references in here. Okay, and that should be all we need to do to actually configure that.
6:47 Of course the, the bulk of the work comes in actually writing the script itself. Uh, we do have a lot of mega script documentation available to assist you in writing those.
6:57 Uh, I'll. Put the example scripts I'm using in the tutorial page as well, just so you can use it for reference.
7:04 Uh, but let's have a look at this in action. So all I'm going to do is go and impersonate one of my customers.
7:11 And then go to my basket. Now you remember there are different options that we had available to do what to do with the shipping address.
7:23 So first, let's try a UK shipping address. and continue and then here you can see that when we get to the delivery method step I've only got two available out of the three I've got our permanent click and Quebec option.
7:39 And I've got our UK standard shipping option because it's recognised it as a UK address. You can also see that it's updated the price, some data the descriptions and as we can see down here the, delivery days offset.
7:54 So when we can actually be expected to be delivered is changing based on that selection as well. Now if I go back and change that to an international dress.
8:07 We can see it's now recognising that it's not a UK address, so it's hiding that option completely and instead it's showing us our international option, which has, slightly different configurations.
8:17 So again, that's a very specific option for a very specific script, but it's showing you the kind of things that it's capable of doing.
8:25 Now, this scripting capability can provide immense flexibility. So, you can implement static shipping rules directly within your mega scripts. You can also integrate seamlessly with third party APIs, so things like easy posts, for example, to pull real time shipping rates.
8:44 Now, of course, we do have third party integrations already. We do have integrations with easy posts. Would you have integrations with PrintIQ?
8:52 This is just another option that's available for you. especially if you have that knowledge and that capability to write these custom scripts and of course if you have that module available.
9:03 by using the Connect Scripting plugin, you gain complete control over your shipping options at checkout. Whether using custom static rules or dynamic external integrations.
9:15 So with accurate real time synchronization, your customers benefit from- Clear precise shipping costs and options that are available to

Incomplete
Step by Step Guide

Using the Connect Scripting Plugin in Infigo for Shipping Control


1. Introduction to Connect Scripting Plugin 0:00

generated-image-at-00:00:00

  • Overview of the video purpose: controlling shipping rates and methods during checkout.

  • Dynamic shipping options can be set up through code.

  • Access to the Connect Scripting module is required.


2. Accessing the Connect Scripting Module 0:10

generated-image-at-00:00:10

  • Reminder to contact your Customer Success Manager if you need access to the module.


3. Shipping Plugin Endpoint Support 0:37

generated-image-at-00:00:37

  • The Scripting plugin now supports the Shipping Plugin Endpoint for custom shipping integrations.

  • Use Megascript code for flexibility in defining shipping rules.


4. Data Access During Checkout 1:07

generated-image-at-00:01:07

  • The scripting integration provides access to essential data:

    • Cart details

    • Checkout attributes

    • User information

    • Shipping and billing addresses.


5. Returning Shipping Option Information 1:20

generated-image-at-00:01:20

  • Script execution returns detailed shipping options:

    • Method name/label

    • Unique codes for mapping

    • Price information

    • Descriptors and CSS classes for customization

    • Delivery offset days.


6. Example Setup 1:44

generated-image-at-00:01:44

  • Walkthrough of a simple example on a storefront.

  • Navigate to Connect Settings and ensure the Connect Scripting plugin is enabled.


7. Configuring the Megascript 2:04

generated-image-at-00:02:04

  • Go to the Connect Plugin screen and configure the Connect Scripting option.

  • Select the 'get shipping options' action.


8. Creating or Editing a Megascript 2:56

generated-image-at-00:02:56

  • Access the Megascript management screen to create or edit a Megascript.

  • Input a simple example Megascript using static information.


9. Defining Shipping Options 3:37

generated-image-at-00:03:37

  • Example shipping options:

    • UK Standard Shipping (for UK addresses)

    • International Shipping (for non-UK addresses)

    • Click and Collect (always available, free rate).


10. Saving the Megascript 4:50

generated-image-at-00:04:50

  • Ensure the Megascript is saved before proceeding.


11. Creating a Megascript Instance 5:05

generated-image-at-00:05:05

  • Create or edit a Megascript instance to ensure the script runs at the appropriate event.


12. Mapping Delivery Methods 5:45

generated-image-at-00:05:45

  • Create reference mappings between script elements and delivery methods.

  • Use the delivery method screen to add new delivery methods.


13. Linking Delivery Methods to the Script 6:06

generated-image-at-00:06:06

  • Specify names and link them to the Connect Scripting plugin using external IDs from the script.


14. Testing the Setup 7:04

generated-image-at-00:07:04

  • Impersonate a customer and test the checkout process with different shipping addresses.


15. Observing Shipping Options in Action 7:23

generated-image-at-00:07:23

  • Check available shipping options based on the input address (UK vs International).

  • Observe price updates and delivery days offset.


16. Flexibility of Scripting Capability 8:25

generated-image-at-00:08:25

  • Discuss the flexibility of implementing static rules or integrating with third-party APIs for real-time rates.


17. Conclusion 9:03

generated-image-at-00:09:03

  • Emphasize the control gained over shipping options at checkout using the Connect Scripting plugin.

Link to Loom

https://loom.com/share/8da465d4655f47198755116266e8dfe2

Sample Script

/* ------------------------------------------------------------------
   Get Shipping Options – Country-Based Example MegaScript
   ------------------------------------------------------------------
   • Uses only:
       1. Run.CurrentContext.Event.Parameter.ShippingAddress
       2. Run.Customers.GetCustomerCheckoutAttributes (optional)
   • Returns:
       – UK Standard Shipping
       – International Shipping
-------------------------------------------------------------------*/

// 1. Enable run-log entries & debug level
Run.AddRunLogEntry = true;
Logger.SetLogLevel(LogLevel.Debug);
Logger.LogInfo("Starting Country-Based Shipping Options script");

// 2. Grab the shipping address
var shippingAddress = Run.CurrentContext.Event.Parameter.ShippingAddress || {};
Logger.LogDebug("Shipping country: " + shippingAddress.Country);

// 3. (Optional) fetch checkout attributes if you want to use them
var customer       = Run.CurrentContext.Event.Parameter.Customer;
var checkoutAttrs  = Run.Customers.GetCustomerCheckoutAttributes(customer);
Logger.LogDebug("Fetched checkout attributes XML: " + checkoutAttrs);

// 4. Build the ShippingOptions array
var shippingOptions = [];

// 4a. UK Standard Shipping
if (shippingAddress.Country === "GB") {
    shippingOptions.push({
        Rate: 4.5,
        Name: "UK Standard Shipping",
        Code: "Mis.Scripting__uk_standard",
        CssClass: "shipping-uk",
        AdditionalInformation: "2-4 working days within the UK",
        DeliveryDaysOffset: 3,
        RatedShipmentWarnings: []
    });
}
// 4b. International Shipping
else {
    shippingOptions.push({
        Rate: 15,
        Name: "International Shipping",
        Code: "Mis.Scripting__intl",
        CssClass: "shipping-intl",
        AdditionalInformation: "5-10 working days worldwide",
        DeliveryDaysOffset: 7,
        RatedShipmentWarnings: []
    });
}

// 5. Always add a “Click and Collect” fallback
shippingOptions.push({
    Rate: 0,
    Name: "Click and Collect",
    Code: "Mis.Scripting__pickup",
    CssClass: "shipping-pickup",
    AdditionalInformation: "Free — pick up in store",
    DeliveryDaysOffset: 0,
    RatedShipmentWarnings: []
});

// 6. Return results
var result = Run.CurrentContext.Event.Result;
result.Success         = true;
result.ExternalId      = null;
result.ShippingOptions = shippingOptions;

// 7. Final log
Logger.LogInfo(
  "Finished script; returned " + shippingOptions.length + " options"
);

Alternate Search Terms

custom shipping integration script, dynamic shipping rate scripting, configure shipping methods via code, set shipping rules with Megascript, programmatic checkout shipping options, Connect Scripting shipping tutorial, shipping plugin endpoint guide, Infigo custom shipping rates, real-time shipping rate integration, conditional free shipping script