APIP 2024 - All the Challenges of Sylius Migration to API Platform 3.pdf
ukaszChruciel1
110 views
66 slides
Sep 20, 2024
Slide 1 of 66
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
About This Presentation
Migrating Sylius to API Platform 3 is no small feat. In this presentation, we will discuss the many challenges we faced during this complex transition and the innovative solutions we used to overcome them. This journey began with a clear goal: to leverage the robust capabilities of API Platform 3 to...
Migrating Sylius to API Platform 3 is no small feat. In this presentation, we will discuss the many challenges we faced during this complex transition and the innovative solutions we used to overcome them. This journey began with a clear goal: to leverage the robust capabilities of API Platform 3 to improve the performance and scalability of Sylius. In this talk, I will share the critical steps we took, the obstacles we encountered, and the strategies we used to overcome these challenges.
We will address the following questions:
What were the key technical hurdles in migrating Sylius to API Platform 3?
How did we ensure compatibility and maintain data integrity throughout the migration?
What were our key takeaways and best practices from this experience?
Join us to gain insights from our experience, learn about common pitfalls in such migrations, and discover how to navigate them effectively. Whether you are planning a similar migration or looking to optimize your current setup, this session will provide valuable lessons and practical tips to help you succeed.
Size: 7.96 MB
Language: en
Added: Sep 20, 2024
Slides: 66 pages
Slide Content
SEPTEMBER 19 -20, 2024 - LILLE, FRANCE & ONLINE
All the Challenges of Sylius
migration
to API Platform 3
Tests
01
02
03
04
05
Commands
Open API
Conclusion
Subresources
About me
Łukasz Chruściel
✔Co-owner at Commerce Weavers
✔Core Team Lead at Sylius
✔I’m involved in 3 Sylius & API Platform
eCommerce projects
You don’t have to remind me every year…
API Platform Conference 2022
What we’ve learned
designing the new Sylius API
About team
✔Grzegorz - as an effort lead
✔Developers: Jan, Kuba, Kamil, Michał,
Rafał, Karol
Internal Sylius Team
@Sylius
sylius.com
Scale of the migration
v2.7.18 v3.4.0
Where we were? Where we go?
73 shop endpoints
Sylius API statistics
188 admin endpoints
40808 lines of code
across 562 files
Main problems
✔New metadata class
✔New configuration reference
✔New architecture of Providers/Processors
✔New subresource architecture
✔Sylius is not a typical use-case
01
02
03
04
05
Tests
Commands
Serialization
Open API
Conclusion
Command 101
✔Decouples infrastructure from application
✔Holds customer intention
✔Commands never contain entities
✔Handlers are stateless
✔Maintains the same behaviour even
if framework has changed
API Platform Con 2021
Sylius & API Platform: the
story of integration
Architecture 101
Request is like
Says more than a 1000 words
Mapping of request body
to command is not
enough
Channel Order
Language
User
Request is not only the body
Request data Translates to
✔Hostname
✔Language Header
✔Authorization Header
✔URI attributes
✔Channel code
✔Local code
✔Shop User ID
✔Order token
Result?
✔Better design
✔Command immutability
✔Better decoupling from framework
01
02
03
04
05
Tests
Commands
Subresources
Open API
Conclusion
Tests 101
✔BDD for behaviour
✔Behat for BDD
✔Contract testing for API design
✔PHPUnit for contract testing
API Platform Con 2021
Sylius & API Platform: the
story of integration
@shopping_cart
Feature: Adding a simple product to the cart
In order to select products for purchase
As a Visitor
I want to be able to add simple products to cart
Background:
Given the store operates on a single channel in "United States"
And the store has a product "T-Shirt banana" priced at "$12.54"
And the store ships everywhere for free
@api @ui @javascript
Scenario: Adding a simple product to the cart
When I add this product to the cart
Then I should be on my cart summary page
And I should be notified that the product has been successfully added
And there should be one item in my cart
And this item should have name "T-Shirt banana"
Behaviour Driven
Development
public function it_adds_item_to_order_as_guest (): void
{
$this?lsetUpDefaultPostHeaders ();
Nowadays
image of modern, nice country with not obvious
issues
Some issues still exists
Double nested structures
Double nested structures
What we want is:
{"@id": "\/api\/v2\/shop\/orders\/TOKEN\/items\/ID\/item-units\/ID"},
What we have right now is:
{"@id": "\/api\/v2\/shop\/order-item-units\/ID"},
Some issues still exists
01
02
03
04
05
Tests
Commands
Open API
Conclusion
Subresources
API Platform
documentation
??????
But sometimes it is not
enough
Cart pick up
final readonly class OpenApiFactory implements OpenApiFactoryInterface
{
public function ??construct(
private OpenApiFactoryInterface $decorated,
/** @var iterable<DocumentationModifierInterface> ??
private iterable $openApiModifiers,
) {
Assert?{allIsInstanceOf($openApiModifiers, DocumentationModifierInterface ?{class);
}
public function ??invoke(array $context = []): OpenApi
{
$openApi = ($this?ldecorated)($context);
foreach ($this?lopenApiModifiers as $openApiModifier) {
$openApi = $openApiModifier?lmodify($openApi);
}
return $openApi;
}
}
Documentation modifiers
$acceptLanguageHeaderParameter = new Parameter(
name: 'Accept-Language',
in: 'header',
description: 'Locales in this enum are all locales defined in the shop and only enabled ones
will work in the given channel in the shop.' ,
required: false,
schema: [
'type' ?? 'string',
'enum' ?? array_map(
fn (LocaleInterface $locale): string ?? $locale?lgetCode(),
$this?llocaleRepository?lfindAll(),
),
],
);
Documentation modifiers
Key take-outs
✔Use commands to decouple from framework
-With a little bit of effort you can map more than just request body to command
✔Tests are a must have for successful migration
✔New operation system rocks
-but we may improve some stuff for more deeply nested classes
Thank you!
FOLLOW ME!
@lukaszchrusciel
commerceweavers.com
Any questions?
01 - Interesting
introduction
Some cool stuff
{
"@context": "/contexts/ConstraintViolationList" ,
"@type": "ConstraintViolationList" ,
"hydra:title": "An error occurred",
"hydra:description": "isbn: This value is neither a valid ISBN-10 nor a valid
ISBN-13.\ntitle: This value should not be blank." ,
"violations": [
{
"propertyPath": "isbn",
"message": "This value is neither a valid ISBN-10 nor a valid ISBN-13."
},
{
"propertyPath": "title",
"message": "This value should not be blank."
}
]
}
Some code
Some title
Add your text here
Another example
✔You can add stuff here
✔Or here…
✔Or even here!
Another example
✔You can add stuff here
✔Or here…
✔Or even here!
Add something here
Another example
✔You can add stuff here
✔Or here…
✔Or even here!
Another slide
Example
✔You can add stuff here
✔Or here…
✔Or even here!
Some content you want to
highlight
Another example
✔You can add stuff here
✔Or here…
✔Or even here!
Another content
to highlight
Add caption (or not)
Some title
Add your text here
Say something (or delete this)
Some title
Add your text here
Some title
Some interesting
point
Another interesting
point
A final interesting
point
Some title
Some interesting
point
A final interesting
point
Another interesting point
You can say interesting
things here
✔Large topics discussed on that wonderful
slide
✔You can write something else
Hello!
Thank you!
Hello!
Any questions?
@JaneDoeTwitter
jane-doe.com
Follow me on social media
Need graphic stuff for your slides?
Need graphic stuff for your slides?
Something cool