NAV

Get Storefront Details

Get basic storefront information to use in your script.

Ecwid.getStaticBaseUrl

Get Static Base Url code example

var StaticBaseUrl = Ecwid.getStaticBaseUrl()

console.log(StaticBaseUrl)

// prints
// "https://d3fi9i0jj23cau.cloudfront.net/gz/"

Returns the base URL for static Ecwid files, like images and CSS, with the ’/’ at the end.

Ecwid.getOwnerId

Get store ID code example

var storeId = Ecwid.getOwnerId()

console.log(storeId);

// prints
// 1003

Returns the store ID.

Ecwid.getInitializedWidgets

Get all widgets to be displayed when page loads

var widgets = Ecwid.getInitializedWidgets();

console.log(widgets);

// prints 
// ["Minicart", "SearchPanel", "ProductBrowser"]

Returns array containing widget types present on a page. There are four types available:

  • Minicart - Minicart widget
  • SearchPanel - Search widget
  • ProductBrowser - Storefront widget
  • Categories - Categories widget
  • SingleProduct - Embedded product (old version)
  • Product - Embedded product (latest version)

Ecwid.formatCurrency

Format a number using currency format of a store

var currencyFormat = Ecwid.formatCurrency(12.99)

console.log(currencyFormat)

// prints
// "$12.99"

Converts the given currency value to a human-readable string according to the store settings. It accepts both string and integer as arguments.

Ecwid.getStorefrontLang

var lang = Ecwid.getStorefrontLang();

console.log(lang);

//prints
// "en"

Get current language of storefront. The function is available as soon as Ecwid store starts to load.

Ecwid.getAppPublicConfig

Get app public config function usage

Ecwid.getAppPublicConfig(appId);

Example values from app publc config

  {
    "key": "public",
    "value": "12345"
  }

Get app public config code example

  var pageId = Ecwid.getAppPublicConfig("my-cool-app");

  console.log(pageId);
  // prints 
  // '12345'

Returns value for public key from Ecwid Application Storage endpoint.

Ecwid.getAppPublicConfig() receives one argument:

NameTypeDescription
appIdStringNamespace of your application (as set in the application settings).

Ecwid.getAppPublicToken

Get app public config function usage

Ecwid.getAppPublicToken(appId);

Get app public token code example

var publicToken = Ecwid.getAppPublicToken('my-cool-app');

console.log(publicToken);

// 'public_qKDUqKkNXzcj9DejkMUqEkYLq2E6BXM9'

Returns public applicaiton token for an Ecwid store. In order for this function to work, your app has to ask for public_storefront scope from a store. Learn more

Ecwid.getAppPublicToken() receives one argument:

NameTypeDescription
appIdStringNamespace of your application (as set in the application settings).

Ecwid.getFeatureToggles

var ecwidFeatureTogglesInfo = Ecwid.getFeatureToggles();

console.log(ecwidFeatureTogglesInfo);

// {
//  newProductList: false, 
//  newDetailsPage: false
// }

Ecwid.getFeatureToggles() function returns enabled or disabled storefront features we released over the years and just recently.

Returned fields:

NameTypeDescription
newProductListbooleantrue if new product listing is enabled in a store. false otherwise
newDetailsPagebooleantrue if new product details page is enabled in a store. false otherwise

Page Object

Describes the page displaying inside the product browser.

Get page type after new page is loaded

Ecwid.OnPageLoaded.add(function(page){
  console.log("Current page is of type: " + page.type);
})

// prints
// Current page is of type: CATEGORY

Fields:

NameTypeDescription
typestring, one of the following: ‘ACCOUNT_SETTINGS’, ‘ADDRESS_BOOK’, ‘ORDERS’, ‘CATEGORY’, ‘CART’, ‘CHECKOUT_ADDRESS_BOOK’, ‘CHECKOUT_PAYMENT_DETAILS’, ‘CHECKOUT_PLACE_ORDER’, ‘CHECKOUT_SHIPPING_ADDRESS’, ‘ORDER_CONFIRMATION’, ‘ORDER_FAILURE’, ‘CHECKOUT_RESULT’, ‘DOWNLOAD_ERROR’, ‘PRODUCT’, ‘SEARCH’, ‘FAVORITES’, 'RESET_PASSWORD’The type of the page. Some pages may have parameters like for example product id of the viewing product. Those parameters are described below.
keywordsstring, optionalfor type==’ORDERS’: the keywords that are used to find orders in the customer account page. for type==’SEARCH’: the keywords that are used to find products on the product search page.
frominteger timestamp, optionalfor type==’ORDERS’: The timestamp of the start of the orders date range.
tointeger timestamp, optionalfor type==’ORDERS’: The timestamp of the end of the orders date range.
offsetfor type==’ORDERS’: the position of the current order list page (starting from 0). for type==’CATEGORY’ and SEARCH’: the position of the current product list page (starting from 0).
categoryIdintegerfor type==’CATEGORY’: the id of the showing product category or 0 if this is the starting page of the catalog and no categories are selected yet. for type==’PRODUCT’: the category internal id the current product has been navigated from. Zero (0) is the root category, −1 meaning that the category is unknown (e.g. a product opened from a search result).
mainCategoryIdintegerfor type==’PRODUCT’ in the OnPageLoaded event: the internal id of category that is considered the default category of this product (in case if the product is assigned to a few different categories). If a product is assigned to a single category, mainCategoryId will be equeal to categoryId; if a product is not assigned to any category, its mainCategoryId is 0 (zero). for type==’PRODUCT’ in the OnPageLoad event: always 0 (zero);
sortstring, one of: ‘normal’, ‘addedTimeDesc’, ‘priceAsc’, ‘priceDesc’, ‘nameAsc’, ‘nameDesc’for type==’CATEGORY’ and ’SEARCH’: the order of the product list, as selected by the user in the ‘sort by’ drop-down. ‘Desc’ suffix stands for the descending order, ‘Asc’ suffix stands for the ascending order.
orderIdintegerfor type==’CHECKOUT_RESULT’ and type==’ORDER_CONFIRMATION’: the internal id of the order (not to be confused with the store order number)
ticketintegerfor type==’CHECKOUT_RESULT’: the security random code that allows to retrieve information about the order
errorTypeone of the following: ‘expired’, ‘invalid’, ‘limit’for type==’DOWNLOAD_ERROR’: the type of the error while downloading an e-good file.
keyinteger, optionalfor type==’DOWNLOAD_ERROR’: the downloading file internal id
productIdintegerfor type==’PRODUCT’: the internal id of the displaying product (not to be confused with SKU).
orderNumberintegerfor type==’ORDER_CONFIRMATION’ the number of the order placed by customer(without prefix and suffix).
vendorOrderNumberstringfor type==’CHECKOUT_RESULT’ and type==’ORDER_CONFIRMATION’ the number of the order placed by customer(with prefix and suffix).

Ecwid.setStorefrontBaseUrl

Set storefront base URL to a custom URL after store is loaded

Ecwid.setStorefrontBaseUrl('https://www.ecwid.com/demo/?ipad&lang=en');

Dynamically updates storefront base URL.

Typically is used for SEO URLs feature to preserve dynamically added query parameters in a page URL. Works similarly to window.ec.config.baseUrl method.