Giter Club home page Giter Club logo

nuxt-shopify's Introduction

nuxt-shopify

๐Ÿ› Shopify Module

npm version Dependencies npm downloads code style: prettier License: MIT FOSSA Status

Easy Shopify Buy client integration with Nuxt.js

Setup

Install with yarn:

yarn add nuxt-shopify

Install with npm:

npm install nuxt-shopify

nuxt.config.js

module.exports = {
  modules: ['nuxt-shopify'],

  shopify: {
    /**
     * Your shopify domain
     */
    domain: 'your-shop-name.myshopify.com',

    /**
     * Your shopify storefront access token
     */
    storefrontAccessToken: 'your-storefront-access-token',

    /**
     * This will be larger than the optimized version, as it will contain all fields that are available in the
     * Storefront API. (https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference)
     * This should only be used when you need to add custom queries to supplement the JS Buy SDK queries.
     */
    unoptimized: false,

    /**
     * Set language to return translated content (optional)
     */
    language: 'ja-JP',
  },
};

OR

module.exports = {
  modules: ['nuxt-shopify'],

  env: {
    SHOPIFY_DOMAIN: 'your-shop-name.myshopify.com', // your shopify domain
    SHOPIFY_ACCESS_TOKEN: 'your-storefront-access-token', // your shopify storefront access token
  },
};

Don't have a Storefront Access Token yet? Get started.

Usage

Component

asyncData

async asyncData({ $shopify, params }) {
  const product = await $shopify.product.fetch(params.id);
  return { product };
}

methods/created/mounted/etc

methods: {
  async fetchProduct(productId) {
    this.product = await this.$shopify.product.fetch(productId);
  }
}

Store actions (including nuxtServerInit)

// In store
{
  actions: {
    async fetchAllProducts ({ commit }) {
      const products = await this.$shopify.product.fetchAll();
      commit('SET_PRODUCTS', products)
    }
  }
}

Shopify Client

Examples from the official shopify-buy sdk library

Fetching products

// Fetch all products in your shop
this.$shopify.product.fetchAll().then((products) => {
  // Do something with the products
  console.log(products);
});

// Fetch a single product by ID
const productId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=';

this.$shopify.product.fetch(productId).then((product) => {
  // Do something with the product
  console.log(product);
});

Fetching Collections

// Fetch all collections, including their products
this.$shopify.collection.fetchAllWithProducts().then((collections) => {
  // Do something with the collections
  console.log(collections);
  console.log(collections[0].products);
});

// Fetch a single collection by ID, including its products
const collectionId = 'Z2lkOi8vc2hvcGlmeS9Db2xsZWN0aW9uLzM2OTMxMjU4NA==';

this.$shopify.collection.fetchWithProducts(collectionId).then((collection) => {
  // Do something with the collection
  console.log(collection);
  console.log(collection.products);
});

Creating a checkout

// Create an empty checkout
this.$shopify.checkout.create().then((checkout) => {
  // Do something with the checkout
  console.log(checkout);
});

Adding Line Items

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout
const lineItemsToAdd = [
  {
    variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==',
    quantity: 5,
    customAttributes: [{ key: 'MyKey', value: 'MyValue' }],
  },
];

// Add an item to the checkout
this.$shopify.checkout.addLineItems(checkoutId, lineItemsToAdd).then((checkout) => {
  // Do something with the updated checkout
  console.log(checkout.lineItems); // Array with one additional line item
});

Updating checkout attributes

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9DaGVja291dC9kMTZmM2EzMDM4Yjc4N=';
const input = { customAttributes: [{ key: 'MyKey', value: 'MyValue' }] };

this.$shopify.checkout.updateAttributes(checkoutId, input).then((checkout) => {
  // Do something with the updated checkout
});

Updating Line Items

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout
const lineItemsToUpdate = [{ id: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=', quantity: 2 }];

// Update the line item on the checkout (change the quantity or variant)
this.$shopify.checkout.updateLineItems(checkoutId, lineItemsToUpdate).then((checkout) => {
  // Do something with the updated checkout
  console.log(checkout.lineItems); // Quantity of line item 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=' updated to 2
});

Removing Line Items

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout
const lineItemIdsToRemove = ['Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ='];

// Remove an item from the checkout
this.$shopify.checkout.removeLineItems(checkoutId, lineItemIdsToRemove).then((checkout) => {
  // Do something with the updated checkout
  console.log(checkout.lineItems); // Checkout with line item 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzc4NTc5ODkzODQ=' removed
});

Fetching a Checkout

const checkoutId = '2U4NWNkYzI4ZWEyOTdlOD9rZXk9MDVjMzY3Zjk3YWM0YWJjNGRhMTkwMDgwYTUzOGJmYmI=';

this.$shopify.checkout.fetch(checkoutId).then((checkout) => {
  // Do something with the checkout
  console.log(checkout);
});

Adding a Discount

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout
const discountCode = 'best-discount-ever';

// Add a discount code to the checkout
this.$shopify.checkout.addDiscount(checkoutId, discountCode).then((checkout) => {
  // Do something with the updated checkout
  console.log(checkout);
});

Removing a Discount

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout

// Removes the applied discount from an existing checkout.
this.$shopify.checkout.removeDiscount(checkoutId).then((checkout) => {
  // Do something with the updated checkout
  console.log(checkout);
});

Updating a Shipping Address

const checkoutId = 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0SW1hZ2UvMTgyMTc3ODc1OTI='; // ID of an existing checkout

const shippingAddress = {
  address1: 'Chestnut Street 92',
  address2: 'Apartment 2',
  city: 'Louisville',
  company: null,
  country: 'United States',
  firstName: 'Bob',
  lastName: 'Norman',
  phone: '555-625-1199',
  province: 'Kentucky',
  zip: '40202',
};

// Update the shipping address for an existing checkout.
this.$shopify.checkout.updateShippingAddress(checkoutId, shippingAddress).then((checkout) => {
  // Do something with the updated checkout
});

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Build the module using yarn build or npm run build
  4. Start development server using yarn dev or npm run dev

๐Ÿ“‘ License

MIT License

FOSSA Status

nuxt-shopify's People

Contributors

atinux avatar dependabot-preview[bot] avatar dependabot[bot] avatar fossabot avatar gomah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nuxt-shopify's Issues

How can I use is as instance. ?

How can I use it as an instance?

I need dynamically change the endpoint and token base on user request.

how could I do it.. please.

Missing the product tags

Hi Gomah,
I would like to get the product tags, but can't get it from the API

Screen Shot 2021-01-21 at 11 31 12 am

Could you please help me to check it?
Thank you so much!

Mode `../../lib/module` not found.

Hey,

I'm having a problem with cloning the repository and actually getting it to work. I've cloned the repo with git clone "repo URL", then I installed the dependencies with yarn install. After that I tried to run yarn dev or npm run dev, but it throws the following error.

PS M:\nuxt-shopify> yarn dev
yarn run v1.22.4
$ nuxt test/fixture

 FATAL  Module ../../lib/module not found. Please ensure ../../lib/module is in dependencies and installed.                                                                                                                        14:23:42  

  at ModuleContainer.addModule (node_modules\@nuxt\core\dist\core.js:182:17)
  at promise.then (node_modules\@nuxt\utils\dist\utils.js:1803:43)


   โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
   โ”‚                                                                                                                      โ”‚
   โ”‚   โœ– Nuxt Fatal Error                                                                                                 โ”‚
   โ”‚                                                                                                                      โ”‚
   โ”‚   Error: Module `../../lib/module` not found. Please ensure `../../lib/module` is in `dependencies` and installed.   โ”‚
   โ”‚                                                                                                                      โ”‚
   โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Anyone know how to solve this?

Much appreciated!

Unable to find `quantityAvailable` on variants โ€“ how can I get count stock?

Hi there,

Iโ€™m not sure if Iโ€™m missing something, but this isnโ€™t coming through on my requests, even with unoptimised: true set in my nuxt.config.js file.

I literally just need to query stock level and product/variant id as I am importing product data from Shopify to Sanity, but have been using: this.$shopify.product.fetchAll().

Thanks so much for your work on this,

Simon

An unknown error has occurred

I'm following this tutorial but keep getting an unknown error message when adding the async function in the index.vue

ERROR [ 16:02:52
{
message: 'an unknown error has occurred.'
}
]

Screenshot

selling_plan_allocations not given in products are variants

Hello,

First I must admit that I am really fund of your plugin.
It works extremely well and saves me a lot of times, thanks!

Is it possible to add selling_plan_allocations to products, carts and variants? (Used for the new subscriptions plugin in shopify)
It is going to be super helpful for me and other users!

Happy x-mas!

Jest: node_modules/nuxt-shopify/lib/module.js

Hi there

Since installing nuxt-shopify and running npm run test (jest), I am now receiving the error:

[fatal] Cannot use import statement outside a module

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Pointing to the error:

node_modules/nuxt-shopify/lib/module.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import path from 'path';
^^^^^^

I've tried all matter of guides online to ignore it, but I can't suss it out myself.

"core-js": "^3.15.1",
"nuxt": "^2.15.3",
"nuxt-shopify": "^1.12.0"
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^27.0.5",
"jest": "^27.3.1",

Fetch more than 20 products by Collection

It is possible to return more than 20 products using the collection id?
I tried to use fetchNextPage without any success. If anymore can share a snippet that would be great!

Thanks!

How to start a request?

As a newbie, I encountered some difficulties:
After installing nuxt-shopify and configuring the token, I copied the script in the document:

methods: {
    test () {
      // Fetch all products in your shop
      this.$shopify.product.fetchAll().then(products => {
        // Do something with the products
        console.log(products);
      });
    }
}

But I received the following error in the console:

{"data":{"products":{"pageInfo":{"hasNextPage":false,"hasPreviousPage":false},"edges":[]}}}

May I ask what additional work I have overlooked? I'm so stupid. Any help is greatly appreciated
PS: Can I use REST api request?

Send cookies to Shopify

Hi, I've been working on a Shopify shop and we've come across some problems with the cookies.

The user accepts the cookies on our headless website, but these cookies are not available in the Shopify checkout. How can we make sure the cookies from the headless website are passed on to the Shopify checkout?

I've talked with someone from Shopify and they recommend this API, but I can't seem to make it work.

Thanks in advance

Error in docs

Fetching a product.

this.$shopify.fetch(productId).then(product => {
       // Do something with the product
      console.log(product);
});

...should be:

this.$shopify.product.fetch(productId).then(product => {
       // Do something with the product
      console.log(product);
});

product fetching limited to 20 items

NVM I found somewhere the params

$shopify.collection
  .fetchAllWithProducts({ productsFirst: 100 })
  .then((collections) => {
    // do something
  });

Bump shopify-buy

โ€ฆto 2.17.0 to include updates in Storefront API 2022-07

Cannot stringify arbitrary non-POJOs GraphModel Warning

Keep getting Cannot stringify arbitrary non-POJOs GraphModel warning

In store/index.js
async nuxtServerInit({commit, dispatch}, context) {
if (process.server) {
try{
const products = await context.app.$shopify.product.fetchAll();
commit('products/setProducts', products)
}catch (e) {
console.log('products err: ',e)
}
}
}

I get same error in asyncData.

Is there something I am missing?

Product filters in queries

Are product filters available with nuxt-shopify when doing product queries?
I would like to filter a collection of product by price/tags/vendor etc..
I know this is available (to some extend) with the storefront API but I am not sure how to use it with nuxt-shopify.

Also in collection with pagination is it possible to add query?
Ex: In collection A get first 20 products with price below 20โ‚ฌ or color blue.

Nuxt 3 error

Any updates in nuxt3 support?

 ERROR  Cannot start nuxt:  Cannot read properties of undefined (reading 'options')                                                      11:21:42

  at shopifyModule (node_modules/nuxt-shopify/lib/module.js:3:33)
  at installModule (node_modules/@nuxt/kit/dist/index.mjs:416:9)
  at async initNuxt (node_modules/nuxt/dist/index.mjs:1825:7)
  at async load (node_modules/nuxi/dist/chunks/dev.mjs:6779:9)
  at async Object.invoke (node_modules/nuxi/dist/chunks/dev.mjs:6840:5)
  at async _main (node_modules/nuxi/dist/cli.mjs:50:20)

Question: How do you handle Shopify product/page updates for static site deployment?

I've run into a dilemma and I was wondering if you found a solution:

When using nuxt-shopify to generate and deploy a static site, the product information (and in my case, store pages) are fetched on the server during the build, and then hard-coded into the static site (working properly). This is perfect until someone updates one of the Shopify pages or product info, and now the data is out of date. I originally looked into building a Universal app, but for my use case, a static Nuxt site is currently the best solution.

How do you have the static content (so that it's available before hydration), but also update the site content with any new Shopify changes that occurred since the build?

Here's what I've done:

  1. I fetch all content (products and pages) in the store via the nuxtServerInit method, which sets up the data for when the first page is loaded. (This is great assuming no changes have been made on Shopify between the build time and when the user accesses the page.)
  2. When the user navigates to a product or page, I trigger a fetch event to go out and retrieve all products and pages again from the API, but on an interval (e.g. I only allow a fetch every 5 minutes).

This works; however, on the initial page load, there will be a flash of content if anything has changed. For example, if I change a product title, it will show incorrectly until the $shopify method returns the fresh data and writes it to the store. Then for the rest of the user's session, the newest data is shown.

I know I could show the loader or hide content until after the fetch completes; however, this would mean that no content is likely visible for SEO purposes, and the user would have to wait for products, images, etc. to load after they are fetched (which defeats the purpose of the static site, since there would originally not be an API call here).

I found a way around this by trigging a build via webhook on the host server any time certain Shopify events occur (e.g. product creation/deletion/update) that completely rebuilds and re-deploys the site. This solves my issue, but that could potentially be a lot of build time, which is less than ideal.

Any ideas? If you have the time to help me take a look, I have a project all set up.

fetchNextPage() Collection Pagination?

Hello, all!

I am attempting to implement collection pagination in the form of an infinite scroll, but I am having difficulty with fetchNextPage. fetchWithProducts() works perfectly as described in the project readme, but trying to extend the client to use fetchNextPage, i always get a TypeError: node is undefined error on that line. I am following the migrate documentation from the storefront migration guide: https://github.com/Shopify/js-buy-sdk/blob/master/tutorials/MIGRATION_GUIDE.md#pagination

Here is my method:

            fetchCollection() {
                let productsForCollection;                
                this.$shopify.collection.fetchWithProducts(this.id, { productsFirst: 12 }).then((collection) => {
                    productsForCollection = collection.products;
                    console.log(productsForCollection);

                });
                this.$shopify.fetchNextPage(productsForCollection).then((nextPageOfProducts) => {
                    console.log(nextPageOfProducts);
                });
            },

Has anyone successfully implemented pagination on their nuxt-shopify project and can give me any pointers on what i might be doing wrong?

asyncData error using now-builder

The error:

TypeError: n(...) is not a function
    at e.exports.global.fetch (server.js:2:422464)
    at e.fetcher (server.js:2:196611)
    at e.value (server.js:2:198382)
    at t.value (server.js:2:224516)
    at asyncData (df30ccfd100953e8f69a.js:1:10823)

my code in pages/index.vue:

async asyncData({ $shopify }) {
    try {
      // find home page collection products
      const collection = await $shopify.collection.fetchByHandle('frontpage')
      return { products: collection.products }
    } catch (e) {
      console.error('Error while fetching product collections: ', e)
      return {}
    }
  },

Fetch id of productVariant

I am having issues in using the $shopify.checkout.addLineItems method. When I fetch a product, the id's of my productVariants look like this:

"variants": [
      {
        "id": 37347204038813,
        "product_id": 5909234516125,
        "admin_graphql_api_id": "gid://shopify/ProductVariant/37347204038813"
      },
]

But none of these ids work here:

  async addCartItem(state, {selectedVariantId}) {
    const lineItemsToAdd = [
      {
        variantId: selectedVariantId, // either id or product_id
        quantity: 1
      }];

    await this.$shopify.checkout.addLineItems(this.app.$checkout.getCheckoutId(), lineItemsToAdd)
      .then(checkout => {
        console.log(checkout);
      }).catch((e) => {
        console.log(e);
      });
  },

Error message:

Error: [{"message":"Variable $lineItems of type [CheckoutLineItemInput!]! was provided invalid value for 0.variantId (Invalid global id 5909234516125)","locations":[{"line":1,"column":3245}],"extensions":{"value":[{"variantId":5909234516125,"quantity":1}],"problems":[{"path":[0,"variantId"],"explanation":"Invalid global id 5909234516125","message":"Invalid global id 5909234516125"}]}}]

Of course, I noticed that the variantId looks different, then the ID I am getting. But nowhere is written, where I can find the acutal "global" id.

Also, fetching the variant by id or product_id also does not work.

Gift card

Is is currently possible to accept gift cards? A gift card code doesn't seem to work with addDiscount.

Leaving names blank when updating shipping address breaks

Because I don't take the name of the customer on my custom front end, I tried to leave these fields blank when using the "updateShippingAddress" action but it failed. Is there any way to allow these entries to be blank?

Thanks,

Does having a Support plan or Opinion about Metafield of Shopify ?

First, always Thanks to NUXT-SHOPIFY.
It makes people easy to use Shopify like me.

Now I am curious about Metafield Supporting plan or opinion of others.

Here is Metafield specification.

I think the Metafield function is not supported in NUXT-SHOPIFY.

and couldn't find information about this.

Is there any plan or opionion about this one?

Thank you for reading! :bowtie:

Fetching Pages from Shopify

Hey @Gomah,

Thank you for your amazing work with this plugin. Any ideas on how we might be able to access Pages from Shopify?

I've had a look at the Shopify Buy SDK, and unfortunately Shopify haven't included a PageResource internally. This is the query we need to run.

const query = $shopify.graphQLClient.query((root) => {
      root.addConnection('pages', { args: { first: 10 }}, (page) => {
        page.add('title');
        page.add('body');
      });
    });
let page = await $shopify.graphQLClient.send(query).then(({ model, data }) => {
      return data;
    });

Upon running the above snippet I'm getting an error No field of name "pages" found on type "QueryRoot" in schema.

And this seems to be because the Pages type isn't included in the Shopify import Client from 'shopify-buy'; build. I've hacked together a quick example using import Client from 'shopify-buy/index.unoptimized.umd'; and I can see my above query working.

Any ideas on how we might get the unoptimised Shopify SDK working with your plugin? Would it be possible to create a speparate branch using the unoptimised version?

Thanks mate,
Rob

Get translation of products

I'm currently working on a project where we need to display product content from Shopify in two different languages (English & Swedish), but I can't find anywhere if this is actually accessible in this module.

I've added a third-party app on Shopify and translated one product, but I can't see any "translation"-key or similar on the product object. The Shopify documentation says that product description and title should be available in the Storefront API: https://shopify.dev/tutorials/manage-app-translations-with-admin-api#storefront-api-translation-resources

It should be possible to get translated content according to the JS Buy SDK documentation as well: https://github.com/Shopify/js-buy-sdk#initializing-the-client

I've tried to add:

language: 'sv-SE'

to the nuxt config, but nothing happens.

Is it possible to get the product translations and if so, how?

Thanks,
Emil

CORS errors on request

I am following the instructions from https://nuxt-shopify-docs.vercel.app/usage/shopify-client and also the provided readme here.
For example I tried following code provided by the docs to fetch a certain product:

methods: {
  async fetchProduct(productId) {
    this.product = await this.$shopify.product.fetch(productId);
  }
}

But I always get CORS errors denying my request.
I am trying to fix this issue for several days now and cant find a solution, what am I doing wrong?

Fetch product by handle

Is is possible to return product data using the product handle instead of the id?

I'm currently using asyncData with the fetch method and passing params.handle. I've tried using fetchQuery, but it doesn't look like that supports handle.

Thanks!

Support for Directives (inContext)

Hi, I am not sure if it's already the case but it seems that directive like @inContext are not supported currently by the shopify client.

I tried to use the @incontext directive in my query like explained in this guide but with no success.

Is there a way to check if it's working or maybe I am doing something wrong but just want to check.
My query:

query allProducts @inContext(country: US) {
      products(first: 1) {
        pageInfo { hasNextPage, hasPreviousPage }
        edges {
          node {
            variants(first: 1) {
              pageInfo { hasNextPage, hasPreviousPage }
              edges {
                node {
                  priceV2 {
                    amount
                    currencyCode
                  }
                }
              }
            }
          }
        }
      }
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.