【问题标题】:Magento getUrl showing cached urlMagento getUrl 显示缓存的 url
【发布时间】:2015-11-15 14:30:18
【问题描述】:

我添加了一个显示父类别的子类别的自定义块。如下。

<?php
$_helper    = $this->helper('catalog/output');
$_category  = $this->getCurrentCategory();

echo $_helper->categoryAttribute($_category, $_category->getName(), 'name');
$categoriess = $_category->getCollection()
    ->addAttributeToSelect(array('name', 'thumbnail'))
    ->addAttributeToFilter('is_active', 1)
    ->addIdFilter($_category->getChildren())
?>
<ul class="subcategories">
<?php foreach ($categoriess as $categoryy): ?>
    <li>
        <a href="<?php echo $categoryy->getUrl() ?>"><img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $categoryy->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($categoryy->getName()) ?>"   />
            <span><?php echo $categoryy->getName() ?></span></a>
    </li>
<?php endforeach; ?>
</ul>

此代码正确显示了父类别中的子类别列表。但是,当我导航到这些子类别之一时,会发生一些奇怪的事情。

问题

父类别 = CAR MAKES 子类别 = 奥迪、福特、沃克斯豪尔

使用上面的代码,我正确地收到了上面子类别的列表。刷新缓存后,如果我要导航到 AUDI,则会正确生成 url,例如:

 mysite.com/CAR MAKES/Audi.html

这很好,但是如果我然后返回并导航到 FORD,页面顶部的 url 会显示为

 mysite.com/CAR MAKES/Ford.html

但是

如果我使用此代码在生成的页面上回显 url:

<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); echo $currentUrl; ?>

它会一直显示

mysite.com/CAR MAKES/Audi.html

即使我导航到 FORD 或 VAUXHALL,回显的 url 也是 /Audi.html,尽管页面顶部的 url 显示正确。

我完全不知道为什么会这样。我正在尝试为每个汽车品牌和型号生成一个产品列表,但是一旦您导航到一个品牌和型号,它会在导航到另一个品牌和型号时始终显示这些结果。除非我刷新缓存,在这种情况下,我第一次导航到品牌和模型时它会正确显示,然后错误会重复。

【问题讨论】:

    标签: php magento url caching categories


    【解决方案1】:

    在您的布局更新中添加此代码。

    <block type="core/template" template="your-template-path.phtml" name="template-name" ><action method="setCacheLifetime"><s>null</s></action></block>
    

    【讨论】:

    • 好的,我已经尝试将此添加到类别布局更新中,但没有任何效果。通过此代码调用显示产品子类别的 cmd 块:{{block type="catalog/navigation" template="catalog/category/sub.phtml"}} 不确定这是否有任何区别
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多