Articles on: API

Preorder Metafields Documentation

Overview


This document details the metafields used in the preorders system, explaining how they are structured and their relationships with shops and product variants. An important note here is that preorder offers on our dashboard are called selling plans in our backend system.

Shop Level Metafields



1. Selling Plans Metafield


Configuration
- Key: selling_plans
- Type: json
- Namespace: restockrocket_production
- Owner: Shop

Purpose
Stores the complete configuration of all enabled selling plans (preorder offers) for a shop.

Fields
{
  "shopify_selling_plan_group_id": "string",  // Unique identifier for the selling plan group in Shopify
  "shopify_selling_plan_id": "string",        // Unique identifier for the specific selling plan in Shopify
  "enabled": boolean,                         // Whether the selling plan is active
  "variant_ids": ["string"],                 // List of product variant IDs associated with this plan
  "name": "string",                          // Display name of the selling plan
  "preorder_button_text": "string",          // Text shown on the preorder button
  "preorder_button_description": "string",    // Description shown below the preorder button
  "preorder_button_description_background_color": "string",  // Background color of the description box
  "preorder_button_description_text_color": "string",        // Text color of the description
  "preorder_button_description_border_radius": "number",     // Border radius of the description box
  "preorder_button_description_show_quantity_limit": boolean,  // Whether to show quantity limits
  "preorder_button_description_quantity_limit_suffix": "string",  // Text after quantity limit
  "preorder_button_description_shipping_text_prefix": "string",   // Text before shipping info
  "delivery_exact_time": "string",           // Exact time of delivery
  "quantity_limit_text": "string",           // Text explaining quantity limitations
  "preorder_button_description_show_shipping": boolean,  // Whether to show shipping info
  "preorder_shipping_text": "string",        // Shipping information for preorder items
  "shipping_applies_to_all_products": boolean,  // Whether shipping settings are global
  "shipping_text": "string",                 // General shipping information
  "payment_type": "string",                  // Type of payment (full/partial)
  "billing_checkout_charge_type": "string",  // How the charge is calculated
  "billing_checkout_charge_amount": "number", // Fixed amount for checkout charge
  "billing_checkout_charge_percentage": "number",  // Percentage amount for checkout
  "pricing_type": "string",                  // Type of pricing adjustment
  "pricing_amount": "number",                // Fixed amount for pricing
  "pricing_percentage": "number",            // Percentage for pricing
  "discount_text": "string",                 // Text explaining discounts
  "billing_title": "string",                 // Title for billing information
  "billing_description": "string",           // Detailed billing information
  "enable_billing_widget": boolean,          // Whether to show billing widget
  "inventory_provider": "string",            // Provider handling inventory
  "preorder_badge_enabled": boolean,         // Whether to show preorder badge
  "preorder_badge_text": "string",           // Text shown on the badge
  "preorder_badge_text_color": "string",     // Color of badge text
  "preorder_badge_background_color": "string",  // Background color of badge
  "translations": {                          // Translations for multilingual support
    "locale_code": {
      "shipping_text": "string",
      "billing_title": "string",
      "billing_description": "string",
      "discount_text": "string",
      "preorder_badge_text": "string",
      "preorder_button_description": "string",
      "quantity_limit_text": "string",
      "preorder_shipping_text": "string",
      "preorder_button_text": "string"
    }
  }
}


Accessing in Liquid
{% assign current_variant_id = product.selected_or_first_available_variant.id %}
{% assign selling_plans = shop.metafields.restockrocket_production.selling_plans.value %}
  
{% for plan in selling_plans %}
  {% if plan.enabled %}
    {% assign variant_ids = plan.variant_ids %}
    {% if variant_ids contains current_variant_id %}
      {% comment %}
        This variant is part of the selling plan
        You can now access plan details:
      {% endcomment %}
  
      <div class="preorder-button" style="background-color: {{ plan.preorder_badge_background_color }}">
        <span style="color: {{ plan.preorder_badge_text_color }}">
          {{ plan.preorder_badge_text }}
        </span>
      </div>
  
      {% if plan.preorder_button_description_show_quantity_limit %}
        {% assign preorder_count = product.selected_or_first_available_variant.metafields.restockrocket_production.preorder_count | default: 0 %}
        {% assign preorder_max_count = product.selected_or_first_available_variant.metafields.restockrocket_production.preorder_max_count %}
  
        {% if preorder_max_count %}
          {% assign remaining = preorder_max_count | minus: preorder_count %}
          <div class="quantity-limit">
            {{ remaining }}{{ plan.preorder_button_description_quantity_limit_suffix }}
          </div>
        {% endif %}
      {% endif %}
    {% endif %}
  {% endif %}
{% endfor %}


Example: Working with Delivery Times
{% assign current_variant_id = product.selected_or_first_available_variant.id %}
{% assign selling_plans = shop.metafields.restockrocket_production.selling_plans.value %}

{% for plan in selling_plans %}
  {% if plan.enabled %}
    {% assign is_variant_in_plan = false %}
    {% for variant_id in plan.variant_ids %}
      {% if variant_id == current_variant_id %}
        {% assign is_variant_in_plan = true %}
        {% break %}
      {% endif %}
    {% endfor %}

    {% if is_variant_in_plan and plan.delivery_exact_time %}
      {% assign delivery_date = plan.delivery_exact_time | date: '%Y-%m-%d' | date: '%s' %}
      {% assign today_date = 'now' | date: '%Y-%m-%d' | date: '%s' %}
      {% assign seconds_diff = delivery_date | minus: today_date %}
      {% assign days_until_delivery = seconds_diff | divided_by: 86400 %}

      <div class="delivery-info">
        <h4>Delivery Information</h4>

        {% if days_until_delivery > 0 %}
          <p class="estimated-delivery">
            Estimated delivery: {{ plan.delivery_exact_time | date: '%B %d, %Y' }}
            <span class="days-left">({{ days_until_delivery }} days left)</span>
          </p>

          {% if plan.preorder_shipping_text %}
            {% assign formatted_date = plan.delivery_exact_time | date: '%B %d, %Y' %}
            {% capture date %}{{ formatted_date | escape }}{% endcapture %}
            <p class="shipping-note">
              {{ plan.preorder_shipping_text | url_escape | replace: "%7B%7B%20date%20%7D%7D", date | replace: "%20", " " }}
            </p>
          {% endif %}
        {% else %}
          <p class="delivery-soon">
            Delivery date approaching
          </p>
        {% endif %}
      </div>
    {% endif %}
  {% endif %}
{% endfor %}


Accessing via GraphQL
# Query to get shop selling plans metafield
{
  shop {
    metafield(namespace: "restockrocket_production", key: "selling_plans") {
      id
      namespace
      key
      value
      type
    }
  }
}

# Query to get multiple shop metafields at once
{
  shop {
    metafields(
      namespace: "restockrocket_production",
      first: 10
    ) {
      edges {
        node {
          id
          namespace
          key
          value
          type
        }
      }
    }
  }
}


This example demonstrates:
- Converting the delivery time to a readable format
- Calculating days remaining until delivery
- Displaying a formatted delivery date
- Replacing placeholders in shipping text
- Adding conditional styling based on delivery status
- Basic CSS styling for the delivery information

Product Variant Level Metafields



1. Preorder Count Metafield


Configuration
- Key: preorder_count
- Type: number_integer
- Namespace: restockrocket_production
- Owner: Product Variant

Purpose
- Tracks the current number of preorders for a specific variant
- Used for inventory management and display
- Automatically updated when orders are processed

Accessing in Liquid
{% assign preorder_count = product_variant.metafields.restockrocket_production.preorder_count %}


2. Preorder Max Count Metafield


Configuration
- Key: preorder_max_count
- Type: number_integer
- Namespace: restockrocket_production
- Owner: Product Variant

Purpose
- Sets the maximum number of preorders allowed for a variant
- Controls inventory policy switching
- Triggers blocking orders when count reaches max

Accessing in Liquid
{% assign preorder_max_count = product_variant.metafields.restockrocket_production.preorder_max_count %}


Example Usage: Preorder Count and Max Count
{% assign variant = product.selected_or_first_available_variant %}
{% assign preorder_count = variant.metafields.restockrocket_production.preorder_count.value | default: 0 %}
{% assign preorder_max = variant.metafields.restockrocket_production.preorder_max_count.value %}

{% if preorder_max %}
  {% assign spots_remaining = preorder_max | minus: preorder_count %}

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


Accessing via GraphQL
# Query to get metafields for a specific product variant
{
  productVariant(id: "gid://shopify/ProductVariant/YOUR_VARIANT_ID") {
    metafields(
      namespace: "restockrocket_production",
      first: 10
    ) {
      edges {
        node {
          id
          namespace
          key
          value
          type
        }
      }
    }
  }
}

# Query to get specific metafields for multiple variants of a product
{
  product(id: "gid://shopify/Product/YOUR_PRODUCT_ID") {
    variants(first: 10) {
      edges {
        node {
          id
          title
          metafields(
            namespace: "restockrocket_production",
            keys: ["preorder_count", "preorder_max_count", "shipping_text"]
          ) {
            edges {
              node {
                id
                key
                value
                type
              }
            }
          }
        }
      }
    }
  }
}


3. Shipping Text Metafield


Configuration
- Key: shipping_text
- Type: single_line_text_field
- Namespace: restockrocket_production
- Owner: Product Variant

Purpose
- Stores variant-specific shipping information
- Overrides global shipping text when present

Accessing in Liquid
{% assign shipping_text = product_variant.metafields.restockrocket_production.shipping_text %}

Updated on: 24/01/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!