コード例 #1
0
 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);
         }
     }
 }
コード例 #2
0
ファイル: HookTest.php プロジェクト: vigourouxjulien/thelia
 /**
  * @param HookModel $hook
  * @depends testCreate
  * @expectedException \Propel\Runtime\Exception\PropelException
  */
 public function testCreateDuplicate(HookModel $hook)
 {
     $event = new HookCreateEvent();
     $event->setCode($hook->getCode())->setType(TemplateDefinition::FRONT_OFFICE)->setLocale($this->locale)->setActive(true)->setNative(true)->setTitle("Hook Test");
     $this->action->create($event, null, $this->getMockEventDispatcher());
     $createdHook = $event->getHook();
     $this->assertNull($createdHook);
     $this->assertFalse($event->hasHook());
 }