shopify主题开发-踩坑记录

shopify主题开发-踩坑记录

对shopify主题二次开发,其中遇到问题在此记录。

官方脚手架搭建教程

第一步 安装 Shopify CLI

Windows

npm install -g @shopify/cli @shopify/theme

第二步 使用 Dawn 初始化一个新主题

shopify theme init

自定义项目名称
进入项目目录

cd glitched-tone-theme

进入项目目录

第三步:启动本地开发服务器

启动服务

shopify theme dev --store {store-name}

输入shopify theme info会提示一下内容
在这里插入图片描述
我们的店铺地址是https://XXX.myshopify.com/ 按照提示,开发者或许会输入一下命令

shopify theme dev --store {XXX}

这时候会出现以下错误
在这里插入图片描述
解决方案

shopify theme dev --store=https://XXX.myshopify.com

成功解决
在这里插入图片描述
此时第二个问题就会出现

"Ruby Environment Not Found" 

ruby下载地址

安装之后 重启 查看版本

ruby -v 

在这里插入图片描述
成功解决
在这里插入图片描述

成功运行
在这里插入图片描述

第三步 二次开发主题

首先是了解目录结构

每个商店主题下有7个目录,在templates目录下有一个customers文件夹,一共8个目录。除此之外,不能有其他的目录。如下:

└── theme
    ├── assets   // assets目录包含主题中使用的所有资源文件,包括图像、CSS和JavaScript文件。
    ├── config  // config目录包含主题的配置文件。 配置文件在主题编辑器的主题设置区域中定义设置,并存储它们的值。
    ├── layout  // layout目录包含主题的布局文件,模板文件通过这些文件呈现。 
    ├── locales  // locale目录包含主题的locale文件,这些文件用于提供翻译后的内容。 Locale文件允许您在主题编辑器中提供翻译体验,为在线商店提供翻译,并允许商家在在线商店中定制文本。
    ├── sections  // sections目录包含一个主题的sections。
    ├── snippets  // snippets目录包含较小的可重用代码片段的Liquid文件。 您可以使用Liquid render标记在整个主题中引用这些片段。
    └── templates  // templates目录下的每一个json文件是一个模板,每一个模板对应着一个页面。
        └── customers
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
要在基于@shopify/shopify-app-express的应用程序中注册Shopify Webhook,可以使用该框架提供的webhook路由。下面是一个示例代码来注册一个Webhook: ```javascript const { default: createShopifyAuth } = require('@shopify/koa-shopify-auth'); const { default: Shopify, ApiVersion } = require('@shopify/shopify-api'); const { verifyRequest } = require('@shopify/koa-shopify-auth'); const Koa = require('koa'); const Router = require('koa-router'); const bodyParser = require('koa-bodyparser'); const app = new Koa(); const router = new Router(); const webhook = { topic: 'products/create', address: 'https://your-app.com/webhooks/products/create', format: 'json', }; app.use(bodyParser()); const shopifyAuth = createShopifyAuth({ // Your Shopify app API key and secret apiKey: process.env.SHOPIFY_API_KEY, secret: process.env.SHOPIFY_API_SECRET, // Your app URL appUrl: process.env.APP_URL, // Scopes to request on the merchant's behalf scopes: ['read_products', 'write_products', 'read_script_tags', 'write_script_tags'], // After authentication, redirect to the shop's home page afterAuth(ctx) { const { shop } = ctx.state.shopify; ctx.redirect(`https://${shop}/admin/apps/${process.env.SHOPIFY_API_KEY}`); }, }); // Register webhook router.post('/webhooks/products/create', verifyRequest({ returnHeader: true }), (ctx) => { console.log('New product created:', ctx.request.body); ctx.status = 200; }); (async function() { // Create an instance of Shopify const shopify = new Shopify({ apiKey: process.env.SHOPIFY_API_KEY, apiSecretKey: process.env.SHOPIFY_API_SECRET, shopName: ctx.session.shop, accessToken: accessToken, apiVersion: ApiVersion.October20, autoLimit: { calls: 2, interval: 1000, bucketSize: 35 }, }); // Register webhook await shopify.webhook.create(webhook); // Use the shopifyAuth middleware app.use(shopifyAuth); app.use(router.allowedMethods()); app.use(router.routes()); app.listen(process.env.PORT, () => { console.log(`Server listening on port ${process.env.PORT}`); }); })(); ``` 在上面的代码中,我们首先创建一个Shopify实例,并使用它来注册Webhook。然后,我们使用@shopify/shopify-app-express框架创建一个HTTP服务器,并为Webhook的URL路径创建一个POST路由。在路由处理程序中,我们可以处理接收到的Webhook数据。最后,我们使用Shopify API将Webhook注册到商店中。 注意,我们在Webhook地址中使用了公共URL,这意味着您需要在您的应用程序中设置公共URL,并将其用作Webhook地址。此外,您需要在Shopify后台中配置相应的Webhook主题,以便将Webhook发送到正确的URL地址。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值