如何使用 shopify_app gem 的 webhooks?

How to use webhooks with shopify_app gem?

在过去的几个小时里,我一直在尝试使用官方 shopify_app gem.

向我的 Shopify 应用程序添加一个 webhook

所以我 运行 rails g shopify_app:add_webhook -t products/update -a https://example.com/webhooks/products_update 看到每个文件都按预期生成,在测试商店中安装我的应用程序后检查日志也显示 webhook 已成功启动。

然而,在商店中实际更新产品后,我收到一条错误消息:

ShopifyApp::MissingWebhookJobError (ShopifyApp::MissingWebhookJobError):

shopify_app (7.2.9) app/controllers/shopify_app/webhooks_controller.rb:21:in `webhook_job_klass'
shopify_app (7.2.9) app/controllers/shopify_app/webhooks_controller.rb:10:in `receive'
actionpack (5.0.3) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'

...继续大约 40 行并在大约 10-30 秒后重复自身,然而,在抛出它之前向我展示了参数。我没有更改 products_job.rb,所以它仍然看起来像这样:(虽然我已经尝试更改了很多次)

class ProductsJob < ActiveJob::Base
  def perform(shop_domain:, webhook:)
    shop = Shop.find_by(shopify_domain: shop_domain)

    shop.with_shopify_session do
    end
  end
end

我真的很乐意就此获得任何意见,因为我是 Shopify 应用程序和 Rails 的新手(您可能会说 ^^)

谢谢,乔治

安装 webhook 后,您是否重新启动了 rails 服务器。 请重新启动您的 rails 服务器,同时在 shopify 商店中卸载并重新安装您的应用程序,然后在单击安装按钮之前检查安装页面中相应的 webhook 是否可用。

您的产品更新作业文件名应该像 products_update_job.rb 而不是 products_job.rb 并且内容应该如下所示:

class ProductsUpdateJob < ActiveJob::Base
  def perform(shop_domain:, webhook:)
    shop = Shop.find_by(shopify_domain: shop_domain)

    shop.with_shopify_session do
    end
  end
end

试试这个改变你会得到它。