Hello, I have a problem with hooks. I've created Order Comment Hook. Here is config:
<hooks>
<hook id="order.comment.hook" class="OrderComment\Hook\OrderCommentHook" scope="request">
<tag name="hook.event_listener" event="ordercomment.hook" type="front" method="addCommentField" />
<tag name="hook.event_listener" event="cart.javascript-initialization" type="front" method="addFrontJS" />
</hook>
</hooks>
Here is hook file:
<?php
namespace OrderComment\Hook;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
class OrderCommentHook extends BaseHook
{
public function addCommentField(HookRenderEvent $event)
{
$event->add($this->render("order-comment-form.html"));
}
public function addFrontJS(HookRenderEvent $event)
{
$event->add($this->addJS("assets/js/script.js"));
}
}
I've created new hook "ordercomment.hook" and placed it in cart.html. This hook works well.
But my second hook I want to be assing into "cart.javascript-initialization" hook.
On my OrderCommentHook.php you can see two method.
Method "addCommentField" add simle textare to cart (this work)
Method "addFrontJS" should ad javascript into cart, but I can't save record with addFrontJS. After I submit the from the "Method name" is automatically changed into "addCommentField" and I didn't receive any errors. What's wrong ?
Here you can download this module: OrderComment.zip