Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Shopify在checkout.liquid内获取购物车信息_Javascript_Shopify - Fatal编程技术网

Javascript Shopify在checkout.liquid内获取购物车信息

Javascript Shopify在checkout.liquid内获取购物车信息,javascript,shopify,Javascript,Shopify,我正在使用shopify buy button js在我的网站上创建商品并将其添加到购物车中,并在结账时将用户重定向到我的shopify网站 现在,在checkout页面上,我想在checkout.liquid中检索有关购物车及其行项目的信息,但是当我尝试调用/cart.js以及Shopify.getCart()及其jquery包装时,购物车总是空的 以下是我尝试过的: 内部结帐。液体 尝试1: {{ '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/

我正在使用shopify buy button js在我的网站上创建商品并将其添加到购物车中,并在结账时将用户重定向到我的shopify网站

现在,在checkout页面上,我想在checkout.liquid中检索有关购物车及其行项目的信息,但是当我尝试调用/cart.js以及Shopify.getCart()及其jquery包装时,购物车总是空的

以下是我尝试过的:

内部结帐。液体

尝试1:

{{ '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js' | script_tag }}
{{ 'api.jquery.js' | shopify_asset_url | script_tag }}
<script type="text/javascript">
  $(function() {
      console.log(Shopify.getCart());
  });
</script>
{{{'//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'| script_tag}}
{{'api.jquery.js'| shopify_asset_url | script_tag}
$(函数(){
log(Shopify.getCart());
});
尝试2:

<script type = "text/javascript" >
    $(function() {
        $.getJSON('/cart.js', function(cart) {
            console.log(cart);
        });
    }); 
</script>

$(函数(){
$.getJSON('/cart.js',函数(cart){
控制台日志(购物车);
});
}); 

关于如何获取这些信息有什么想法吗?谢谢

似乎没有直接的方法在客户端检索这些值。我最终在服务器端呈现数据,并使用jQuery解析它们

<div class="data" style="display:none;">
  <span class="taxAmount">{{ checkout.tax_price | money_without_currency | remove: ',' }}</span>
  <span class="grandTotal">{{ checkout.total_price | money_without_currency | remove: ',' }}</span>
  <span class="currency">{{ shop.currency }}</span>

  {% for line_item in checkout.line_items %}
        <div class="lineItem">
          <span class="name">{{ line_item.product.title }}</span>
          <span class="sku">{{ line_item.sku }}</span>
          <span class="quantity">{{ line_item.quantity }}</span>
          <span class="unitPrice">{{ line_item.price | money_without_currency | remove: ',' }}</span>
          <span class="salePrice">{{ line_item.price | money_without_currency | remove: ',' }}</span>
          <span class="totalPrice">{{ line_item.price | times: line_item.quantity | money_without_currency | remove: ',' }}</span>
          <span class="imageUrl">{{ line_item.image | image_url }}</span>
        </div>
  {% endfor %}
</div>

<script type="text/javascript">
  $(function() {
        $('.data .lineItem').each(function() {
            "sku": $(this).find('.sku').text(),
            "name": $(this).find('.name').text()
            // do my stuff
        });
  });

{{checkout.tax|u price | money|u不带|货币|删除:','}
{{checkout.total|u price | money|u不带|货币|删除:','}
{{shop.currency}}
{checkout.line\u items%}
{{line_item.product.title}
{{line_item.sku}}
{{line_item.quantity}}
{{line_item.price | money_不带|货币|删除:','}
{{line_item.price | money_不带|货币|删除:','}
{{line_item.price | times:line_item.quantity | money |不带|货币|删除:','}
{{line_item.image}image_url}
{%endfor%}
$(函数(){
$('.data.lineItem')。每个(函数(){
“sku”:$(this.find('.sku').text(),
“名称”:$(this.find('.name').text()
//做我的事
});
});