Main site

Built-in Modules > VidaXL Class

VidaXL 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 VidaXL class is crafted to fetch real-time shipping rates for products from VidaXL.

Class Definition

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

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

Arguments

  • destination (Object): This parameter corresponds to the "destination" data within the input DATA JSON object used by the calculateShippingRates function.

Usage Example

const vidaxl = new VidaXL(DATA.destination);
const vidaxlProducts = [
  { vidaxl_logistic_weight: 45, quantity: 1 },
  { vidaxl_logistic_weight: 34, quantity: 1 },
  // ... further products
];
const rates = await vidaxl.getRates(vidaxlProducts);

The usage example illustrates initializing the VidaXL class with destination details. The getRates method then computes shipping rates for an array of VidaXL products, with their vidaxl_logistic_weight (in kilograms) and the quantity of each. The resulting rates are presented in the same format as Shopify's shipping rates.

Sample AI Prompt

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

Sample AI Output

import { enrichItemDetails } from "./modules.js";
import { VidaXL } 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 vidaXL products from the items
    const vidaXLProducts = DATA.items
      .filter((item) => item.metafields?.market?.vidaxl_logistic_weight)
      .map((item) => ({
        vidaxl_logistic_weight: item.metafields.market.vidaxl_logistic_weight,
        quantity: item.quantity,
      }));

    // Get shipping rates from VidaXL
    const vidaxl = new VidaXL(DATA.destination);
    const rates = await vidaxl.getRates(vidaxlXLProducts);

    // 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: "",
        },
      ],
    };
  }
}