brille24/sylius-shop-api-plugin

该软件包已被废弃且不再维护。作者建议使用 sylius/shop-api-plugin 软件包。

Sylius 电子 commerce 的商店 API。

安装: 426

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 1

分支: 52

类型:sylius-plugin


README

Sylius Shop API

68747470733a2f2f64656d6f2e73796c6975732e636f6d2f6173736574732f73686f702f696d672f6c6f676f2e706e67

Sylius Shop API

License Version Build Status Scrutinizer Quality Score

此仓库在 Sylius E-Commerce 平台之上提供了 ShopApi 实现。

注意

这只是 Sylius - Standard 的补充。请查看 官方文档 以理解基本概念。

先决条件

为了运行此插件,您需要满足以下要求

  1. 已安装 composer Composer

    $ wget https://getcomposer.org.cn/composer.phar
    $ php composer.phar create-project sylius/sylius-standard project
  2. 已安装 Sylius

    $ cd project
    $ php bin/console sylius:install

其余的命令在 project 文件夹中执行。

使用方法

  1. 运行 composer require sylius/shop-api-plugin:^1.0@beta

  2. 扩展配置文件

    1. 将 SyliusShopApi 添加到 AppKernel。
    // app/AppKernel.php
    
        public function registerBundles(): array
        {
            return array_merge(parent::registerBundles(), [
                new \Sylius\ShopApiPlugin\ShopApiPlugin(),
                new \League\Tactician\Bundle\TacticianBundle(),
            ]);
        }
    1. - { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true } 添加到 app/config/config.yml 文件中的 fos_rest.format_listener.rules 部分,并从插件导入配置。
    # app/config/config.yml
    
    imports:
        # ...
        - { resource: "@ShopApiPlugin/Resources/config/app/config.yml" }
        - { resource: "@ShopApiPlugin/Resources/config/app/sylius_mailer.yml" }
    
    # ...
    
    fos_rest:
        # ...
        
        format_listener:
            rules:
                - { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true } # <-- Add this
                - { path: '^/api', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
                - { path: '^/', stop: true }
    
    1. 调整结账配置,以避免与 Sylius 商店 API 冲突。例如(假设您正在使用常规 Sylius 安全定义)
    # app/config/config.yml
    
    # ...
    
    sylius_shop:
        checkout_resolver:
            pattern: "%sylius.security.shop_regex%/checkout/.+"
    1. 添加路由到 app/config/routing.yml
    # app/config/routing.yml
    
    # ...
    
    sylius_shop_api:
        resource: "@ShopApiPlugin/Resources/config/routing.yml"
    1. 配置防火墙
      1. sylius.security.shop_regex 参数更改为排除 shop-api 前缀
      2. 添加 ShopAPI 正则表达式参数 shop_api.security.regex: "^/shop-api"
      3. 添加 ShopAPI 防火墙配置
    parameters:
        # ...
    
        sylius.security.shop_regex: "^/(?!admin|api/.*|api$|shop-api)[^/]++" # shop-api has been added inside the brackets
        shop_api.security.regex: "^/shop-api"
    
    # ... 
    
    security:
        firewalls:
            // ...
    
            shop_api:
                pattern: "%shop_api.security.regex%"
                stateless:  true
                anonymous:  true
    1. (可选) 如果您已安装 nelmio/NelmioCorsBundle 以支持跨源 Ajax 请求

      1. 将 NelmioCorsBundle 添加到 AppKernel
      // app/AppKernel.php
      
      /**
       * {@inheritdoc}
       */
      public function registerBundles()
      {
          $bundles = array(
              // ...
              new Nelmio\CorsBundle\NelmioCorsBundle(),
              // ...
          );
          // ...
      }
      1. 将配置添加到 `config.yml`
      # app/config/config.yml
      
      # ...
      
      nelmio_cors:
          defaults:
              allow_credentials: false
              allow_origin: []
              allow_headers: []
              allow_methods: []
              expose_headers: []
              max_age: 0
              hosts: []
              origin_regex: false
              forced_allow_origin_value: ~
          paths:
              '^/shop-api/':
                  allow_origin: ['*']
                  allow_headers: ['Content-Type', 'authorization']
                  allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'OPTIONS']
                  max_age: 3600

附加功能

属性

如果您想要接收序列化属性,您需要在 shop_api.included_attributes 键下定义它们的代码数组。例如。

shop_api:
    included_attributes:
        - "MUG_MATERIAL_CODE"

授权

默认情况下,此包不提供授权。但它与 LexikJWTAuthenticationBundle 一起进行了测试。要检查示例配置,请查看

来自测试应用。

测试

可以使用 API 测试用例测试应用程序。要运行测试套件,请执行以下命令

$ bin/phpunit

PHPStan

PHPStan 是一个用于分析 PHP 类型的工具。问题是基础 API 不支持 PHPStan,并且仍在使用 PHP 7.1 运行,这意味着安装 PHPStan 将导致向后兼容性破坏。

安全问题

如果您认为您发现了安全问题,请不要使用问题跟踪器并不要公开发布。相反,所有安全问题都必须发送至 security@sylius.com