Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Insight into the Shopware 6 core architecture

Insight into the Shopware 6 core architecture

With Shopware 6, the architecture was rethought from scratch and adapted to today's eCommerce.

In this session, Jan Bücker and Jonas Elfering will give you a deeper insight into the PHP-side architecture and functionality. All important and interesting sections from Context to the Data Abstraction Layer are introduced to you step by step, so that you are prepared to get started with Shopware 6.

Jan Bücker

May 23, 2019
Tweet

Other Decks in Technology

Transcript

  1. 56
    Developers have contributed to the platform

    View Slide

  2. 7500+
    commits were made to build v6.0.0+dp1

    View Slide

  3. 31bfd704
    First commit on Shopware 6

    View Slide

  4. Insight into the core architecture
    Jan Bücker, Jonas Elfering

    View Slide

  5. Jan Bücker
    Developer Core
    ➜ 4 years at shopware AG
    ➜ Born ‘89
    ➜ Say hi on twitter @janbuecker
    ➜ I music!

    View Slide

  6. ➜ @shopware since 2017
    ➜ @keulinho
    ➜ @j_elfering
    Jonas Elfering
    Developer Enterprise

    View Slide

  7. Attention!
    This talk is based on v6.0.0+dp1 and implementations
    may change with upcoming releases.

    View Slide

  8. Attention!
    This talk is based on v6.0.0+dp1 and implementations
    may change with upcoming releases.
    already changed

    View Slide

  9. Agenda
    ● Project structure
    ● API
    ● Context
    ● Translations
    ● Data Abstraction Layer
    ● Cart
    ● Business Events

    View Slide

  10. Getting the
    names right
    ● Project template ?
    ● Platform ?
    ● Shopware 6 ?

    View Slide

  11. Project template
    Blueprint for projects
    Tailored for specific needs e.g.
    ● Production (high performance)
    ● Development (debugging)
    ● Cloud hosting specific
    customization (AWS, GCP,
    Azure)
    ● Overwrite default config values
    Project template • Platform • Shopware 6

    View Slide

  12. Platform
    Mono repository for
    Shopware 6 modules
    ● One repository containing all
    modules
    ● Easy to make changes across
    all modules to maintain stability
    ● Split into Many-Repositories
    ● Contributions go here
    Project template • Platform • Shopware 6 https://github.com/shopware/platform

    View Slide

  13. Many
    Repositories
    Composable bundles, that are
    structured by domain
    ● Core
    ● Administration
    ● Storefront
    ● Docs
    These are read-only. Do not
    contribute to them.
    Project template • Platform • Shopware 6

    View Slide

  14. Shopware 6
    The Product
    Project template +
    ● Core
    ● Administration
    ● Storefront
    ● Plugins
    Project template • Platform • Shopware 6

    View Slide

  15. Technical requirements

    View Slide

  16. Technical
    requirements
    ● Web server running php
    ● PHP >= 7.2
    ● MySQL >= 5.7 (MariaDB >= 10.3)
    ○ High group_concat_max_len
    Optional
    ● Node.js >= 8.10
    ● NPM >= 6.5

    View Slide

  17. API
    Build headless eCommerce

    View Slide

  18. API != API
    Building headless eCommerce

    View Slide

  19. API
    ● Admin API
    ● Sync API
    ● Sales Channel API

    View Slide

  20. Admin API
    ● Manage your Shop
    ● Used by the Administration
    ● CRUD operations for every
    entity
    ● Action routes for everything
    else

    View Slide

  21. Admin API
    ● Stateless
    ● Auth via OAuth (JWT)
    ● Dynamic OpenAPI 3 schema
    including all entities
    ● Supports JSON:API
    ○ Deduplication built-in
    ○ Self-discovery
    ○ Implementations for various
    languages

    View Slide

  22. Sync API
    or Admin Batch API
    ● Single endpoint in Admin API
    ● Multiple actions in one request
    ○ upsert
    ○ delete
    ● Probably faster with large data
    sets (in the future)

    View Slide

  23. Sync API
    or Admin Batch API

    View Slide

  24. Sales Channel
    API
    ● Storefront functionality
    ○ Sell products via API
    ○ Perform checkout
    ○ Manage your account
    ● Authentication with pre-shared
    key
    ● Dynamic OpenAPI 3 schema
    for all available routes

    View Slide

  25. Context

    View Slide

  26. Context
    Crucial information of a request
    ● Immutable object
    ● Built from the request
    ● Runtime information

    View Slide

  27. Contexts
    Context

    View Slide

  28. Sales Channel Context

    View Slide

  29. ● 3 levels of inheritance
    priority
    ○ current language
    ○ root language
    ○ system language
    Context
    Language chain for partial
    translations

    View Slide

  30. ● 3 levels of inheritance
    priority
    ○ current language
    ○ root language
    ○ de-DE
    Context
    Language chain for partial
    translations

    View Slide

  31. ● 3 levels of inheritance
    priority
    ○ current language
    ○ en-GB
    ○ de-DE
    Context
    Language chain for partial
    translations

    View Slide

  32. ● 3 levels of inheritance
    priority
    ○ en-US
    ○ en-GB
    ○ de-DE
    Context
    Language chain for partial
    translations

    View Slide

  33. Translations

    View Slide

  34. View Slide

  35. View Slide

  36. Translations
    Translate all the things
    ● Content
    ● Administration UI
    ● Storefront UI

    View Slide

  37. Translations
    Translate all the things
    ● Content
    ● Administration UI
    ● Storefront UI

    View Slide

  38. Content
    Translations
    ● Built into the Data Abstraction
    Layer
    ● Translated fields can be
    managed in all languages
    ● Inheritance with partial
    translations

    View Slide

  39. Data Abstraction Layer

    View Slide

  40. Why?
    Reasons not to use Doctrine
    ORM
    ● Difficult to optimize
    ● Not suitable for core concepts
    ● Entities not extendable for
    plugins
    ● Not possible to enforce
    patterns

    View Slide

  41. Reading data

    View Slide

  42. Adding Criteria

    View Slide

  43. Loading Associations

    View Slide

  44. Aggregating Data

    View Slide

  45. Aggregating Data

    View Slide

  46. Writing data

    View Slide

  47. Writing data

    View Slide

  48. Define your own Entities

    View Slide

  49. Data Abstraction
    Layer
    ● tag your entity with
    shopware.entity.definition
    ● add a DB migration
    optional
    ● add a EntityClass
    ● add a CollectionClass
    if necessary
    ● add a translation definition
    Define your own Entities

    View Slide

  50. TranslationDefinition

    View Slide

  51. Content Translation - Example

    View Slide

  52. Content Translation - Example

    View Slide

  53. Content Translation - Example

    View Slide

  54. Content Translation - Example

    View Slide

  55. Sales Channel
    API
    Entities
    ● SalesChannelDefinitions
    extend EntityDefinitions
    ● Add custom criteria
    ● Add fields

    View Slide

  56. Sales Channel API Entities

    View Slide

  57. Indexer
    ● Denormalization for improved
    read performance
    ● Denormalized data needs
    synchronisation
    ○ Build the whole index
    ○ Update the index for updated
    entities only
    Synchronizing denormalized
    data

    View Slide

  58. Indexer

    View Slide

  59. Migrations

    View Slide

  60. Migrations
    ● Blue/Green compatible
    ● 2-Phase Migrations
    ○ update
    ○ updateDestructive
    ● usable for Plugins as well
    Updating the DB schema

    View Slide

  61. Migrations
    ● Must be compatible with old
    and new application
    ○ No breaking changes
    ● Application rollback without
    another DB schema migration
    1. Phase: update

    View Slide

  62. Migrations
    ● Contains the breaking changes
    ● Application rollback not
    possible
    ● Last possible rollback point ->
    last destructive Migration
    2. Phase: updateDestructive

    View Slide

  63. Data
    Abstraction
    Layer
    Common obstacles
    ● IDs are binary UUIDs
    ● Objects for reading
    ● Arrays for writing
    ● Translated properties must be
    nullable

    View Slide

  64. Data
    Abstraction
    Layer
    Tools
    ● Debug View Generator
    ● Schema Generator
    ● Validation command

    View Slide

  65. Cart

    View Slide

  66. Cart
    ● First component in Shopware 6
    ● State machine
    ● High Performance

    View Slide

  67. Cart
    Calculation process

    View Slide

  68. Cart
    Enrichment process

    View Slide

  69. Payment

    View Slide

  70. Payment
    ● Executed after order placed
    ● Synchronous
    ● Asynchronous

    View Slide

  71. Payment
    asynchronous

    View Slide

  72. Business Events

    View Slide

  73. Business Event
    ● Important business cases
    ● Describes itself
    ● Same event dispatcher

    View Slide

  74. Business Event
    Example: order placed

    View Slide

  75. Actions
    for Business Events
    Add actions for events:
    ● Send an email
    ● Call an API
    ● Send a Slack message

    View Slide

  76. Business Event
    Tag for mailing

    View Slide

  77. Actions
    for Business Events
    order.placed
    event dispatcher Plugin X

    View Slide

  78. Actions
    for Business Events
    order.placed
    action event dispatcher
    send mail call API Slack msg
    event dispatcher Plugin X

    View Slide

  79. Further topics
    ● Filesystem
    ● Custom Fields
    ● Tooling
    ● Versioning
    ● Message Queue
    ● Custom Rule Builder rules

    View Slide

  80. View Slide

  81. Questions
    THANK YOU!

    View Slide