dongrong6235 2013-12-02 10:10
浏览 28

在缓存开启的Magento页脚部分获取类别信息

I'm having a problem with Magento blockcache and FPC turned on. I'm trying to output some category information in the page footer, but that block doesn't seem to be able to get the right category information. When I output the same thing into the categorys view.phtml file it workes fine, but in the footer the cache will not recognize the different categories and output from first visited category page.

I've tried getting the category information with (syntax from memory, might not be accurate):

  • Magento::registry('current_category')
  • Changing the block type to category_view and using same method as the prduct listing, with $this->getCurrentCategory()-getId();
  • checking how the block code for category listing loads the data, using the request ID and loading the category object from scratch.

All of these methods fail, and will basically show the wrong category ID and info except for maybe the first one I visit.

The block isn't part of a module, just a phtml file included in local.xml but in my attempts I've also tried making a basic module and doing it in a block file.

It seems as if the block output is global based on the XML block name, and not tied into the FPC view? Also, I'm unsure of how the product listing block manages to get the right category data out but it seems damn near impossible in any other part of the page?

Am I forced to try and solve it with hole punching? Becasue I've tried that too. Didn't work, or maybe I didn't get the holepunching to function since I've never done it before..

The thing is that I'd actually want this block to be cached, just not in a global fashion - but instead based on what category I'm on. Any suggestions or insight into how and why I might solve this?

I could perhaps output the info I want in the product listing part and move it down with js, but I would very much prefer not to as you might imagine.

  • 写回答

1条回答 默认 最新

  • duanji2002 2014-02-21 23:06
    关注

    I had a similar problem. Are you calling your block like so?

    $this->getChildHtml('my_block');
    

    Call it like this:

     $this->getChildHtml('my_block',false);
    

    "false" will disable caching for that one block being called. I had to do the same on a block I was calling within the head, worked like a charm.

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?