> For the complete documentation index, see [llms.txt](https://docs.stoqapp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stoqapp.com/preorder-metafields/market-level-product-variant-metafields.md).

# Market level product variant Metafields

This document outlines the structure and usage of market-specific metafields for product variants. These metafields enable market-specific order limit tracking, and shipping information display.

### 1. Market Preorder Count Metafield

#### Configuration

* **Key**: `market_preorder_count`
* **Type**: `json`
* **Namespace**: `restockrocket_production`
* **Owner**: Product Variant

#### Purpose

* Tracks the current number of preorders for a variant per market
* Used for market-specific inventory management
* Automatically updated when orders are processed in different markets
* Stored as a JSON object mapping market IDs to counts

#### Accessing in Liquid

```liquid

{% assign market_preorder_count = product_variant.metafields.restockrocket_production.market_preorder_count.value | json %}
```

```
Example value of market_preroder_count =>
{ 
  "market_id_1": 1,
  "market_id_2": 5,
  "market_id_3": 3
}
```

### 2. Market Preorder Max Count Metafield

#### Configuration

* **Key**: `market_preorder_max_count`
* **Type**: `json`
* **Namespace**: `restockrocket_production`
* **Owner**: Product Variant

#### Purpose

* Sets the maximum number of preorders allowed per market
* Controls market-specific inventory policy switching
* Triggers blocking orders when count reaches max in specific markets
* Stored as a JSON object mapping market IDs to maximum counts

#### Accessing in Liquid

```liquid

{% assign market_preorder_max_count = product_variant.metafields.restockrocket_production.market_preorder_max_count.value | json %}

```

```
Example value of market_preorder_max_count =>
{ 
  "market_id_1": 10,
  "market_id_2": 15,
  "market_id_3": 10
}
```

#### Example Usage: Market-Specific Preorder Count and Max Count

```liquid
{% assign variant = product.selected_or_first_available_variant %}
{% assign market_counts = variant.metafields.restockrocket_production.market_preorder_count.value | json %}
{% assign market_max_counts = variant.metafields.restockrocket_production.market_preorder_max_count.value | json %}
{% assign current_market = shop.market.id %}

{% if market_max_counts[current_market] %}
  {% assign current_count = market_counts[current_market] %}
  {% assign max_count = market_max_counts[current_market] %}
  {% assign spots_remaining = max_count | minus: current_count %}

  {% if spots_remaining > 0 %}
    <div class="preorder-availability">
      <span class="spots-left">{{ spots_remaining }} spots remaining in your market</span>
      {% if spots_remaining < 5 %}
        <span class="low-stock-warning">Almost sold out in your region!</span>
      {% endif %}
    </div>
  {% else %}
    <div class="preorder-full">
      Preorder limit reached for your market
    </div>
  {% endif %}
{% endif %}
```

### 3. Market Shipping Text Metafield

#### Configuration

* **Key**: `market_shipping_text`
* **Type**: `json`
* **Namespace**: `restockrocket_production`
* **Owner**: Product Variant

#### Purpose

* Stores market-specific shipping/delivery timeline text
* Allows different shipping information per market
* Stored as a JSON object mapping market IDs to shipping text

#### Accessing in Liquid

```liquid
{% assign market_shipping_text = product_variant.metafields.restockrocket_production.market_shipping_text.value | json %}
```

```
Example value of market_shipping_text =>
{
  "market_id_1": "Ships in 1 week",
  "market_id_2": "Ships in 2 weeks",
  "market_id_3": "Ships in 4 days"
}
```

### Accessing via GraphQL

#### Query for Market-Specific Metafields

```graphql
{
  productVariant(id: "gid://shopify/ProductVariant/YOUR_VARIANT_ID") {
    metafields(
      namespace: "restockrocket_production",
      keys: ["market_preorder_count", "market_preorder_max_count", "market_shipping_text"]
    ) {
      edges {
        node {
          id
          key
          value
          type
        }
      }
    }
  }
}
```

#### Query for Multiple Variants with Market Data

```graphql
{
  product(id: "gid://shopify/Product/YOUR_PRODUCT_ID") {
    variants(first: 10) {
      edges {
        node {
          id
          title
          metafields(
            namespace: "restockrocket_production",
            keys: ["market_preorder_count", "market_preorder_max_count", "market_shipping_text"]
          ) {
            edges {
              node {
                id
                key
                value
                type
                # Example response for market_preorder_count:
                # value: {"market_id_1": 45, "market_id_2": 20, "market_id_3": 15}
                # Example response for market_preorder_max_count:
                # value: {"market_id_1": 100, "market_id_2": 50, "market_id_3": 30}
                # Example response for market_shipping_text:
                # value: {"market_id_1": "Ships in 2 weeks", "market_id_2": "Ships in 3 weeks", "market_id_3": "Ships in 4 weeks"}
              }
            }
          }
        }
      }
    }
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stoqapp.com/preorder-metafields/market-level-product-variant-metafields.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
