Main site

Built-in Modules > Syncee Class

Syncee Class

Important: This plugin relies on third-party resources. The resources might change or be discontinued without notice. Ensure you test the plugin extensively before production use, implement error handling with a try-catch block, have a backup shipping rate ready, and reach out to our support with detailed descriptions of any unexpected issues.

Overview

The Syncee class is designed to obtain real-time shipping rates for products from Syncee.

Class Definition

class Syncee {
  constructor(destination) {
    // Class constructor
  }

  async getRates(synceeProducts) {
    // Method to fetch rates
  }
}

Arguments

  • destination (Object): The "destination" data from the DATA JSON object used in the calculateShippingRates function.

Usage Example

const syncee = new Syncee(DATA.destination);
const synceeProducts = [
  { syncee_product_id: "197259_61772_7679369281762", quantity: 1 },
  { syncee_product_id: "302372_67382_4654296301681", quantity: 2 },
  // ... more products
];
const rates = await syncee.getRates(synceeProducts);

This example demonstrates the instantiation of the Syncee class with the required destination parameter. The getRates method then calculates shipping rates for an array of Syncee products, identified by syncee_product_id and quantity. The returned rates are presented in the same format used by Shopify's shipping rates.

The syncee_product_id is the last pathname of the Syncee product page url. For example, https://app.syncee.co/explore-products/products/197259_61772_7679369281762, the product id is 197259_61772_7679369281762.

The Syncee plug-in returns rates in USD currency. Use our built-in currency converter class Currency to convert to other currencies. Rates for undeliverable destination will return a null shipping price.

Sample AI Prompt

I'd like a shipping rate calculator for items from Syncee products.
Enrich the data with metafield namespace "market" with size 10.
The Syncee product id for each items is saved in the data items metafield "market" with key named "syncee_product_id".

Sample AI Output

import { enrichItemDetails } from "./modules.js";
import { Syncee } from "./modules.js";

export async function calculateShippingRates(DATA, env) {
  try {
    // Enrich data with metafield namespace "market" with size 10
    DATA = await enrichItemDetails(DATA, [{ namespace: "market", size: 10 }]);

    // Get Syncee products from items metafield "market" with key "syncee_product_id"
    const synceeProducts = DATA.items.map((item) => {
      const synceeProductId = item.metafields.market.find(
        (metafield) => metafield.key === "syncee_product_id"
      )?.value;
      return { syncee_product_id: synceeProductId, quantity: item.quantity };
    });

    // Create a new instance of Syncee with destination data
    const syncee = new Syncee(DATA.destination);

    // Get shipping rates from Syncee
    const rates = await syncee.getRates(synceeProducts);

    // Return shipping rates in Shopify format
    return { rates };
  } catch (error) {
    // Return error rate
    return {
      rates: [
        {
          service_name: "",
          service_code: "",
          total_price: null,
          description: "",
          currency: "",
          min_delivery_date: "",
          max_delivery_date: "",
        },
      ],
    };
  }
}