开发者

Trying to create rule based static blocks in Magento

So one of my clients has a request to do rule based static blocks on their home page. The page will basically swap out several static blocks for others based on the perceived gender of the person viewing the site. It will get this data from the session that the user is currently in, or the data associated with the users account. Basically, if a user searches in a specific set of categories (Men's or Women's categories) it should swap the static blocks out on the home page, so when that user visits the site again they will have a more personalized experience. There will be a default set of blocks if the user is new to the site.

Something like this (and excuse my shabby php):

if($categories = $user->getViewedCategories()){
    foreach($categories as $category){
        switch开发者_开发知识库($category){
            case 14: //insert womens category id here
                echo $staticBlockWomen
                break;
            case 16: //insert mens category id here
                echo $staticBlockMen
                break;
        }
    }
} else {
    echo $staticBlockDefault
}

I know Magento tracks a users path through a site, and I know that other elements in Magento can have rules based on this data (the dynamic banners and checkout rules), but I am really lost on where to get started.

If someone could point me in the right direction, any help would be appreciated!

Cheers, Matthew


I'm assuming you know the basics of Magento (at least how to create new blocks and how to manage the layout using xml).

If you need more info about that,

You can accomplish what you need in a few steps:

1 - create the blocks you need (create a new module and block classes inside it within the corresponding .phtml files)

2 - from the admin panel, select the category for which you want to add a block and navigate to "Custom Design" tab, then add in the "Custom Layout Update" textarea something like this:

<reference name="content" >
    <block type="mymodule/myblock" name="myblock" />
</reference>

This way, every time the selected category is viewed by the custmer, a block of type "mymodule/myblock" will be added in the content area.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜