brille24 / sylius-shop-api-plugin
Shop API for Sylius E-Commerce.
Installs: 426
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 52
Type:sylius-plugin
Requires
- php: ^7.1
- brille24/sylius-customer-options-plugin: dev-master
- brille24/sylius-tierprice-plugin: dev-master
- brille24/sylius-wishlist-plugin: dev-master
- league/tactician-bundle: ^1.1
- league/tactician-doctrine: ^1.1
- phpstan/phpstan-shim: ^0.10.1
- sylius/sylius: ^1.1
Requires (Dev)
- lakion/api-test-case: ^3.1
- lexik/jwt-authentication-bundle: ^2.5
- matthiasnoback/symfony-config-test: ^3.1
- matthiasnoback/symfony-dependency-injection-test: ^2.3
- phpspec/phpspec: ^5.0
- phpstan/phpstan-shim: ^0.10.3
- phpstan/phpstan-webmozart-assert: ^0.10.0
- phpunit/phpunit: ^6.5
- sylius-labs/coding-standard: ^2.0
Suggests
- nelmio/cors-bundle: allows you to send Cross-Origin Ajax API Request
- dev-master
- 1.0.1
- 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-merge_downstream
- dev-channel_provider
- dev-peter
- dev-test
- dev-wishlist_refactoring
- dev-fixed_api_branch
- dev-order_endpoint
- dev-reorder
- dev-addresses
- dev-tierprice
- dev-wishlist_customer_options
- dev-wishlist
- dev-email_verification
- dev-expose_customer_orders
- dev-products-by-code
- dev-yaml-stringing
This package is auto-updated.
Last update: 2021-04-12 15:28:07 UTC
README
Sylius Shop API
Sylius Shop API
This repository provides a ShopApi implementation on the top of Sylius E-Commerce platform
Beware
It is also just an addition to Sylius - Standard. Please, check official documentation in order to understand the basic concepts.
Pre - requirements
In order to run this plugin you need to fulfill following requirements:
-
Installed composer Composer.
$ wget http://getcomposer.org/composer.phar $ php composer.phar create-project sylius/sylius-standard project
-
Installed Sylius
$ cd project $ php bin/console sylius:install
Rest of the command are executed inside project
folder.
Usage
-
Run
composer require sylius/shop-api-plugin:^1.0@beta
. -
Extend config files:
- Add SyliusShopApi to AppKernel.
// app/AppKernel.php public function registerBundles(): array { return array_merge(parent::registerBundles(), [ new \Sylius\ShopApiPlugin\ShopApiPlugin(), new \League\Tactician\Bundle\TacticianBundle(), ]); }
- Add
- { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true }
tofos_rest.format_listener.rules
section inapp/config/config.yml
file and import config from Plugin.
# 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 }
- Adjust checkout configuration to not collide with Sylius shop API. For example (assuming, that you are using regular Sylius security definition):
# app/config/config.yml # ... sylius_shop: checkout_resolver: pattern: "%sylius.security.shop_regex%/checkout/.+"
- Add routing to
app/config/routing.yml
# app/config/routing.yml # ... sylius_shop_api: resource: "@ShopApiPlugin/Resources/config/routing.yml"
- Configure firewall
- Change
sylius.security.shop_regex
parameter to excludeshop-api
prefix also - Add ShopAPI regex parameter
shop_api.security.regex: "^/shop-api"
- Add ShopAPI firewall config:
- Change
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
-
(optional) if you have installed
nelmio/NelmioCorsBundle
for Support of Cross-Origin Ajax Request,- Add the NelmioCorsBundle to the AppKernel
// app/AppKernel.php /** * {@inheritdoc} */ public function registerBundles() { $bundles = array( // ... new Nelmio\CorsBundle\NelmioCorsBundle(), // ... ); // ... }
- Add the configuration to the `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
Additional features
Attributes
If you would like to receive serialized attributes you need to define an array of theirs codes under shop_api.included_attributes
key. E.g.
shop_api: included_attributes: - "MUG_MATERIAL_CODE"
Authorization
By default no authorization is provided together with this bundle. But it is tested to work along with LexikJWTAuthenticationBundle In order to check example configuration check
- security.yml
- jwt parameters and jwt config in config.yml
- example rsa keys
- login request
From the test app.
Testing
The application can be tested with API Test Case. In order to run test suite execute the following command:
$ bin/phpunit
PHPStan
PHPstan is a tool to analyse PHP types. The problem is that the base API does not support phpstan and is still running on PHP 7.1 which would mean that installing PHPstan would be a backwards compatibility break.
Security issues
If you think that you have found a security issue, please do not use the issue tracker and do not post it publicly.
Instead, all security issues must be sent to security@sylius.com
.