Skip to content

Instantly share code, notes, and snippets.

@matheusgnreis
Last active April 15, 2024 13:39
Show Gist options
  • Save matheusgnreis/2d509bbb78f09040d7023807378fe206 to your computer and use it in GitHub Desktop.
Save matheusgnreis/2d509bbb78f09040d7023807378fe206 to your computer and use it in GitHub Desktop.

Products Props

Object: window._context

Overview

The window._context object represents product-related information stored within the JavaScript environment of the current browser session. It encapsulates essential details about a specific product listed on the page, such as its attributes, pricing, availability, and metadata.

Properties

resource (String)

  • Specifies the type of resource this object represents, which in this case is "products".

body (Object)

  • Contains the main data related to the product.

Body object

_id (String)
  • The unique identifier for this product.
sku (String)
  • Stock Keeping Unit (SKU) code for the product.
name (String)
  • The name or title of the product.
meta_title (String)
  • The SEO meta title of the product.
meta_description (String)
  • The SEO meta description of the product.
price (Number)
  • The price of the product in the specified currency (BRL).
cost_price (Number)
  • The cost price of the product.
dimensions (Object)
  • The physical dimensions of the product.

    • width (Object)
      • unit: Unit of measurement (cm). Can be m, mm or others, by default is cm
      • value: Width value.
    • height (Object)
      • unit: Unit of measurement (cm).
      • value: Height value.
    • length (Object)
      • unit: Unit of measurement (cm).
      • value: Length value.
weight (Object)
  • The weight of the product.

    • unit: Unit of measurement (kg). Can be g, dm or others, by default is cm
    • value: Weight value.
variations (Array)
  • Variations of the product (e.g., color, size).

    Array of product variations.

    Each variation object contains:

      `_id` (String): Unique identifier for the variation.
    
      `name` (String): Name of the variation.
    
      `sku` (String): Stock Keeping Unit (SKU) code for the variation.
    
      `quantity` (Number): Available quantity of this variation.
    
      `specifications` (Object): Specifications of the variation.
          `size (Array): Array containing size`or any grade specifications.
            
            `text`: Variation text.
            `value`: Variation value. **Obs**: Only in colors variation, the value must be the color in hexadecimal.
    
quantity (Number)
  • The available quantity of the product in stock.
keywords (Array)
  • Keywords associated with the product.
brands (Array)
  • Array of brands associated with the product.

categories (Array)

Array of categories to which the product belongs.

Each category object contains:
    `_id` (String): Unique identifier for the category.
    `name` (String): Name of the category.
    `slug` (String): slug of the category.
specifications (Object)
  • Detailed specifications of the product.
commodity_type (String)
  • Type of commodity (physical).
available (Boolean)
  • Indicates whether the product is available for purchase (true) or not (false).
visible (Boolean)
  • Indicates whether the product is visible (true) or hidden (false).
pictures (Array)
  • Array of images representing the product.
updated_at (String)
  • Date and time when the product information was last updated.
created_at (String)
  • Date and time when the product was created.
inventory_records (Array)
  • Records of inventory associated with the product.

Example Usage

// Accessing product details
const productName = window._context.body.name;
const productPrice = window._context.body.price;
const productDescription = window._context.body.body_html;

// Checking availability
const isAvailable = window._context.body.available;

// Accessing product dimensions
const productDimensions = window._context.body.dimensions;

// Retrieving product pictures
const productPictures = window._context.body.pictures;

// Viewing brand information
const productBrand = window._context.body.brands[0].name;

Notes

  • Ensure that the window._context object is properly initialized and contains valid data before accessing its properties.
  • The structure and contents of window._context may vary based on the specific implementation and requirements of the product page.

This documentation outlines the structure and key properties of the window._context object, providing a clear understanding of the product-related data it encapsulates. Adjustments can be made based on actual observations and requirements specific to your implementation. If you have any further questions or need additional clarification on specific properties, please feel free to ask!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment