swordfox/silverstripe-shopify

将Shopify产品导入您的Silverstripe网站,实现了购买按钮SDK以创建购物车和结账

安装次数: 1,175

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 3

分支: 2

类型:silverstripe-vendormodule


README

本模块适用于希望将Shopify产品导入SilverStripe商店的用户。

基于xddesigners/silverstripe-shopify - 但已完全重构。

  • 按产品分别添加/删除收藏夹。
  • 导入任务具有选项:默认、仅产品 & 所有产品(见下文“设置导入脚本”)。
  • 模板中包含购买按钮脚本,以便轻松修改和以您自己的方式实现。
  • 移除了版本控制。
  • 不会从Shopify导入图片,而是使用Images.weserv.nl - 一个图片缓存和缩放服务。
  • 可选:从Shopify获取Webhooks以保持商店更新,无需依赖可能消耗资源的导入任务(见下文“设置Webhooks”)。
  • 可选:对于希望在产品售出后在Shopify中删除产品的商店,delete_on_shopify很有用,适用于一次性产品的商店(见下文“设置delete_on_shopify”)。

使用Shopify Buy Button来创建购物车和结账界面。
您将获得一个导入任务,该任务获取所有产品变体并将它们存储在您的网站上的Product DataObject中。

要求

  • SilverStripe 4.x

安装

通过Composer安装模块并配置API密钥。

composer require swordfox/silverstripe-shopify

在Shopify管理员界面中创建一个新的私有应用以获取API密钥。如果您想通过API使用Webhooks,例如dev/tasks/Swordfox-Shopify-Task-Webhooks/create,请确保'webhooks_shared_secret'与'shared_secret'相同,但如果您想使用手动添加的Webhooks,则需要从admin/settings/notifications获取Webhooks共享密钥。

配置

Swordfox\Shopify\Client:
  api_key: 'YOUR_API_KEY'
  api_password: 'YOUR_API_PASSWORD'
  api_limit: 50 # Default limit, 250 max
  api_version: '2021-01' # Default 2021-01
  storefront_access_token: 'YOUR_ACCESS_TOKEN' # for buybutton code
  shopify_domain: 'YOUR_SHOPIFY_DOMAIN' # mydomain.myshopify.com
  shared_secret: 'YOUR_API_SHARED_SECRET'
  webhooks_shared_secret: 'YOUR_WEBHOOKS_SHARED_SECRET' # Use same as above for webhooks added via API e.g. dev/tasks/Swordfox-Shopify-Task-Webhooks/create
  webhooks_create:
    'products/update': 'shop/webhook/update/product'
    'products/create': 'shop/webhook/update/product'
    'products/delete': 'shop/webhook/delete/product'
    'collections/create': 'shop/webhook/update/collection'
    'collections/update': 'shop/webhook/update/collection'
    'collections/delete': 'shop/webhook/delete/collection'
    'inventory_levels/connect': 'shop/webhook/update/inventory'
    'inventory_levels/update': 'shop/webhook/update/inventory'
  delete_on_shopify: false
  delete_on_shopify_after: '+3 days' # strtotime('+3 days')
  delete_on_shopify_keep_active: false
  hide_out_of_stock: false
  hide_if_no_image: false
  hide_if_collection_not_active: false
  new_based_on: 'Created' # LastEdited or ImageAdded (use with hide_if_no_image)
  new_timeframe: '+7 days' # strtotime('+7 days')
  cron_interval: '-18 hours' # Allow for timezone offset, e.g. if your timezone is +12:00, add your cron_interval to that as a negative value. So if your cron runs every 6 hours, set the cron_interval to '-18 hours'
  custom_metafields: true # product.metafields.custom.metatitle & product.metafields.custom.brand
  googlefeed_gtinbarcode: false # Show gtin as Barcode from Shopify
  googlefeed_mpnsku: true # Show mpn as SKU from Shopify
  googlefeed_condition: new # The condition of items

# Override $default_sort
Swordfox\Shopify\Model\Product:
  default_sort: 'Created DESC' # LastEdited DESC or ImageAdded DESC

设置导入脚本

您可以通过dev/tasks界面手动运行导入脚本,或将它们设置为cron任务。默认任务设计为每天运行一次,导入/更新最新的50个api_limitadmin/products.jsonadmin/custom_collections.jsonadmin/smart_collections.jsonhttp://example.com/dev/tasks/Swordfox-Shopify-Task-Importsake dev/tasks/Swordfox-Shopify-Task-Import

仅产品任务设计为在不使用Webhooks的情况下每天运行几次,导入最新的50个api_limitadmin/products.json

http://example.com/dev/tasks/Swordfox-Shopify-Task-Import/productsonlysake dev/tasks/Swordfox-Shopify-Task-Import/productsonly

所有产品任务设计为在初始设置时运行,并从admin/products.jsonadmin/custom_collections.jsonadmin/smart_collections.json导入所有内容。

http://example.com/dev/tasks/Swordfox-Shopify-Task-Import/productsallsake dev/tasks/Swordfox-Shopify-Task-Import/productsall

设置Webhooks

以下Webhooks受支持,并且可以通过API使用http://example.com/dev/tasks/Swordfox-Shopify-Task-Webhooks/createsake dev/tasks/Swordfox-Shopify-Task-Webhooks/create自动创建。

Shopify webhooks

设置 delete_on_shopify

您可以通过 dev/tasks 接口手动运行 Shopify 上的删除脚本,或者设置成定时任务。此任务适用于销售一次性产品的商店,并在一定时间后将产品从 Shopify 上删除。例如,在导入任务中设置 ShopifyProduct::DeleteOnShopify 时,使用 delete_on_shopify_after: '+3 days',如果 delete_on_shopify: true

http://example.com/dev/tasks/Swordfox-Shopify-Task-DeleteOnShopifysake dev/tasks/Swordfox-Shopify-Task-DeleteOnShopify