intro aux modules thelia 2
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
E-Commerce solution based on Symfony 2 componentsBy / Manuel Raynaud @manuraynaud
Clemont'ech APIHour #9 28/05/2014
InternationalisationInteropérabilitéMise en place de bonnes pratiquesNouvelles fonctionnalités
BACKOFFICEphp 5.4sf2 componentsPropel
SF2 COMPONENTSHttpKernelHttpFoundationEventDispatcherDependencyInjectionForm
FRONTOFFICEHTML 5BootStrap 3 + less
ÉTENDRETHELIA
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 ...
LISTENERS
DISPATCH D'UN EVENT
RÉCUPÉRER LE DISPATCHER //depuis le container$eventDispatcher = $container->get('event_dispatcher');
//depuis un event$eventDispatcher = $event->getDispatcher();
CRÉER UN EVENT1 event = 1 classe de données
<?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; }}
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);
LISTE DES EVENTS THELIADocumentation -> dev -> eventThelia\Core\Event\TheliaEvents
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(); }
}
DÉCLARER LE LISTENER <service id="MyModule.cart.listener" class="MyModule\Listener\Cart"> <tag name="kernel.event_subscriber"/></service>
AVANTAGESJouer sur la prioritéPossibilité de surcharger totalement Thelia
INCONVÉNIENTRien ne vous assure que votre listener sera exécuté
ROUTING
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>
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>
NEXT ?
HooksAPIMarketplace
ONE MORETHING !
MERCI !http://doc.thelia.nethttps://github.com/thelia@theliaecommerce