Giter Club home page Giter Club logo

syliusshopapiplugin's Introduction

Sylius Shop API License Version Build Status on linux Scrutinizer Quality Score

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:

  1. Installed composer Composer.

    $ wget http://getcomposer.org/composer.phar
    $ php composer.phar create-project -s beta sylius/sylius-standard project
  2. Installed Sylius

    $ cd project
    $ php bin/console sylius:install

Rest of the command are executed inside project folder.

Usage

  1. Run composer require sylius/shop-api-plugin.

  2. Extend config files:

    1. Add SyliusShopApi to AppKernel.
    // app/AppKernel.php
    
        /**
         * {@inheritdoc}
         */
        public function registerBundles()
        {
            $bundles = [
                // ...
    
                new \Sylius\ShopApiPlugin\ShopApiPlugin(),
                new \League\Tactician\Bundle\TacticianBundle(),
            ];
    
            return array_merge(parent::registerBundles(), $bundles);
        }
    1. Add - { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true } to fos_rest.format_listener.rules section in app/config/config.yml file and import config from Plugin.
    # 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 }
    
    1. Add routing to app/config/routing.yml
    # app/config/routing.yml
    
    # ...
    
    sylius_shop_api:
        resource: "@ShopApiPlugin/Resources/config/routing.yml"
    1. Configure firewall
      1. Change sylius.security.shop_regex parameter to exclude shop-api prefix also
      2. Add ShopAPI regex parameter shop_api.security.regex: "^/shop-api"
      3. Add ShopAPI firewall config:
    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
    1. 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/.+"
    1. (optional) if you have installed nelmio/NelmioCorsBundle for Support of Cross-Origin Ajax Request,

      1. Add the NelmioCorsBundle to the AppKernel
      // app/AppKernel.php
      
      /**
       * {@inheritdoc}
       */
      public function registerBundles()
      {
          $bundles = array(
              // ...
              new Nelmio\CorsBundle\NelmioCorsBundle(),
              // ...
          );
          // ...
      }
      1. 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

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

syliusshopapiplugin's People

Contributors

lchrusciel avatar pjedrzejewski avatar pamil avatar zales0123 avatar arminek avatar hailong avatar klederson avatar

Watchers

James Cloos avatar Nicolas Paulhan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.