marcelsud / shop-api-plugin
为Sylius电子商务平台提供Shop API。
v1.0.1
2017-12-09 08:45 UTC
Requires
- php: ^7.1
- league/tactician-bundle: ^1.0
- league/tactician-doctrine: ^1.1
- sylius/sylius: ^1.0
Requires (Dev)
Suggests
- nelmio/cors-bundle: allows you to send Cross-Origin Ajax API Request
- dev-master
- v1.0.1
- v1.0.0
- v1.0.0-beta.20
- v1.0.0-beta.19
- v1.0.0-beta.18
- v1.0.0-beta.17
- v1.0.0-beta.16
- v1.0.0-beta.15
- v1.0.0-beta.14
- v1.0.0-beta.13
- v1.0.0-beta.12
- v1.0.0-beta.11
- v1.0.0-beta.10
- v1.0.0-beta.9
- v1.0.0-beta.8
- v1.0.0-beta.7
- v1.0.0-beta.6
- v1.0.0-beta.5
- v1.0.0-beta.4
- v1.0.0-beta.3
- v1.0.0-beta.2
- v1.0.0-beta.1
- v1.0.0-alpha.3
- v1.0.0-alpha.2
- v1.0.0-alpha.1
- dev-products-by-code
- dev-yaml-stringing
This package is not auto-updated.
Last update: 2024-09-15 04:26:12 UTC
README
该仓库在Sylius电子商务平台之上提供了一个ShopApi实现。
注意
它也是Sylius - 标准的补充。请检查官方文档以了解基本概念。
先决条件
为了运行此插件,您需要满足以下要求
-
已安装Composer。
$ wget https://getcomposer.org.cn/composer.phar $ php composer.phar create-project -s beta sylius/sylius-standard project
-
已安装Sylius
$ cd project $ php bin/console sylius:install
其余命令都在project
文件夹内执行。
用法
-
运行
composer require sylius/shop-api-plugin
。 -
扩展配置文件
- 将SyliusShopApi添加到AppKernel。
// app/AppKernel.php /** * {@inheritdoc} */ public function registerBundles() { $bundles = [ // ... new \Sylius\ShopApiPlugin\ShopApiPlugin(), new \League\Tactician\Bundle\TacticianBundle(), ]; return array_merge(parent::registerBundles(), $bundles); }
- 将
- { 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" } # ... 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 }
- 将路由添加到
app/config/routing.yml
# app/config/routing.yml # ... sylius_shop_api: resource: "@ShopApiPlugin/Resources/config/routing.yml"
- 配置防火墙
- 将
sylius.security.shop_regex
参数更改为排除shop-api
前缀 - 添加ShopAPI正则表达式参数
shop_api.security.regex: "^/shop-api"
- 添加ShopAPI防火墙配置
- 将
parameters: # ... sylius.security.shop_regex: "^/(?!admin|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
- 调整结账配置以避免与Sylius商店API冲突。例如(假设您使用的是常规Sylius安全定义)
# app/config/config.yml # ... sylius_shop: checkout_resolver: pattern: "%sylius.security.shop_regex%/checkout/"
-
(可选)如果您已安装用于支持跨源Ajax请求的
nelmio/NelmioCorsBundle
,- 将NelmioCorsBundle添加到AppKernel
// app/AppKernel.php /** * {@inheritdoc} */ public function registerBundles() { $bundles = array( // ... new Nelmio\CorsBundle\NelmioCorsBundle(), // ... ); // ... }
- 将配置添加到`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兼容。要检查示例配置,请查看
- security.yml
- jwt参数和jwt配置在config.yml中
- 示例rsa密钥
- 登录请求
来自测试应用。
测试
可以使用API测试用例来测试应用程序。要运行测试套件,请执行以下命令
$ bin/phpunit