不知道最好的方法来连接流星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 =
"" +
"
" + 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项目的帮助将不胜感激。