Code Monkey home page Code Monkey logo

shopapiplugin's Introduction

Sylius Logo.

Sylius Shop API

License Build Status Scrutinizer Quality Score

This repository contains a plugin that extends the Sylius eCommerce platform with an API in JSON that allows performing all standard shop operations from the customer perspective.

Documentation

The latest documentation is available here. If you are looking for more information how the system works have a look at the cookbook

Installation

IMPORTANT NOTE: Before installing SyliusShopApiPlugin, you should disable all SyliusShopBundle's dependencies. You cannot use these packages together.

  1. Run composer require sylius/shop-api-plugin and, when asked if you want to execute the Flex recipe, answer 'Yes'.

  2. Extend config files:

    1. Add SyliusShopApi to config/bundles.php.
    // config/bundles.php
    
        return [
            Sylius\ShopApiPlugin\SyliusShopApiPlugin::class => ['all' => true],
        ];
    1. Add - { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true } to fos_rest.format_listener.rules section in config/packages/fos_rest.yaml file and import config from Plugin.
    # config/packages/_sylius_shop_api.yaml
    
    imports: # <-- Add this section if it does not already exist and add the lines below
        # ...
        - { resource: "@SyliusShopApiPlugin/Resources/config/app/config.yml" }
        - { resource: "@SyliusShopApiPlugin/Resources/config/app/sylius_mailer.yml" }
    
    # config/packages/fos_rest.yaml
    
    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 new routes file to import routes from the SyliusShopApiPlugin
    # config/routes/sylius_shop_api.yaml
    
    sylius_shop_api:
        resource: "@SyliusShopApiPlugin/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 sylius_shop_api.security.regex: "^/shop-api"
      3. Add ShopAPI firewall config:
        • Symfony 6:

          # config/packages/security.yaml
          
          parameters:
              # ...
          
              sylius.security.shop_regex: "^/(?!admin|api/.*|api$|shop-api|media/.*)[^/]++" # shop-api has been added inside the brackets
              sylius_shop_api.security.regex: "^/shop-api"
          
          # ... 
          
          security:
              firewalls:
                  // ...
          
                  sylius_shop_api:
                      pattern: "%sylius_shop_api.security.regex%"
                      stateless: true
                      entry_point: jwt
                      provider: sylius_shop_user_provider
                      json_login:
                          check_path: /shop-api/login
                          username_path: email
                          password_path: password
                          success_handler: lexik_jwt_authentication.handler.authentication_success
                          failure_handler: lexik_jwt_authentication.handler.authentication_failure
                      jwt: true
             access_control:
             - { path: "%sylius_shop_api.security.regex%/address-book", role: ROLE_USER}
             - { path: "%sylius_shop_api.security.regex%/me", role: ROLE_USER}
        • Symfony 5:

          # config/packages/security.yaml
          
          parameters:
              # ...
          
              sylius.security.shop_regex: "^/(?!admin|api/.*|api$|shop-api|media/.*)[^/]++" # shop-api has been added inside the brackets
              sylius_shop_api.security.regex: "^/shop-api"
          
          # ... 
          
          security:
              firewalls:
                  // ...
          
                  sylius_shop_api:
                      pattern: "%sylius_shop_api.security.regex%"
                      stateless: true
                      anonymous: true
                      provider: sylius_shop_user_provider
                      json_login:
                          check_path: /shop-api/login
                          username_path: email
                          password_path: password
                          success_handler: lexik_jwt_authentication.handler.authentication_success
                          failure_handler: lexik_jwt_authentication.handler.authentication_failure
                      guard:
                          authenticators:
                              - lexik_jwt_authentication.jwt_token_authenticator
             access_control:
             - { path: "%sylius_shop_api.security.regex%/address-book", role: ROLE_USER}
             - { path: "%sylius_shop_api.security.regex%/me", role: ROLE_USER}
    2. (optional) if you have installed nelmio/NelmioCorsBundle for Support of Cross-Origin Ajax Request,

      1. Add the NelmioCorsBundle to the AppKernel
      // config/bundles.php
      
      return [
          Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
      ];
      1. Add the new configuration file
      # config/packages/nelmio_cors.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', 'PATCH', 'OPTIONS']
                  max_age: 3600
  3. Follow https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/index.rst#installation

Sample configuration of Shop API can be found here: https://github.com/Sylius/SyliusDemo/commit/4872350dcd6c987d54dec1f365b4bb890d7183c9

Additional features

Attributes

If you would like to receive serialized attributes you need to define an array of theirs codes under sylius_shop_api.included_attributes key. E.g.

# config/packages/sylius_shop_api.yml
sylius_shop_api:
    included_attributes:
        - "MUG_MATERIAL_CODE"

This plugin comes with an integration with LexikJWTAuthenticationBundle. More information about security customizations may be found there.

Testing

The application can be tested with API Test Case. In order to run test suite execute the following commands:

$ cp tests/Application/.env.test.dist tests/Application/.env.test
$ set -a && source tests/Application/.env.test && set +a
$ (cd tests/Application && bin/console doctrine:database:create -e test)
$ (cd tests/Application && bin/console doctrine:schema:create -e test)

$ vendor/bin/phpunit

The application can be also tested with PHPSpec:

$ vendor/bin/phpspec run

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 [email protected].

Maintenance

This library is officially maintained by Sylius together with the following contributors outside of the organization:

Release cycle

This projects follows Semantic Versioning. Shop API release cycle is independent from Sylius release cycle.

Next major releases are not planned yet. Minor and patch releases will be published as needed.

We provide bug fixes only for the most recent minor release. We provide security fixes for one year since the release of subsequent minor release.

Supported versions

Version Release date End of support
1.0 23rd Nov 2019 19th June 2021
1.1 19th June 2020 08th December 2020
1.2 08th December 2020 22th April 2021
1.2.1 22th April 2021 22th April 2021
1.3 22th April 2021 22th April 2021
1.3.1 22th April 2021 30th June 2021
1.4 30th June 2021 06th July 2021
1.4.1 06th July 2021 20th July 2022
1.5 20th July 2022 21th July 2022
1.5.1 21th July 2022 13th January 2023
1.6 13th January 2023

shopapiplugin's People

Contributors

adamkasp avatar adrianmarte avatar alexander-schranz avatar amr3zzat avatar antonioperic avatar arminek avatar bartoszpietrzak1994 avatar bitbager avatar cboita avatar clem21 avatar cschulz avatar dennisdebest avatar diimpp avatar dlobato avatar gorkalaucirica avatar gsadee avatar hailong avatar jakobtolkemit avatar jseparovic1 avatar klederson avatar lchrusciel avatar mamazu avatar medteck avatar pamil avatar pjedrzejewski avatar teohhanhui avatar themilek avatar timesplinter avatar tomanhez avatar zales0123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shopapiplugin's Issues

Initialize the bundle

  • Basic bundle structure
  • README with initial installation notes
  • Testing infrastructure
  • Travis Configuration

[Feature Request] Products GRID

Currently, the implementation does not allow to sort paginated products page or reduce an amount of records. We need to add a grid to it.

Missing general total

The total response looks like this:

    "totals": {
        "items": 9995,
        "taxes": 0,
        "shipping": 1500,
        "promotion": 0
    }

We are missing summarized total amount.

Price handler

Currently, we are returning only one price on the product. Because of original pricing and in order to not break a contract in future we should go with and object instead.
This:

    "price": 1999

should be changed to:

    "price": {
        "current": 1999
    }

[RFC] Should the price and cost be unified?

Right now each price representation is unified to:

    "price": {
        "current": 1500
    }

But in a scope of shipping or payments, it is not a price itself. Should the key be renamed for something like cost? Also, do we need for a cost object or just an integer value would be enough?

Locale fallbacks

We should use fallback translation if product/taxon does not exist in given locale.

[RFC] Naming convention

The plugin should be named Sylius/ShopApiPlugin to keep our current naming convention. The same way config files has been named (src/ShopApiPlugin). Other possibility is to rename the plugin file and adjust README form #39.

Doctrine persist error when adding a product with options

Steps to reproduce: On sample data setup, pick a product with options (sticker) and do this request:

{
	"productCode": "010ab7d7-4e2d-3410-9c10-10122e3c1aef",
	"options": {
		"sticker_size": "sticker_size_3"	
	},
	"quantity": 2
}

I got:

{
  "code": 500,
  "message": "A new entity was found through the relationship 'Sylius\\Component\\Core\\Model\\OrderItemUnit#orderItem' that was not configured to cascade persist operations for entity: Sylius\\Component\\Core\\Model\\OrderItem@000000004b16a3e0000000006a74788a. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist  this association in the mapping for example @ManyToOne(..,cascade={\"persist\"}). If you cannot find out which entity causes the problem implement 'Sylius\\Component\\Core\\Model\\OrderItem#__toString()' to get a clue."
}

[RFC] Translatable products

On a product list, the query is built with a locale code. As a result, some of the records can be missed if a product does not have a translation in this locale. Probably, we should use a fallback locale and normally display all of the products for given channel.

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.