How to use the shopify-buy.buildClient function in shopify-buy

To help you get started, we’ve selected a few shopify-buy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github princefishthrower / react-redux-shopify-storefront-api-example / src / index.js View on Github external
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import Client from 'shopify-buy';
import { Provider } from 'react-redux';
import store from './store';
import './styles/shopify.css';

// build shopify client
const client = Client.buildClient({
    storefrontAccessToken: 'YOUR_SHOPIFY_STOREFRONT_ACCESS_TOKEN',
    domain: 'YOUR_MYSHOPIFY_STORE_URL'
});
store.dispatch({type: 'CLIENT_CREATED', payload: client});

// buildClient() is synchronous, so we can call all these after!
client.product.fetchAll().then((res) => {
  store.dispatch({type: 'PRODUCTS_FOUND', payload: res});
});
client.checkout.create().then((res) => {
  store.dispatch({type: 'CHECKOUT_FOUND', payload: res});
});
client.shop.fetchInfo().then((res) => {
  store.dispatch({type: 'SHOP_FOUND', payload: res});
});
github Shopify / storefront-api-examples / react-js-buy / src / index.js View on Github external
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import Client from 'shopify-buy';
import '../../shared/app.css';

const client = Client.buildClient({
  storefrontAccessToken: 'dd4d4dc146542ba7763305d71d1b3d38',
  domain: 'graphql.myshopify.com'
});

ReactDOM.render(
  ,
  document.getElementById('root')
);
github alexislepresle / gatsby-shopify-theme / src / context / store.js View on Github external
import React from 'react'
import Client from 'shopify-buy'

const client = Client.buildClient({
  storefrontAccessToken: process.env.SHOPIFY_ACCESS_TOKEN,
  domain: `${process.env.SHOP_NAME}.myshopify.com`,
})

export const defaultStoreContext = {
  client,
  adding: true,
  checkout: { lineItems: [] },
  products: [],
  shop: {},
  filteredType: 'all',
  filteredSort: 'featured',
  addVariantToCart: () => { },
  addVariantToCartAndBuyNow: () => { },
  removeLineItem: () => { },
  updateLineItem: () => { },
github Shopify / storefront-api-examples / node-js-buy / src / js-buy-sdk.js View on Github external
import fetch from 'node-fetch';
import Client from 'shopify-buy';

global.fetch = fetch;

const client = Client.buildClient({
  storefrontAccessToken: '20ef0127c6c37cee73dd149879a379a8',
  domain: 'faheemnusrat.com'
});

export default client;
github AlexanderProd / gatsby-shopify-starter / src / provider / ContextProvider.js View on Github external
import React, { useState, useEffect } from 'react'
import Client from 'shopify-buy'

import Context from '~/context/StoreContext'

const client = Client.buildClient({
  storefrontAccessToken: process.env.SHOPIFY_ACCESS_TOKEN,
  domain: `${process.env.SHOP_NAME}.myshopify.com`,
})

const ContextProvider = ({ children }) => {
  let initialStoreState = {
    client,
    adding: false,
    checkout: { lineItems: [] },
    products: [],
    shop: {},
  }

  const [store, updateStore] = useState(initialStoreState)

  useEffect(() => {
github gatsbyjs / store.gatsbyjs.org / src / context / StoreContext.js View on Github external
import React from 'react';
import Client from 'shopify-buy';

const client = Client.buildClient({
  domain: 'gatsby-swag.myshopify.com',
  storefrontAccessToken: '9aa73c089d34741f36edbe4d7314373a'
});

export const defaultStoreContext = {
  client,
  isCartOpen: false,
  checkout: { lineItems: [] },
  products: [],
  shop: {},
  addVariantToCart: () => {},
  removeLineItem: () => {},
  updateLineItem: () => {},
  toggleCart: () => {}
};
github gil-- / gatsby-starter-shopifypwa / src / layouts / index.js View on Github external
import React from 'react'
import PropTypes from 'prop-types'
import Helmet from 'react-helmet'
import Client from 'shopify-buy'

import Header from '../components/header'
import './index.css'

const shopifyClient = Client.buildClient({
  domain: `${process.env.GATSBY_SHOPIFY_SHOP_NAME}.myshopify.com`,
  storefrontAccessToken: process.env.GATSBY_SHOPIFY_ACCESS_TOKEN,
})

const Layout = ({ children, data, ...props }) => (
  <div>
    
    <header>
    </header></div>
github kellyvaughn / kvlly / src / components / shopcontext.js View on Github external
import React from 'react'
import Client from 'shopify-buy'

const client = Client.buildClient({
  domain: `${process.env.SHOPIFY_STORE_NAME}.myshopify.com`,
  storefrontAccessToken: process.env.SHOPIFY_SECRET,
})

export const defaultStoreContext = {
  client,
  adding: false,
  checkout: { lineItems: [] },
  products: [],
  shop: {},
  filteredType: 'all',
  addVariantToCart: () => {},
  removeLineItem: () => {},
  updateLineItem: () => {},
}

shopify-buy

The JS Buy SDK is a lightweight library that allows you to build ecommerce into any website. It is based on Shopify's API and provides the ability to retrieve products and collections from your shop, add products to a cart, and checkout.

MIT
Latest version published 7 months ago

Package Health Score

73 / 100
Full package analysis