示例#1
0
 /**
  * Check if a module is valid
  *
  * @param IsValidPaymentEvent $event
  */
 public function isValid(IsValidPaymentEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $module = $event->getModule();
     // dispatch event to target specific module
     $dispatcher->dispatch(TheliaEvents::getModuleEvent(TheliaEvents::MODULE_PAYMENT_IS_VALID, $module->getCode()), $event);
     if ($event->isPropagationStopped()) {
         return;
     }
     // call legacy module method
     $event->setValidModule($module->isValidPayment());
 }
示例#2
0
 /**
  * Get postage from module using the classical module functions
  *
  * @param DeliveryPostageEvent $event
  */
 public function getPostage(DeliveryPostageEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $module = $event->getModule();
     // dispatch event to target specific module
     $dispatcher->dispatch(TheliaEvents::getModuleEvent(TheliaEvents::MODULE_DELIVERY_GET_POSTAGE, $module->getCode()), $event);
     if ($event->isPropagationStopped()) {
         return;
     }
     // call legacy module method
     $event->setValidModule($module->isValidDelivery($event->getCountry()));
     if ($event->isValidModule()) {
         $event->setPostage($module->getPostage($event->getCountry()));
     }
 }
示例#3
0
 /**
  * Get the event name for the loop depending of the event name and the loop name.
  *
  * This function also checks if there are services that listen to this event.
  * If not the function returns null.
  *
  * @param string $eventName the event name (`TheliaEvents::LOOP_EXTENDS_ARG_DEFINITIONS`,
  *                          `TheliaEvents::LOOP_EXTENDS_INITIALIZE_ARGS`, ...)
  * @return null|string The event name for the loop if listeners exist, otherwise null is returned
  */
 protected function getDispatchEventName($eventName)
 {
     $customEventName = TheliaEvents::getLoopExtendsEvent($eventName, $this->loopName);
     if (!isset(self::$dispatchCache[$customEventName])) {
         self::$dispatchCache[$customEventName] = $this->dispatcher->hasListeners($customEventName);
     }
     return self::$dispatchCache[$customEventName] ? $customEventName : null;
 }
 /**
  * Returns an array of event names this subscriber wants to listen to.
  *
  * @return array The event names to listen to
  *
  * @api
  */
 public static function getSubscribedEvents()
 {
     return [TheliaEvents::getLoopExtendsEvent(TheliaEvents::LOOP_EXTENDS_BUILD_MODEL_CRITERIA, 'customer') => ['extendCustomerLoop', 128], TheliaEvents::getLoopExtendsEvent(TheliaEvents::LOOP_EXTENDS_BUILD_MODEL_CRITERIA, 'order') => ['extendOrderLoop', 128], TheliaEvents::getLoopExtendsEvent(TheliaEvents::LOOP_EXTENDS_INITIALIZE_ARGS, 'order') => ['changeLimit', 128], TheliaEvents::getLoopExtendsEvent(TheliaEvents::LOOP_EXTENDS_BUILD_MODEL_CRITERIA, 'product') => ['extendProductBuildModelCriteria', 120]];
 }
示例#5
0
 /**
  * Check if a payment module manage stock on creation
  *
  * @param EventDispatcher $dispatcher
  * @param PaymentModuleInterface $module
  * @return bool if the module manage stock on creation, false otherwise
  */
 protected function isModuleManageStockOnCreation(EventDispatcherInterface $dispatcher, PaymentModuleInterface $module)
 {
     $event = new ManageStockOnCreationEvent($module);
     $dispatcher->dispatch(TheliaEvents::getModuleEvent(TheliaEvents::MODULE_PAYMENT_MANAGE_STOCK, $module->getCode()));
     return null !== $event->getManageStock() ? $event->getManageStock() : $module->manageStockOnCreation();
 }