forked from crowetic/commerce
* Adding multiple initial files * Updated the default cart endpoint * Fixes * Updated CommerceAPI class for better usage * Adding more migration changes * Taking multiple steps into better API types * Adding more experimental types * Removed many testing types * Adding types, fixes and other updates * Updated commerce types * Updated types for hooks now using the API * Updated mutation types * Simplified cart types for the provider * Updated cart hooks * Remove normalizers from the hooks * Updated cart endpoint * Removed cart handlers * bug fixes * Improve quantity input behavior in cart item * Removed endpoints folder * Making progress on api operations * Moved method * Moved types * Changed the way ops are created * Added customer endpoint * Login endpoint * Added logout endpoint * Add missing logout files * Added signup endpoint * Removed customers old endpoints * Moved endpoints to nested folder * Removed old customer endpoint builders * Updated login operation * Updated login operation * Added getAllPages operation * Renamed endpoint operations to handlers * Changed import * Renamed operations to handlers in usage * Moved getAllPages everywhere * Moved getPage * Updated getPage usage * Moved getSiteInfo * Added def types for product * Updated type * moved products catalog endpoint * removed old catalog endpoint * Moved wishlist * Removed commerce.endpoint * Replaced references to commerce.endpoint * Updated catalog products * Moved checkout api * Added the get customer wishlist operation * Removed old wishlist stuff * Added getAllProductPaths operation * updated reference to operation * Moved getAllProducts * Updated getProduct operation * Removed old getConfig and references * Removed is-allowed-method from BC * Updated types for auth hooks * Updated useCustomer and core types * Updated useData and util hooks * Updated useSearch hook * Updated types for useWishlist * Added index for types * Fixes * Updated urls to the API * Renamed fetchInput to fetcherInput * Updated fetch type * Fixes in search hook * Updated Shopify Provider Structure (#340) * Add codegen, update fragments & schemas * Update checkout-create.ts * Update checkout-create.ts * Update README.md * Update product mutations & queries * Uptate customer fetch types * Update schemas * Start updates * Moved Page, AllPages & Site Info * Moved product, all products (paths) * Add translations, update operations & fixes * Update api endpoints, types & fixes * Add api checkout endpoint * Updates * Fixes * Update commerce.config.json Co-authored-by: B <curciobelen@gmail.com> * Added category type and normalizer * updated init script to exclude other providers * Excluded swell and venture temporarily * Fix category & color normalization * Fixed category normalizer in shopify * Don't use getSlug for category on /search * Update colors.ts Co-authored-by: cond0r <pinte_catalin@yahoo.com> Co-authored-by: B <curciobelen@gmail.com>
136 lines
3.2 KiB
Markdown
136 lines
3.2 KiB
Markdown
## Shopify Provider
|
|
|
|
**Demo:** https://shopify.demo.vercel.store/
|
|
|
|
Before getting starter, a [Shopify](https://www.shopify.com/) account and store is required before using the provider.
|
|
|
|
Next, copy the `.env.template` file in this directory to `.env.local` in the main directory (which will be ignored by Git):
|
|
|
|
```bash
|
|
cp framework/shopify/.env.template .env.local
|
|
```
|
|
|
|
Then, set the environment variables in `.env.local` to match the ones from your store.
|
|
|
|
## Contribute
|
|
|
|
Our commitment to Open Source can be found [here](https://vercel.com/oss).
|
|
|
|
If you find an issue with the provider or want a new feature, feel free to open a PR or [create a new issue](https://github.com/vercel/commerce/issues).
|
|
|
|
## Modifications
|
|
|
|
These modifications are temporarily until contributions are made to remove them.
|
|
|
|
### Adding item to Cart
|
|
|
|
```js
|
|
// components/product/ProductView/ProductView.tsx
|
|
const ProductView: FC<Props> = ({ product }) => {
|
|
const addToCart = async () => {
|
|
setLoading(true)
|
|
try {
|
|
await addItem({
|
|
productId: product.id,
|
|
variantId: variant ? variant.id : product.variants[0].id,
|
|
})
|
|
openSidebar()
|
|
setLoading(false)
|
|
} catch (err) {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Proceed to Checkout
|
|
|
|
```js
|
|
// components/cart/CartSidebarView/CartSidebarView.tsx
|
|
import { useCommerce } from '@framework'
|
|
|
|
const CartSidebarView: FC = () => {
|
|
const { checkout } = useCommerce()
|
|
return (
|
|
<Button href={checkout.webUrl} Component="a" width="100%">
|
|
Proceed to Checkout
|
|
</Button>
|
|
)
|
|
}
|
|
```
|
|
|
|
## APIs
|
|
|
|
Collections of APIs to fetch data from a Shopify store.
|
|
|
|
The data is fetched using the [Shopify JavaScript Buy SDK](https://github.com/Shopify/js-buy-sdk#readme). Read the [Shopify Storefront API reference](https://shopify.dev/docs/storefront-api/reference) for more information.
|
|
|
|
### getProduct
|
|
|
|
Get a single product by its `handle`.
|
|
|
|
```js
|
|
import getProduct from '@framework/product/get-product'
|
|
import { getConfig } from '@framework/api'
|
|
|
|
const config = getConfig()
|
|
|
|
const product = await getProduct({
|
|
variables: { slug },
|
|
config,
|
|
})
|
|
```
|
|
|
|
### getAllProducts
|
|
|
|
```js
|
|
import getAllProducts from '@framework/product/get-all-products'
|
|
import { getConfig } from '@framework/api'
|
|
|
|
const config = getConfig()
|
|
|
|
const { products } = await getAllProducts({
|
|
variables: { first: 12 },
|
|
config,
|
|
})
|
|
```
|
|
|
|
### getAllCollections
|
|
|
|
```js
|
|
import getAllCollections from '@framework/product/get-all-collections'
|
|
import { getConfig } from '@framework/api'
|
|
|
|
const config = getConfig()
|
|
|
|
const collections = await getAllCollections({
|
|
config,
|
|
})
|
|
```
|
|
|
|
### getAllPages
|
|
|
|
```js
|
|
import getAllPages from '@framework/common/get-all-pages'
|
|
import { getConfig } from '@framework/api'
|
|
|
|
const config = getConfig()
|
|
|
|
const pages = await getAllPages({
|
|
variables: { first: 12 },
|
|
config,
|
|
})
|
|
```
|
|
|
|
## Code generation
|
|
|
|
This provider makes use of GraphQL code generation. The [schema.graphql](./schema.graphql) and [schema.d.ts](./schema.d.ts) files contain the generated types & schema introspection results.
|
|
|
|
When developing the provider, changes to any GraphQL operations should be followed by re-generation of the types and schema files:
|
|
|
|
From the project root dir, run:
|
|
|
|
```sh
|
|
yarn generate:shopify
|
|
```
|