类别页面上的Bigcommerce Stencil SKU编号

时间:2016-06-28 14:09:15

标签: bigcommerce

我目前看到{{product.sku}}与产品页面绑定。

我需要在类别/搜索页面上显示sku编号,但没有全局属性。

编辑模板>组件>产品> card.html

如果您知道任何解决方案或指出我正确的方向,那将是一个帮助。

提前感谢你:)

2 个答案:

答案 0 :(得分:1)

以下是根据您的网站量身定制的示例,介绍如何从每个产品页面加载SKU,然后将其插入类别页面。此代码应位于类别页面上。这只是一个例子,您可能需要修改它才能在您的网站上运行。

// For Each Product...
$('.product').each(function(i) {
  // Get the product URL 
  var url = $('> article > figure > a', this).attr('href'); // http://screencast.com/t/qBgwszhhpFiz

  // Perform GET
  getProductSKU(url).then(function(sku) {
    console.log(sku);
    // do something with the sku
    // such as append it to the product, maybe above the 'add to cart button'
  });

});

/**
 * Performs HTTP Get to a given product page
 * and returns the SKU on that page. 
 * @param url <string> - The product URL to GET
 * @return Promise - Resolved with product SKU on success. 
 */
function getProductSKU(url) {
  return new Promise(function(resolve, reject) {
    $.ajax({
      url: url,
      type:'GET',
      success: function(data){
        resolve($(data).find('#sku-value').text()); //Return the SKU - http://screencast.com/t/zlCAftmekgp
      },
      error: reject
    });
  });
}

链接:
http://screencast.com/t/qBgwszhhpFiz
http://screencast.com/t/zlCAftmekgp

答案 1 :(得分:0)

您可以执行ajax load()调用以将此信息提取到您需要的页面,但目前还没有产品卡公开的帮助程序或数据来支持此信息。

相关问题