codecloud/symfony-shopify-bundle

让Shopify应用开发变得简单

1.0.0 2015-04-08 16:30 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:38:28 UTC


README

此包允许快速轻松地与Shopify集成。

Build Status on Travis Scrutinizer Quality Score

特性

  • 带有少量配置选项的Shopify OAuth注册流程。
  • 围绕Guzzle的轻量级包装,方便API交互。所有API端点均受支持。
  • Symfony防火墙验证传入的API请求是否经过认证(以嵌入Shopify Admin)
  • 支持Webhook以监听Shopify事件。

商店模型

商店由ShopifyStoreInterface的实例表示。您需要提供其实现并处理持久性。

OAUTH配置

// app/confiy.yml

code_cloud_shopify:
    store_manager_id: { id of your store manager service }
    oauth:
        api_key: { your app's API Key }
        shared_secret: { your app's shared secret } 
        scope: { the scopes your app requires, i.e.: "read_customers,write_customers" }
        redirect_route: { the route to redirect users to after installing the app, i.e.: "admin_dashboard".. }
    webhooks:
        - orders/create
        - customers/update

API使用

您可以通过``服务访问授权商店的API。

// in Controller

$api = $this->get('')->getForStore("name-of-store");

$customers = $api->Customer->findAll();
$orders = $api->Order->findAll();

Webhook

您可以注册您感兴趣接收的Webhook列表。当接收到Webhook时,包将自动将其注册到Shopify并触发事件。

<?php

namespace AppBundle\Event;

use CodeCloud\Bundle\ShopifyBundle\Event\WebhookEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class WebhookListener implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            WebhookEvent::NAME => 'onWebhook',
        ];
    }

    public function onWebhook(WebhookEvent $event)
    {
        switch ($event->getTopic()) {
            case 'orders/create':
                // your custom logic here
                break;
            case 'orders/update':
                // your custom logic here
                break;
        }
    }
}

安全与认证

默认情况下,该包为Shopify内嵌入的行政区域提供基于会话的认证。

security:
    providers:
        codecloud_shopify:
            id: codecloud_shopify.security.admin_user_provider

    firewalls:
        admin:
            pattern: ^/admin
            provider: codecloud_shopify
            guard:
                authenticators:
                    - codecloud_shopify.security.session_authenticator

经过认证的用户将是一个CodeCloud\Bundle\ShopifyBundle\Security\ShopifyAdminUser实例,其用户名将是经过认证的商店名称(storename.myshopify.com),并且他们的角色将包括ROLE_SHOPIFY_ADMIN

出于开发目的,您可以模拟任何现有商店。

# in config_dev.yml
code_cloud_shopify:
    dev_impersonate_store: "{store-name}.myshopify.com"

致谢

非常感谢David Smith最初创建此包。