Share
Embed
Transcript
37 slides
-
Agenda • ShopifyͰͷϑϩϯτΤϯυͷ࡞Γํ • ։ൃ༻αΠτ / Storefront APIར༻ͷ४උ • Gatsby(React)ͰShopifyͱ࿈ܞͨ͠αΠτΛ࡞Δ
• What’s your favorite style to make the store? #ShopifyUC -
Agenda • ShopifyͰͷϑϩϯτΤϯυͷ࡞Γํ • ։ൃ༻αΠτ / Storefront APIར༻ͷ४උ • Gatsby(React)ͰShopifyͱ࿈ܞͨ͠αΠτΛ࡞Δ
• What’s your favorite style to make the store? #ShopifyUC -
ߏஙํ๏1 ςʔϚΛߪೖ͢Δ • ετΞ͔ΒΠϯετʔϧ • ແྉ൛Ͱͦͦ͜͜ߴػೳ • ΧελϚΠβʔతͳػೳ • ΧελϚΠζͷࣗ༝ʹ੍ݶ
• αϙʔτ͕ӳޠߴΊ(༗ྉTheme) • Shopify LiteͰͦͦ͑ͳ͍ #ShopifyUC -
ߏஙํ๏2 ςʔϚΛࣗ࡞͢Δ • Liquidه๏ + JavaScriptͰ࡞ΕΔ • Tutorialίʔυྫ͕ଟ͍ • ༗ྉςʔϚൢചࢦͤΔ
• Liquidه๏ʹೃછΊΔ͔൱͔͕ਫྮ • Sampleଟ͍͕ɺݱঢ়ӳޠߴΊ • Shopify LiteͰͦͦ͑ͳ͍ #ShopifyUC -
ߏஙํ๏3 APIΛͬͯ֎෦ߏங • Shopify API(REST / GraphQL)Λར༻ • LiteͰϑϩϯτΤϯυ͕࡞ΕΔ •
JavaScriptͷจ຺ͰߏஙՄೳ • JamstackͰαΠτ͕࡞ΕΔ͔͕ਫྮ • Shopifyͷ֎ʹͳΔͷͰࢿྉΑΓগͳ͍ • ظతʹอकӡ༻͢ΔલఏʹͳΓ͕ͪ -
Agenda • ShopifyͰͷϑϩϯτΤϯυͷ࡞Γํ • ։ൃ༻αΠτ / Storefront APIར༻ͷ४උ • Gatsby(React)ͰShopifyͱ࿈ܞͨ͠αΠτΛ࡞Δ
• What’s your favorite style to make the store? #ShopifyUC -
Shopify Perners • ShopifyΞΧϯτͱผʹొ • ແྉͰ։࢝Մೳ • ΞϑΟϦΤΠτͳͲ • Dev༻ͷγϣοϓ͕ແྉͰ࡞ΕΔ
https://www.shopify.jp/partners #ShopifyUC -
https://YOUR-SHOP-NAME.myshopify.com/admin/apps/private/new αΠτͷAPIܥαΠτͷ[ΞϓϦཧ]͔Β • ύʔτφʔͷཧը໘ʹʮΞϓϦཧʯ͋Δ͕ɺͦΕShopifyΞϓϦ͚ • ετΞϑϩϯτAPIͱಉը໘ʹ͋ΔʮAdmin APIʯShopifyΞϓϦ͚ • ্ه2ͭShopifyͷΞϓϦΛ࡞Δ࣌ʹ͏APIͷઃఆͱ֤छใ •
ݖݶ͕͍ͷͰɺؒҧͬͯΣϒαΠτߏஙʹ͏ͱɾɾɾ • ʮStoreͷFrontendͷͨΊͷAPIʯ= ʮετΞϑϩϯτAPIʯͱ֮͑Α͏ • ετΞϑϩϯτAPIApple PayAndroidͷܾࡁʹରԠՄೳʢMobile Buy SDKʣ #ShopifyUC -
Agenda • ShopifyͰͷϑϩϯτΤϯυͷ࡞Γํ • ։ൃ༻αΠτ / Storefront APIར༻ͷ४උ • Gatsby(React)ͰShopifyͱ࿈ܞͨ͠αΠτΛ࡞Δ
• What’s your favorite style to make the store? #ShopifyUC -
https://www.gatsbyjs.com/ Gatsby -> Reactϕʔεͷ੩తαΠτδΣωϨʔλʔ • APIϑΝΠϧ͔ΒσʔλΛऔΓࠐΈɺ੩తͳHTMLΛ࡞͢Δπʔϧͷ1ͭ • ੩తαΠτͱͯ͠ެ։͢ΔͷͰɺαʔόʔΛ྿Ձʹ͍͢͠ • ϑϩϯτΤϯυͷίʔυJavaScript
(React)Ͱ࣮ • ϓϥάΠϯγεςϜ͕͋Γɺ༗໊Ͳ͜Ζͷσʔλ΄΅ϊʔίʔυͰऔΓࠐΊΔ • औΓࠐΜͩσʔλΛར༻͢ΔͷʹɺGraphQL͕ඞཁɻ • ʮWebαΠτΛReactͰ࡞Γ͍ͨʯ࣌ʹߴ֬Ͱީิʹग़Δπʔϧͷ1ͭ #ShopifyUC -
gatsby-config.jsʹଓใΛهड़ module.exports = { siteMetadata: { title: `Gatsby Typescript Starter`,
}, plugins: [ `gatsby-plugin-typescript`, { resolve: `gatsby-source-shopify`, options: { // ετΞͷυϝΠϯ shopName: “example.myshopify.com”, // ετΞϑϩϯτAPIͷΞΫηετʔΫϯ accessToken: “xxxxxxxxxxxxxxxxxx”, }, }, ], } #ShopifyUC -
GraphQLͰඞཁͳσʔλ͚ͩऔಘ͢Δ const result = await graphql(` query { allShopifyProduct(sort: {
fields: [title] }) { edges { node { title images { originalSrc } shopifyId handle priceRange { maxVariantPrice { amount } minVariantPrice { amount } } } } } } `)} #ShopifyUC -
GraphQLͰϩʔυ ReactͰHTMLԽ import * as React from 'react' import Link
from 'gatsby-link' import { graphql } from "gatsby" import DefaultLayout from '../layouts' const Page = ({data}: any) => { return ( <DefaultLayout> <div> <article> <h1>Products</h1> <ul> {data.allShopifyProduct.edges.map(({ node }: any) => ( <li key={node.shopifyId}> {node.images[0] && node.images[0].originalSrc ? ( <img src={node.images[0].originalSrc} width={400} /> ): null} <h3> <Link to={`/product/${node.handle}`}>{node.title}</Link> {" - "}${node.priceRange.minVariantPrice.amount} </h3> <p>{node.description}</p> </li> ))} </ul> </article> <Link to="/">Go back to the homepage</Link> </div> </DefaultLayout> ) } • APIΛୟ͔ͳ͍ • ͯ͢GraphQLܦ༝ • ෳͷαʔϏε / APIΛར ༻ͨ͠߹ʹศརͳ #ShopifyUC -
npm i -S \ shopify-buy import * as React from
"react" import {buildClient} from 'shopify-buy' import { Button } from 'antd' … const client = buildClient({ storefrontAccessToken: ‘your_token’, domain: ‘example.myshopify.com', }) const handleCheckout = React.useCallback((variantId: string) => { client.checkout.create() .then(async(checkout) => { const checkoutId = checkout.id await client.checkout.addLineItems( checkoutId, [{ variantId, quantity: 1 }] ) // @ts-expect-error window.open(checkout.webUrl) }) .catch(e => { console.log(e) }) }, [client]) • JavaScriptͰΧʔτૢ࡞ • ײతͳϝιουͰ ShopifyͷAPIΛૢ࡞Մೳ • TypeScriptͳΒ @types/shopify-buyΛ #ShopifyUC -
JamstackͳShopifyϑϩϯτΤϯυߏங • ׳Εͯͳ͍ਓʹͱͬͯਖ਼ͨͩͷ • Jamstack / Next.js / Nuxt.js /
Gatsby / GridsomeͳͲʹ׳Ε͍ͯΔਓʹ࿕ใ • ʮطଘͷϦιʔεɾϊϋΛͬͯShopifyͷαΠτߏங͕͍͔ͨ͠൱͔ʯͷબ • طଘͷϦιʔεɾϊϋ͕ͳ͍߹ʹݫ͍͠ • σʔλιʔε͕͋ͪͪ͜ʹࢄΒ͍ͬͯΔ߹ʹ༗༻ʢಛʹGatsby / Gridsomeʣ • σʔλऩूͱॲཧ͕͔ΕΔͷͰɺஈ֊తͳϚΠάϨͳͲൺֱత༰қʹ #ShopifyUC -
Agenda • ShopifyͰͷϑϩϯτΤϯυͷ࡞Γํ • ։ൃ༻αΠτ / Storefront APIར༻ͷ४උ • Gatsby(React)ͰShopifyͱ࿈ܞͨ͠αΠτΛ࡞Δ
• What’s your favorite style to make the store? #ShopifyUC -
ECΔ͚ͩͳΒ STORESBASE͋Δ • STORES / BASEແྉ • UIαϙʔτຊ͚ • ༗ྉϓϥϯͰShopifyͱಉ͔
ͦΕΑΓ྿Ձʹ͑Δ • ͦΕͰShopifyΛ͏ͷʁ -
API͕ ։͔Ε͍ͯΔ߹ • ίʔυΛॻ͚ɺͳΜͰͰ͖Δ • ػೳʹΑͬͯαϙʔτઌ͕มΘΔ͜ͱ • ࠨ + ʮͲ͏ศརʹ֦ு͍͔ͯ͘͠ʯ
• ࠨ + ֦ுػೳͷ։ൃൢച API͕ ։͔Ε͍ͯͳ͍߹ • Ͱ͖Δ͜ͱ = ϕϯμʔͷϦϦʔε༰ • ͳʹ͔͋ΕϕϯμʔʹରԠґཔ • ʮγεςϜΛͲ͏ૢ࡞͢Δ͔ʯ • ӡ༻ߦ / ઃఆߦͱͯ͠ͷۀ #ShopifyUC -
ॻ͘ / ͢͜ͱͰΑΓਂֶ͍ͼʹͳΔ • ࢼ͢ɾಈ͔͢ஈ֊Ͱʮͳͥಈ͍͔ͨɾͳࣦͥഊ͔ͨ͠ʯΛߟ͑ʹ͍͘ • ϫʔΫγϣοϓͰ৮ͬͯຬͯ͠ɺͦͷޙ৮͍ͬͯͳ͍ͷɻ͋Γ·ͤΜ͔ʁ • Ξτϓοτ͢ΔͨΊʹɺʮͬͨ͜ͱΛݴޠԽ͢Δʯඞཁ͕͋Δ •
ॻ͖ग़ͯ͠ΈΔ͜ͱͰɺʮ࣮Θ͔͍ͬͯͳ͔ͬͨ͜ͱʯ͕ݟ͑ͯ͘Δ • ʮΈΜͳॻ͔ͳ͍ʯ͚ͩͰɺʮΈΜͳࣦഊ֮ͯ͑ͯ͠Δʯ • ࣦഊΛॻ͘ = ࣦഊͷৼΓฦΓ͕Ͱ͖͍ͯΔ • ͳΜͰ͍͍͔Βɺࢼͨ͜͠ͱͷৼΓฦΓΛPublishing͠Α͏ʂ #ShopifyUC -
JamstackͳShopifyϑϩϯτΤϯυߏங • ׳Εͯͳ͍ਓʹͱͬͯਖ਼ͨͩͷ • Jamstack / Next.js / Nuxt.js /
Gatsby / GridsomeͳͲʹ׳Ε͍ͯΔਓʹ࿕ใ • ʮطଘͷϦιʔεɾϊϋΛͬͯShopifyͷαΠτߏங͕͍͔ͨ͠൱͔ʯͷબ • طଘͷϦιʔεɾϊϋ͕ͳ͍߹ʹݫ͍͠ • σʔλιʔε͕͋ͪͪ͜ʹࢄΒ͍ͬͯΔ߹ʹ༗༻ʢಛʹGatsby / Gridsomeʣ • σʔλऩूͱॲཧ͕͔ΕΔͷͰɺஈ֊తͳϚΠάϨͳͲൺֱత༰қʹ #ShopifyUC