Immersion in the Sylius
Paweł Jędrzejewski
Who am I?
Paweł Jędrzejewski
Huge beliver in Open Source
Symfony & BDD evangelist
Creator of Sylius
Working for Opensoft o...
ŁÓDŹ, POLAND
?
THE PROBLEM
PHP has changed
This change created the market for a new e-commerce solution
among developers
With the flexibi...
WHAT IS SYLIUS
A short history
Open sourced in 2011 as a set of bundles
Main application in development for ~9 months
Alre...
FLEXIBILITY QUALITY PEOPLE
FLEXIBILITY QUALITY PEOPLE
QUALITY
Behat and phpspec, perfect combination
Most of new features start with an RFC issue
Discussion about the idea and ...
FLEXIBILITY QUALITY PEOPLE
BUNDLES vs. MAIN APPLICATION
Set of 19 decoupled and
independent bundles

Standard webshop
experience

Can be used to crea...
Sylius Bundles
What they can do for you?

EVERY SINGLE SYLIUS FEATURE AVAILABLE FOR YOUR PROJECt
Simpler CRUD for symfony
SyliusResourceBundle
Removing tons of duplicated code in controllers for basic CRUD
actions.
Remo...
ADD YOUR RESOURCE
sylius_resource:
resources:
acme.user:
driver: doctrine/orm
templates: AcmeShopBundle:User
classes:
mode...
acme.controller.user
showAction
indexAction
createAction
updateAction
deleteAction
acme_user_show:
pattern: /users/{id}
methods: [GET]
defaults:
_controller: acme.controller.user:showAction
acme_profile_sh...
acme_profile_show:
pattern: /profile/{username}
methods: [GET]
defaults:
_controller: acme.controller.user:showAction
_syl...
acme_user_recently_registered:
pattern: /users/recently-registered
methods: [GET]
defaults:
_controller: acme.controller.u...
acme_user_update_addresses:
pattern: /users/{id}/update-addresses
methods: [GET]
defaults:
_controller: acme.controller.us...
Docs.sylius.org
CONFIGURATION
sylius_taxation:
driver: doctrine/orm
classes:
tax_rate:
model: AcmeShopBundleEntityTaxRate
controller: Acme...
USING CUSTOM MODELS and FORMS
Every model class can be overridden
All repositories, managers and forms are
updated automat...
OVERRIDING CONTROLLERS
All models use default or slightly customized
CRUD controller
Add your own methods
YOUR OWN REPOSITORY
Sylius repositories extend native Doctrine
implementations
Override the repositories through configura...
CHANGE THE RULES, VALIDATION
All Sylius models ship with their own validation
mapping under group „sylius”
You can easily ...
DOCTRINE RTEL, DYNAMIC RELATIONS
We're using interfaces instead of
implementation to define the relations
When you overrid...
WE LOVE EVENTS, YOU SHOULD TOO
The default controller triggers multiple useful
events during CRUD actions

sylius.product....
PRODUCTS
SyliusProductBundle
ORDERS AND CART
SyliusOrderBundle + SyliusCartBundle
Generic Order model with support of Adjustments
Cart bundle provides ...
COUNTRIES, ZONES AND ADDRESSES
SyliusAddressingBundle
Provides a very basic Address model
Countries and their Provinces ma...
$billingAddress = $order->getBillingAddress();
$zone = $this->zoneMatcher->match($billingAddress);
$address = $location->g...
TAKE CARE OF YOUR INVENTORY
SyliusInventoryBundle
Built around 1 interface you need to implement
Tracks every single inven...
HATE IT OR LOVE IT, TAXATION
SyliusTaxationBundle
TaxableInterface = heart of the bundle
Multiple tax categories and rates...
MERCHANDISE NEEDS TO BE SHIPPED
SyliusShippingBundle
Integrate through one interface
Manage Shipments and Shipping Methods...
class PerItemRateCalculator extends Calculator
{
public function calculate(ShippingSubjectInterface $subject, array $confi...
CATEGORIZE ALL THIS STUFF, NOW
SyliusTaxonomiesBundle
Classify any Model using different Taxonomies
Flexible forms
Based o...
JUST FEW STEPS MORE
SyliusFlowBundle
Useful for anything which takes more than 1
action to complete
Checkouts, installatio...
PROCESS SCENARIO
<?php
class CheckoutProcessScenario implements ProcessScenarioInterface
{
public function build(ProcessBu...
PAYUM INTEGRATION
SyliusPayumBundle NEW!
Integrates Payum library into Sylius checkout
Replaceable by other bundles in fut...
Make your app configurable, EASILY
SyliusSettingsBundle
You can define settings schema and the form
User edits the setting...
Settings schema
class GeneralSettingsSchema implements SchemaInterface
{
public function buildSettings(SettingsBuilderInte...
EDITING VIA FORM
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('meta_keywords', 'text', array(...
PROMOTIONS ARE NICE
SyliusPromotionsBundle
Can be integrated with any Model
Very flexible Actions and Rules system
Support...
PROMOTION STRUCTURE
SUPER AWESOME PROMOTION
ACTION

RULE

ACTION

RULE

ACTION
CUSTOM RULES
interface RuleCheckerInterface
{
/**
* @param PromotionSubjectInterface $subject
* @param array

$configurati...
YOUR OWN ACTIONS
class AddPackageAction implements PromotionActionInterface
{
public function execute(PromotionSubjectInte...
Sylius Application
How to bootstrap Symfony2 shop in minutes? (soon)

Bringing smile back to developer's faces
INSTALLATION

$ composer create-project sylius/sylius -s dev path/to/install
$ cd path/to/install
$ app/console sylius:ins...
ONE CORE TO RULE THEM ALL
SyliusCoreBundle
Integrates all the bundles together
Standard webshop application
Contains all t...
THE WEB INTERFACE
SyliusWebBundle
Provides the default web interface for Sylius
Contains all the templates and menu builde...
THE BACKEND
public function forwardAction(ProcessContextInterface $context)
{
$request = $this->getRequest();
$order = $this->getCurre...
TO DO
Documentation, documentation, documentation
New default store look
Rework translations and integrate with CrowdIn
Po...
COMING SOON...
Pull Requests
Customer groups
Subscriptions support
Product reviews
Symfony CMF integration (editable block...
Www.sylius.org
Github.com/sylius
@pjedrzejewski

THANK YOU
Questions?
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Immersion in the Sylius
Upcoming SlideShare
Loading in …5
×

Immersion in the Sylius

3,668 views

Published on

Sylius is an open source e-commerce solution for PHP, based on the great Symfony2 framework. My first talk ever, at Symfony CAMP UA 2013.

Published in: Technology
1 Comment
5 Likes
Statistics
Notes
  • Nice presentation, thanks.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
3,668
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
32
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide

Immersion in the Sylius

  1. 1. Immersion in the Sylius Paweł Jędrzejewski
  2. 2. Who am I? Paweł Jędrzejewski Huge beliver in Open Source Symfony & BDD evangelist Creator of Sylius Working for Opensoft on
  3. 3. ŁÓDŹ, POLAND
  4. 4. ?
  5. 5. THE PROBLEM PHP has changed This change created the market for a new e-commerce solution among developers With the flexibility of modern frameworks and the new way of collaboration we can build something interesting for the business Sylius reflects this evolution
  6. 6. WHAT IS SYLIUS A short history Open sourced in 2011 as a set of bundles Main application in development for ~9 months Already used in production by developers and companies
  7. 7. FLEXIBILITY QUALITY PEOPLE
  8. 8. FLEXIBILITY QUALITY PEOPLE
  9. 9. QUALITY Behat and phpspec, perfect combination Most of new features start with an RFC issue Discussion about the idea and eventual implementation Behat features Implementation
  10. 10. FLEXIBILITY QUALITY PEOPLE
  11. 11. BUNDLES vs. MAIN APPLICATION Set of 19 decoupled and independent bundles Standard webshop experience Can be used to create a custom platform Highly customizable Integrate e-commerce into existing application Easy to understand for every Symfony2 developer
  12. 12. Sylius Bundles What they can do for you? EVERY SINGLE SYLIUS FEATURE AVAILABLE FOR YOUR PROJECt
  13. 13. Simpler CRUD for symfony SyliusResourceBundle Removing tons of duplicated code in controllers for basic CRUD actions. Removing the manager and manipulator classes, relying on Doctrine instead. Removing the "frontend" and "backend" controllers. Supporting different persistence layers. Make the controllers format agnostic. (API)
  14. 14. ADD YOUR RESOURCE sylius_resource: resources: acme.user: driver: doctrine/orm templates: AcmeShopBundle:User classes: model: AcmeShopBundleEntityUser repository: AcmeShopBundleEntityUserRepository controller: AcmeShopBundleControllerUserController
  15. 15. acme.controller.user showAction indexAction createAction updateAction deleteAction
  16. 16. acme_user_show: pattern: /users/{id} methods: [GET] defaults: _controller: acme.controller.user:showAction acme_profile_show: pattern: /profile/{username} methods: [GET] defaults: _controller: acme.controller.user:showAction _sylius: template: AcmeShopBundle:Profile:show.html.twig criteria: { username: $username, enabled: true }
  17. 17. acme_profile_show: pattern: /profile/{username} methods: [GET] defaults: _controller: acme.controller.user:showAction _sylius: template: AcmeShopBundle:Profile:show.html.twig method: findOneForProfilePage arguments: [$username] acme_user_disabled_index: pattern: /users/disabled methods: [GET] defaults: _controller: acme.controller.user:indexAction _sylius: template: AcmeShopBundle:User:disabled.html.twig criteria: { enabled: false }
  18. 18. acme_user_recently_registered: pattern: /users/recently-registered methods: [GET] defaults: _controller: acme.controller.user:indexAction _sylius: template: AcmeShopBundle:User:recentlyRegistered.html.twig criteria: { enabled: true } sorting: { createdAt: desc } paginate: false limit: 5
  19. 19. acme_user_update_addresses: pattern: /users/{id}/update-addresses methods: [GET] defaults: _controller: acme.controller.user:updateAction _sylius: template: AcmeShopBundle:User:updateAddresses.html.twig form: acme_user_addresses redirect: route: acme_user_index
  20. 20. Docs.sylius.org
  21. 21. CONFIGURATION sylius_taxation: driver: doctrine/orm classes: tax_rate: model: AcmeShopBundleEntityTaxRate controller: AcmeShopBundleControllerTaxRateController repository: AcmeShopBundleEntityTaxRateRepository form: AcmeShopBundleFormTypeTaxRateType validation_groups: tax_rate: [sylius, acme]
  22. 22. USING CUSTOM MODELS and FORMS Every model class can be overridden All repositories, managers and forms are updated automatically Form class can be customized
  23. 23. OVERRIDING CONTROLLERS All models use default or slightly customized CRUD controller Add your own methods
  24. 24. YOUR OWN REPOSITORY Sylius repositories extend native Doctrine implementations Override the repositories through configuration Repositories are services
  25. 25. CHANGE THE RULES, VALIDATION All Sylius models ship with their own validation mapping under group „sylius” You can easily override it with your own rules Consistent translation messages
  26. 26. DOCTRINE RTEL, DYNAMIC RELATIONS We're using interfaces instead of implementation to define the relations When you override the model class, all relations get updated automatically Defaults are turned into entities if you don't provide your own class
  27. 27. WE LOVE EVENTS, YOU SHOULD TOO The default controller triggers multiple useful events during CRUD actions sylius.product.pre_create sylius.product.post_create
  28. 28. PRODUCTS SyliusProductBundle
  29. 29. ORDERS AND CART SyliusOrderBundle + SyliusCartBundle Generic Order model with support of Adjustments Cart bundle provides actions and services for customer to interact with the Order entity The order/cart items can be easily customized to handle different options
  30. 30. COUNTRIES, ZONES AND ADDRESSES SyliusAddressingBundle Provides a very basic Address model Countries and their Provinces management Zones system with a ZoneMatcher service Useful for taxation and shipping zones
  31. 31. $billingAddress = $order->getBillingAddress(); $zone = $this->zoneMatcher->match($billingAddress); $address = $location->getAddress(); $zones = $this->zoneMatcher->matchAll($address);
  32. 32. TAKE CARE OF YOUR INVENTORY SyliusInventoryBundle Built around 1 interface you need to implement Tracks every single inventory unit Based on events Items available on demand Backorders
  33. 33. HATE IT OR LOVE IT, TAXATION SyliusTaxationBundle TaxableInterface = heart of the bundle Multiple tax categories and rates support Customizable tax calculators Tax included in price
  34. 34. MERCHANDISE NEEDS TO BE SHIPPED SyliusShippingBundle Integrate through one interface Manage Shipments and Shipping Methods Custom shipping rules Flexible calculators system
  35. 35. class PerItemRateCalculator extends Calculator { public function calculate(ShippingSubjectInterface $subject, array $configuration) { return $configuration['amount'] * $subject->getShippingItemCount(); } public function getConfigurationFormType() { return 'sylius_shipping_calculator_per_item_rate_configuration'; } public function setConfiguration(OptionsResolverInterface $resolver) { $resolver ->setRequired(array( 'amount')) ->setAllowedTypes(array('amount' => array('numeric'))) ; } }
  36. 36. CATEGORIZE ALL THIS STUFF, NOW SyliusTaxonomiesBundle Classify any Model using different Taxonomies Flexible forms Based on DoctrineExtensions
  37. 37. JUST FEW STEPS MORE SyliusFlowBundle Useful for anything which takes more than 1 action to complete Checkouts, installation wizards, complex actions Used by OroCRM and Akeneo PIM for installers
  38. 38. PROCESS SCENARIO <?php class CheckoutProcessScenario implements ProcessScenarioInterface { public function build(ProcessBuilderInterface $builder) { $builder ->add('security', 'sylius_checkout_security') ->add('addressing', 'sylius_checkout_addressing') ->add('shipping', 'sylius_checkout_shipping') ->add('payment', 'sylius_checkout_payment') ->add('finalize', 'sylius_checkout_finalize') ->add('purchase', 'sylius_checkout_purchase') ; } }
  39. 39. PAYUM INTEGRATION SyliusPayumBundle NEW! Integrates Payum library into Sylius checkout Replaceable by other bundles in future PayPal Express Checkout and Stripe support Omnipay usage through a bridge
  40. 40. Make your app configurable, EASILY SyliusSettingsBundle You can define settings schema and the form User edits the settings through UI You get the access via services and Twig
  41. 41. Settings schema class GeneralSettingsSchema implements SchemaInterface { public function buildSettings(SettingsBuilderInterface $builder) { $builder ->setDefaults(array( 'meta_keywords' => 'symfony, sylius, ecommerce, webshop, shopping cart', 'meta_description' => 'Sylius is modern ecommerce solution for PHP.', )) ->setAllowedTypes(array( 'meta_keywords' => array('string'), 'meta_description' => array('string'), )) ; }
  42. 42. EDITING VIA FORM public function buildForm(FormBuilderInterface $builder) { $builder ->add('meta_keywords', 'text', array( 'constraints' => array(new NotBlank()) )) ->add('meta_description', 'textarea', array( 'constraints' => array(new NotBlank()) )) ; }
  43. 43. PROMOTIONS ARE NICE SyliusPromotionsBundle Can be integrated with any Model Very flexible Actions and Rules system Support for promotion coupons
  44. 44. PROMOTION STRUCTURE SUPER AWESOME PROMOTION ACTION RULE ACTION RULE ACTION
  45. 45. CUSTOM RULES interface RuleCheckerInterface { /** * @param PromotionSubjectInterface $subject * @param array $configuration * * @return Boolean */ public function isEligible(PromotionSubjectInterface $subject, array $configuration); /** * @return string */ public function getConfigurationFormType(); }
  46. 46. YOUR OWN ACTIONS class AddPackageAction implements PromotionActionInterface { public function execute(PromotionSubjectInterface $subject, array $configuration) { $package = $this->findPackage($configuration); $item = $this->cartItemRepository->createNew(); $item->setQuantity(1); $item->setUnitPrice(isset($configuration['price']) ? $configuration['price'] : $package->getGrossPrice()); $item->setPackage($package); $subject->addItem($item); } public function getConfigurationFormType() { return 'xyz_promotion_action_add_package_configuration'; } }
  47. 47. Sylius Application How to bootstrap Symfony2 shop in minutes? (soon) Bringing smile back to developer's faces
  48. 48. INSTALLATION $ composer create-project sylius/sylius -s dev path/to/install $ cd path/to/install $ app/console sylius:install $ composer create-project sylius/sylius-standard -s dev path/to/install $ cd path/to/install $ app/console sylius:install
  49. 49. ONE CORE TO RULE THEM ALL SyliusCoreBundle Integrates all the bundles together Standard webshop application Contains all the models and services
  50. 50. THE WEB INTERFACE SyliusWebBundle Provides the default web interface for Sylius Contains all the templates and menu builders Splitted into Frontend & Backend parts
  51. 51. THE BACKEND
  52. 52. public function forwardAction(ProcessContextInterface $context) { $request = $this->getRequest(); $order = $this->getCurrentCart(); $this->dispatchCheckoutEvent(SyliusCheckoutEvents::ADDRESSING_INITIALIZE, $order); $form = $this->createCheckoutAddressingForm($order); if ($request->isMethod('POST') && $form->bind($request)->isValid()) { $this->dispatchCheckoutEvent(SyliusCheckoutEvents::ADDRESSING_PRE_COMPLETE, $order); $this->getManager()->persist($order); $this->getManager()->flush(); $this->dispatchCheckoutEvent(SyliusCheckoutEvents::ADDRESSING_COMPLETE, $order); return $this->complete(); } return $this->renderStep($context, $order, $form); }
  53. 53. TO DO Documentation, documentation, documentation New default store look Rework translations and integrate with CrowdIn Polish the checkout process Integrate BazingaHateoasBundle for API Integrate Symfony CMF and Create.js
  54. 54. COMING SOON... Pull Requests Customer groups Subscriptions support Product reviews Symfony CMF integration (editable blocks and pages) Facebook/Amazon and so on...
  55. 55. Www.sylius.org Github.com/sylius @pjedrzejewski THANK YOU Questions?

×