Shopify function delivery customization cart variant inventory info

What i want to do:

  1. on checkout page, based on the inventory quatity of product variant to determin if the ‘fast shipping‘ method show/hide. (low quatity → hide the ‘fast shpping‘ shipping method, high quatity → no changes)

but it seems to be impossible:

  1. based on what i’ve known, we can’t use external network request at shopify function(rust), if it’s possible, i will query the quatity of product variant sku for logic
  2. The input of Delivery Customization graphql: Delivery Customization Function API can’t retrive the cart line item product variant inventory quatity info

so what should i do to get the variant inventory quatity at checkou page for Delivery Customization ?

As you mentioned, its not possible to make network requests (without being on Enterprise), I’d suggest maybe storing the inventory data against a variant metafield which you can then access in the input.

Potentially setup a flow to keep this in sync.

@Luke i did what you say, but i met another problem, i just hide one shipping method in function, but the frontend page shows ‘Shipping not available

Your order cannot be shipped to the selected address. Review your address to ensure it’s correct and try again, or select a different address.‘

here is the detail of my function(input,output,logs) & shipping configuration at shopify admin dashboard:

Customer Context:

Shipping Address: United States, NY

Function Context:

  1. the part of rust code about how to call hide function:

  1. input:

{
  "cart": {
    "deliveryGroups": [
      {
        "id": "gid:\/\/shopify\/CartDeliveryGroup\/0",
        "deliveryAddress": {
          "countryCode": "US",
          "provinceCode": "NY"
        },
        "deliveryOptions": [
          {
            "handle": "d7ac0988951ed0a4431d71a5c511f671-69723fff8c227e1a0225fd0632a536be",
            "title": "Standard Shipping (3-7 Day)",
            "code": "Standard Shipping (3-7 Day)"
          },
          {
            "handle": "d7ac0988951ed0a4431d71a5c511f671-5e337d31cad8c5095325215cdec9a558",
            "title": "Expedited 2-Day Shipping",
            "code": "Expedited 2-Day Shipping"
          }
        ]
      }
    ],
    "lines": [
      {
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid:\/\/shopify\/ProductVariant\/50175777931554",
          "sku": "TP201",
          "metafield": {
            "value": "{\"CN_GD\":87,\"US_NY\":10}"
          }
        },
        "quantity": 11
      }
    ]
  },
  "deliveryCustomization": {
    "metafield": {
      "value": "eyJjYXJ0X29iamVjdCI6MSwiY29uZGl0aW9uX29wZXJhdG9yIjoxLCJjb25kaXRpb25fdmFsdWUiOi0xLCJhY3Rpb25fdHlwZSI6MSwiYWN0aW9uX3RhcmdldF9vcGVyYXRvciI6MSwiYWN0aW9uX3RhcmdldF9wYXR0ZXJuIjoiRXhwZWRpdGVkIDItRGF5IFNoaXBwaW5nIn0="
    }
  }
}
  1. output:
{
  "operations": [
    {
      "deliveryOptionHide": {
        "deliveryOptionHandle": "d7ac0988951ed0a4431d71a5c511f671-5e337d31cad8c5095325215cdec9a558"
      }
    }
  ]
}

Shopify Admin Dashboard Context:

Now what i’m confirmed info:

  1. the product quantity i purchased is < my location quatity
  2. my function works fine
  3. i’ve looked into my rust code(print more debug log), it just hide the ‘Expedited 2-Day Shipping‘, didn’t change any other shipping method

What I expect:

it should display ‘Standard Shipping (3-7 Day) - Free‘ Shipping method at custmer checkout page, why it shows nothing ?