我有一个网站自定义建立在node.js上,我希望能够在GET请求中获得我所有的产品。shopify buy-button不允许我一次将所有产品带入页面(它有分页),这阻止了我正确过滤所有产品(我在网站上有自定义过滤器)。
因此,based on a post that I read在shopify论坛我希望做的事情如下:
<div class="wps-buy-button" id='[product-id]-[var-id]' data-id='[product-id]' data-var='[var-id]'></div>
这将允许我过滤所有不同的Shopify产品。然而,现在困难的部分是获取product-id
和var-id
字段。人们可能会认为简单地转到Products => All Products => Export就足够了,但是他们没有在其中列出product-id和var-id。
我试过使用Shopify-Buy npm模块,它看起来像下面的代码,但我得到了一个丑陋的,不可用的响应:
所以我的问题是,我如何才能得到我所有不同的Shopify产品的响应,无论是使用API,还是其他什么,没有having to use PH P,或者支付shopify plugin只是为了获得产品ID和var ID(我使用Shopify lite计划,因为我只是将其插入到我现有的平台)。
验证码:
import Client from 'shopify-buy';
const client = Client.buildClient({
domain: 'your-shop-name.myshopify.com',
storefrontAccessToken: 'your-storefront-access-token'
});
// Fetch all products in your shop
client.product.fetchAll().then((products) => {
// Do something with the products
console.log(products);
});
回复:
[ GraphModel {
id: [Getter],
handle: [Getter],
description: [Getter],
descriptionHtml: [Getter],
updatedAt: [Getter],
title: [Getter],
image: [Getter],
products: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: false,
hasPreviousPage: false,
variableValues: { first: 20, productsFirst: 20 } },
type: { name: 'CollectionConnection',
kind: 'OBJECT',
fieldBaseTypes: { edges: 'CollectionEdge', pageInfo: 'PageInfo' },
implementsNode: false } ]
[ GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: false,
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: { [Boolean: true] value: true },
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
GraphModel {
id: [Getter],
availableForSale: [Getter],
createdAt: [Getter],
updatedAt: [Getter],
descriptionHtml: [Getter],
description: [Getter],
handle: [Getter],
productType: [Getter],
title: [Getter],
vendor: [Getter],
publishedAt: [Getter],
onlineStoreUrl: [Getter],
options: [Getter],
images: [Getter],
variants: [Getter],
refetchQuery: [Getter],
type: [Getter],
nextPageQueryAndPath: [Function],
hasNextPage: true,
hasPreviousPage: { [Boolean: true] value: true },
variableValues: { first: 20, productsFirst: 20 } },
type: { name: 'ProductConnection',
kind: 'OBJECT',
fieldBaseTypes: { edges: 'ProductEdge', pageInfo: 'PageInfo' },
implementsNode: false } ]
2条答案
按热度按时间ldxq2e6h1#
要获取Shopify产品ID和产品变体ID,您可以使用Shopify REST API。因为你已经有了NodeJS应用程序,你可以使用Shopify API Node.js Module。只需获取所有产品,将获取的数据传递到前端,然后使用问题中提到的脚本来呈现Shopify购买按钮。
获取所有产品的示例代码
为了获得更好的性能,请考虑将产品保存在数据库中并定期更新信息。
Shopify REST API
ws51t4hk2#
此解决方案在2023年适用于
shopify-api-node
: