intro aux modules Thelia 2

28
E-Commerce solution based on Symfony 2 components By / Manuel Raynaud @manuraynaud Clemont'ech APIHour #9 28/05/2014

description

La première release de Thelia 2 est sortie mi-avril. A travers cette présentation nous verrons pourquoi nous avons développé une nouvelle version, comprendre son fonctionnement et comment étendre son fonctionnement grâce à l'utilisation de composants Symfony.

Transcript of intro aux modules Thelia 2

Page 1: intro aux modules Thelia 2

E-Commerce solution based on Symfony 2 componentsBy / Manuel Raynaud @manuraynaud

Clemont'ech APIHour #9 28/05/2014

Page 2: intro aux modules Thelia 2
Page 3: intro aux modules Thelia 2

InternationalisationInteropérabilitéMise en place de bonnes pratiquesNouvelles fonctionnalités

Page 4: intro aux modules Thelia 2

BACKOFFICEphp 5.4sf2 componentsPropel

Page 5: intro aux modules Thelia 2

SF2 COMPONENTSHttpKernelHttpFoundationEventDispatcherDependencyInjectionForm

Page 6: intro aux modules Thelia 2

FRONTOFFICEHTML 5BootStrap 3 + less

Page 7: intro aux modules Thelia 2

ÉTENDRETHELIA

Page 8: intro aux modules Thelia 2

STRUCTURE D'UN MODULE MyModule MyModule.php Config config.xml module.xml routing.xml schema.xml Controller MyModuleAdminController.php I18n fr_FR.php en_US.php Model Base Map MyModule.php MyModuleQuery.php Listeners CartListener.php OrderListener.php Loop MyModuleLoop.php templates ...

Page 9: intro aux modules Thelia 2

LISTENERS

Page 10: intro aux modules Thelia 2
Page 11: intro aux modules Thelia 2

DISPATCH D'UN EVENT

Page 12: intro aux modules Thelia 2

RÉCUPÉRER LE DISPATCHER //depuis le container$eventDispatcher = $container->get('event_dispatcher');

//depuis un event$eventDispatcher = $event->getDispatcher();

Page 13: intro aux modules Thelia 2

CRÉER UN EVENT1 event = 1 classe de données

Page 14: intro aux modules Thelia 2

<?phpnamespace Thelia\Core\Event;use Symfony\Component\EventDispatcher\Event;class Cart extends Event{ protected $productId; protected $quantity;

public function __construct($productId, $quantity) { $this->productId = $productId; $this->quantity = $quantity; }

public function getProductId() { return $this->productId; }

public function getQuantity() { return $this->quantity; }}

Page 15: intro aux modules Thelia 2

use Thelia\Core\Event\Cart;use Thelia\Core\Event\TheliaEvents;

//

$eventDispatcher = $container->get('event_dispatcher');$cartEvent = new Cart(1, 3);$eventDispatcher->dispatch(TheliaEvent::CART_ADD, $cartEvent);

Page 16: intro aux modules Thelia 2

LISTE DES EVENTS THELIADocumentation -> dev -> eventThelia\Core\Event\TheliaEvents

Page 17: intro aux modules Thelia 2

CRÉER UN LISTENER <?phpnamespace MyModule\Listener;use Thelia\Core\Event\TheliaEvents;use Thelia\Core\Event\CartEvent;Class CartListener implements EventSubscriberInterface{

public static function getSubscribedEvents() { return [ TheliaEvents::CART_ADD => ['addItem', 100] ]; }

public function addItem(CartEvent $event) { $item = $event->getCart()->getLast();

$item->addQuantity(rand(1,5)); $item->save(); }

}

Page 18: intro aux modules Thelia 2

DÉCLARER LE LISTENER <service id="MyModule.cart.listener" class="MyModule\Listener\Cart"> <tag name="kernel.event_subscriber"/></service>

Page 19: intro aux modules Thelia 2

AVANTAGESJouer sur la prioritéPossibilité de surcharger totalement Thelia

Page 20: intro aux modules Thelia 2

INCONVÉNIENTRien ne vous assure que votre listener sera exécuté

Page 21: intro aux modules Thelia 2

ROUTING

Page 22: intro aux modules Thelia 2

Il suffit de créer un fichier routing.xml dans le répertoire Config <!--?xml version="1.0" encoding="UTF-8" ?-->

<routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <route id="mumodule.id" path="/foo"> <default key="_controller"> MyModule\Controller\MyModuleAdminController::fooAction </default> </route></routes>

Page 23: intro aux modules Thelia 2

Config personnalisée

<service id="router.front" class="%router.class%"> <argument type="service" id="router.module.xmlLoader"> <argument>MyModule/Config/custom_routing.xml</argument> <argument type="collection"> <argument key="cache_dir">%kernel.cache_dir%</argument> <argument key="debug">%kernel.debug%</argument> </argument> <argument type="service" id="request.context"> <tag name="router.register" priority="256"></tag></argument></argument></service>

Page 24: intro aux modules Thelia 2

NEXT ?

Page 25: intro aux modules Thelia 2

HooksAPIMarketplace

Page 26: intro aux modules Thelia 2

ONE MORETHING !

Page 27: intro aux modules Thelia 2
Page 28: intro aux modules Thelia 2

MERCI !http://doc.thelia.nethttps://github.com/thelia@theliaecommerce