开发者

Unobtrusively add block in cart

开发者 https://www.devze.com 2023-03-04 21:52 出处:网络
For a module I\'m working on, I want to add a block in the shopping cart screen, I want to do it unobtrusively and I\'d like to place it beneath the cart content and before the other blocks (coupon, s

For a module I'm working on, I want to add a block in the shopping cart screen, I want to do it unobtrusively and I'd like to place it beneath the cart content and before the other blocks (coupon, shipping estimation, totals, ...).

I've managed to do the unobtrusive part: an observer listens to controller_action_layout_load_before and if the FullNameAction is checkout_cart_index it adds a handle of my layout update xml file:

the observer:

public function showUpperGifts($observer)
{
    $fullNameAction = $observer->getEvent()->getAction()->getFullActionName();
    if ($this->_isEnabled &&
        ($fullNameAction == 'checkout_cart_index')) {
            $layoutUpdate = $observer->getEvent()->getLayout()->getUpdate()
                                ->addHandle('my_special_handle');
    }
}

and the layout file:

<my_special_handle>
    <reference name="content">
        <block type="module/block" name="module_block" template="module/block.phtml"/>
    </reference>
</my_special_handle>

With this, the content of my phtml file shows up, but I'm not able to place it where I want.

My first try was to use the before="name.of.block" attribute, but it doesn't work. If I use before="whatever" it开发者_开发百科 goes before everything inside the checkout.cart block, and if I use after="whatever" it goes after everything. In short it doesn't take the content of before or after into consideration.

Looking at the XML layout files of Magento's core modules, I realized that those argument for before and after only appears when the blocks they are placing after or before are inside the right/left columns. So my guess is that it's something special for those columns.

So my question is, can I specify the location of my block inside content? And yes, how?

Another solution would be to load the block asynchronously, as I could then append to the div of my choice the result of the AJAX call, but I'd rather do it in a "normal" way if I can.

Thanks for reading :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号