public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con->getWrappedConnection());
     $database->insertSql(null, [__DIR__ . '/Config/thelia.sql']);
     // Add order-invoice.before-discount hook if not already defined
     if (null === HookQuery::create()->findOneByCode('order-invoice.before-discount')) {
         try {
             $hookEvent = new HookCreateEvent();
             $hookEvent->setCode('order-invoice.before-discount')->setType(TemplateDefinition::FRONT_OFFICE)->setNative(false)->setActive(true)->setLocale('en_US')->setTitle("Before discount code form block");
             $this->getDispatcher()->dispatch(TheliaEvents::HOOK_CREATE, $hookEvent);
             if ($hookEvent->hasHook()) {
                 // Assign module to this hook
                 $moduleHookEvent = new ModuleHookCreateEvent();
                 $moduleHookEvent->setModuleId($this->getModuleId())->setHookId($hookEvent->getHook()->getId())->setClassname('creditaccount.order_invoice.hook')->setMethod('orderInvoiceForm');
                 // Activate module hook
                 $this->getDispatcher()->dispatch(TheliaEvents::MODULE_HOOK_CREATE, $moduleHookEvent);
                 if ($moduleHookEvent->hasModuleHook()) {
                     $event = new ModuleHookToggleActivationEvent($moduleHookEvent->getModuleHook());
                     $this->getDispatcher()->dispatch(TheliaEvents::MODULE_HOOK_TOGGLE_ACTIVATION, $event);
                 }
             }
         } catch (\Exception $ex) {
             throw new TheliaProcessException(Translator::getInstance()->trans("Failed to put module in 'order-invoice.before-discount' hook (%err)", ['%err' => $ex->getMessage()]), $ex);
         }
     }
 }
Example #2
0
 public function createModuleHook(ModuleHookCreateEvent $event)
 {
     $moduleHook = new ModuleHookModel();
     // todo: test if classname and method exists
     $moduleHook->setModuleId($event->getModuleId())->setHookId($event->getHookId())->setActive(false)->setClassname($event->getClassname())->setMethod($event->getMethod())->setModuleActive($this->isModuleActive($event->getModuleId()))->setHookActive($this->isHookActive($event->getHookId()))->setPosition($this->getLastPositionInHook($event->getHookId()))->setTemplates($event->getTemplates())->save();
     // Be sure to delete this module hook from the ignored module hook table
     IgnoredModuleHookQuery::create()->filterByHookId($event->getHookId())->filterByModuleId($event->getModuleId())->delete();
     $event->setModuleHook($moduleHook);
 }
Example #3
0
 public function testCreate()
 {
     $event = new ModuleHookCreateEvent();
     $event->setHookId($this->hook->getId())->setModuleId($this->module->getId())->setDispatcher($this->dispatcher);
     $this->action->createModuleHook($event);
     $createdModuleHook = $event->getModuleHook();
     $this->assertInstanceOf('\\Thelia\\Model\\ModuleHook', $createdModuleHook);
     $this->assertFalse($createdModuleHook->isNew());
     $this->assertTrue($event->hasModuleHook());
     $this->assertEquals($event->getHookId(), $createdModuleHook->getHookId());
     $this->assertEquals($event->getModuleId(), $createdModuleHook->getModuleId());
     return $createdModuleHook;
 }
Example #4
0
 public function createModuleHook(ModuleHookCreateEvent $event)
 {
     $moduleHook = new ModuleHookModel();
     $moduleHook->setModuleId($event->getModuleId())->setHookId($event->getHookId())->setActive(false)->setModuleActive($this->isModuleActive($event->getModuleId()))->setHookActive($this->isHookActive($event->getHookId()))->setPosition($this->getLastPositionInHook($event->getHookId()))->save();
     $event->setModuleHook($moduleHook);
 }