HTML的购买按钮添加,将shopify购买按钮添加到流星js网站

不知道最好的方法来连接流星js网站使用购买按钮购物。 要initializie的Shopify API - http://shopify.github.io/js-buy-sdk/ - 直接,我导入使用将shopify购买按钮添加到流星js网站

meteor npm install --save shopify-buy

meteor npm install --save shopify-promise

这些包shopify买和shopify-承诺NPM包出现在的package.json

},

"dependencies": {

"babel-runtime": "^6.26.0",

"bcrypt": "^1.0.3",

"shopify-buy": "^0.7.1",

"shopify-promise": "0.0.5",

"simpl-schema": "^0.3.2"

},

After fetching a product with the product ID we use the promise function to generate some markup with the required attributes and content, and add it inside our HTML container element.

client.fetchProduct('your-product-id').then(function(product) {

var html =

"%22%20+%20product.selectedVariantImage.src%20+%20%22" +

"

" + product.title + "

" +

"Buy Now!";

$('#product-1').html(html);

});

但不知道如何通过这个网站回到流星JS模板,因为我只需要传回的数据。

使用类似于上面的JS代码,我尝试将Shopify按钮url添加到我的每个产品中作为shopifyBuyUrl字段。我在服务器做到这一点/ startup.js

Meteor.startup(function() {

var shopifyBuyUrl = require('shopify-buy');

const shopClient = shopifyBuyUrl.buildClient({

api_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",

accessToken: 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',

domain: 'test1.myshopify.com',

appId: '6'

});

[ ... then I have code here that loads the product categories array - this array has 6 categories and an array of products within each category ...]

[next I try and pre-fill the shopifyBuyUrl value for each product]

for (var i=0; i < 6; i++) {

// fetch a product using resource id

for (var j=0; j < products[i].length; j++) {

// shopify product id is hardcoded for now

products[i][j].shopifyProductId='12836712587';

shopClient.fetchProduct('12836712587').then(function(product) {

products[i][j].shopifyBuyUrl=product.selectedVariant.checkoutUrl(1);

})

.catch(function() {

console.log('Request failed');

});

}

}

console.log('Inserting categories into MongoDB ...');

for (var i=0; i < 6; i++) {

Categories.insert(

{

img_alt:name[i],

img_src:src[i],

desc:desc[i],

products:products[i],

});

}

}

上面的代码能够与Shopify成功验证,并创建shopClient实例。 Shopify电话创建Shopify购买网址有时会成功,有时无法记录'请求失败'消息。不确定是否故障与重复使用同一产品ID相关!

由于我不确定是否直接使用Shopify API或使用流星shopify软件包,我还将https://github.com/froatsnook/meteor-shopify软件包添加到我的项目中,并且对此软件包进行了身份验证。但是从包API /演示中不清楚如何使用此包来启用Shopify Buy。

因此,总体上我不清楚什么是使用Shopify和Meteor JS的最佳/正确的方法。 Froats没有办法走还是不再适用?理想情况下,最好直接去Shopify,但不知道它如何与流星合作。

任何将Shopify购买按钮添加到流星JS项目的帮助将不胜感激。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值