Localized Stock

Enables Dynamic Yield recommendations to return only products that are available in the branch where the user is shopping

Prerequisites

Before implementing the Localized Stock extension, make sure that:

  • The Dynamic Yield account team has enabled the extension
  • Your section has a branches feed configured
  • Your product feed is synced via API

Update the product feed

Add the out_of_stock_branches field to your product feed.

The field should contain a pipe-delimited list of branch IDs where the item (SKU) is unavailable.

Example:

{
  "id": "abc-123",
  "action": "update",
  "body": {
    "data": {
      "sku": "abc-123",
      "group_id": "abc",
      "url": "http://www.example.com/abc-123",
      "name": "white sneakers",
      "price": 29.99,
      "in_stock": true,
      "out_of_stock_branches": "branchId1|branchId2",
      "image_url": "http://www.example.com/abc-123.png",
      "categories": "shoes|sneakers"
    }
  }
}

Inventory reporting rules

If a product is available in at least one branch:

  • Set in_stock to true
  • List unavailable branches in out_of_stock_branches

If a product is unavailable in all branches:

  • Set in_stock to false
  • Leave out_of_stock_branches empty

Example:

{
  "in_stock": false,
  "out_of_stock_branches": ""
}

Send the branch context

Recommendation requests must include the current branch ID.

Experience APIs

Include the branch ID in context.branch.id in your Choose request.

{
  "context": {
    "page": {
      "type": "HOMEPAGE",
      "location": "https://shop.example.com"
    },
    "branch": {
      "id": "branch1233"
    }
  }
}

Client-side implementation

Include the branchId parameter in DY.recommendationContext.

window.DY = window.DY || {};

DY.recommendationContext = {
  type: "PRODUCT",
  data: ["SKU123"],
  branchId: "3075749"
};

Requirements and limitations

  • Branch IDs must exist in your branches feed
  • Branch IDs cannot exceed 15 characters
  • Supports up to 1,500 branches

If a branch ID exceeds 15 characters, API logs report the error as "invalid store id" with no further specification.


Did this page help you?