THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline

#1 [RESOLU] Problem with hooks

(26-04-2015 11:03:12)


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

Offline


Maybe you script.js file should be in templates/frontOffice/default(or base?)/asset/js folder instead of templates/frontOffice/asset/js ?

Offline


so simple and so stupid error. I don't know how could I not notice this. Thanks