跳到內容
安裝應用程式
繁體中文

JavaScript API - 網路商店

AI 概覽

說明 Globo Preorder 在您的佈景主題中提供的 JavaScript API,以及如何為自訂或更新後的佈景主題重新定義其選擇器。

  • 應用程式在您的佈景主題中載入後,即可透過 window.Globo.Preorder 使用此 API。
  • 變更款式後,呼叫 Globo.Preorder.initPreorder() 即可重新載入商品頁面上的預購表單。
  • 在 theme.liquid 的 </body> 之前加入指令碼,並使用 window.GloboPreorderParams.selectors 覆寫選擇器。
  • 表格列出每個選擇器鍵值、其類型、適用的頁面(購物車、商品、商品系列、快速檢視)以及指向的目標。

摘要由 AI 產生,可能有誤,請以下方完整指南為準。

Globo Preorder 提供 JavaScript API,可在您的 Shopify 佈景主題中進行自訂整合。當我們的應用程式載入到您的佈景主題時,即可透過 window.Globo.Preorder 物件存取此 API。

1. 全域變數

window.Globo.Preorder
// Use it with function app, after app loaded or window loaded
// Example reload preorder form in product page after variant change
// Use: Globo.Preorder.initPreorder();
window.GloboPreorderParams
// Defined selectors, classes, postion display

2. 定義選擇器 - 整合佈景主題

根據預設,應用程式會定義選擇器,以便在正確的位置正確顯示;不過,佈景主題可能有更新版本,或有應用程式尚未支援的自訂佈景主題。您可以使用變數 window.GloboPreorderParams 重新定義選擇器。

  • 前往 theme.liquid,在 </body> 之前新增 Javascript 程式碼
  • 在商品頁面覆寫選擇器 productAddToCartTextElement 的範例
<script>
window.GloboPreorderParams = window.GloboPreorderParams || {};
window.GloboPreorderParams.selectors = window.GloboPreorderParams.selectors || {};
window.GloboPreorderParams.selectors.productAddToCartTextElement = 'span[data-add-to-cart-text], .add-to-cart-text'; // class of the text element added to cart on product page
</script>

3 鍵值清單

window.GloboPreorderParams.selectors

鍵值類型頁面​定義
cartFormSelectorstring購物車購物車容器
cartRowSelectorstring購物車購物車品項列
cartElementHandlestring購物車商品 handle 元素,必須位於 cartRowSelector 元素內。
cartQuantitySelectorstring購物車商品數量容器,必須位於 cartRowSelector 元素內
cartInputQuantitySelectorstring購物車商品數量輸入欄位
cartPositionLimitMessagestring購物車顯示商品限購訊息的位置
cartProductParentSelectorstring購物車用於在購物車頁面顯示品項徽章。
cartProductTitleSelectorstring購物車用於在購物車頁面顯示品項徽章。
minusQuantitySelectorstring商品當輸入的數量達到上限時,停用數量減少按鈕的點擊
addQuantitySelectorstring商品當輸入的數量達到上限時,停用數量增加按鈕的點擊
productDetailSelectorstring商品商品詳情容器
productDetailImagesSelectorstring商品商品詳情圖片選擇器
productImageSelectorsarrayproduct collection 商品圖片選擇器
pricePositionSelectorsstring商品顯示預購標籤的商品價格位置
priceSelectorsstring商品商品價格外層容器
productFormarray商品商品加入購物車的表單動作
paymentButtonstring商品付款按鈕選擇器
productVariantActivatorstring商品商品子類選擇器,新增 click、change 事件監聽器並重新渲染預購狀態
variantSelectorstring商品商品子類 ID 選擇器 [name="id"]
productQuantityWrapperSelectorstring商品商品數量外層容器,用於顯示限購訊息
productQuantitySelectorstring商品數量輸入欄位選擇器
productAddToCartSelectorstring商品加入購物車按鈕選擇器,
productAddToCartBtnarray商品、快速檢視加入購物車按鈕
productAddToCartTextElementstring商品、快速檢視加入購物車文字
spinnerAtcElementstring商品隱藏商品加入購物車中的載入動畫選擇器
productSoldOutBadgestring商品當商品顯示預購時,隱藏已售完徽章的選擇器
productPositionMessagestring商品在文字上方顯示訊息的位置
productPositionLimitMessagestring商品顯示數量限制警告訊息的位置
productPositionPaymentOptionstring商品顯示付款選項的位置
productPositionBisstring商品顯示到貨通知按鈕的位置

這個頁面有幫助嗎?

回報問題