简体   繁体   English

magento两次加载catalog / product / view.phtml

[英]magento loads catalog/product/view.phtml twice

I am trying to create a magento side bar box that can list products in certain category. 我正在尝试创建一个magento侧边栏框,该框可以列出某些类别的产品。

I have created a file that creates a list of products in a certain catagory called most_sold_list.phtml with the following contents... 我创建了一个文件,该文件创建了一个名为most_sold_list.phtml的类别中的产品列表,具有以下内容...

    <?php
        $_productCollection_1 = $this->getLoadedProductCollection();
    ?>
    <div class="link_list_with_title">
        <p class="catagory_title">Best Sellers</p>

        <ul>
        <?php foreach ($_productCollection_1 as $_product_1): ?>
            <li>
                <a href="<?php echo $_product_1->getProductUrl() ?>" title="<?php echo $_product_1->getName(); ?>"><?php echo $_product_1->getName(); ?></a>
            </li>
        <?php endforeach ?>
        </ul>
    </div>

I then update my local.xml to contain (within <default><reference name="left"> )... 然后,我将local.xml更新为包含(在<default><reference name="left"> )...

    <block type="catalog/product_list" name="most_sold.leftnav" template="most_sold_list.phtml">
        <action method="setCategoryId"><category_id>18</category_id></action>
    </block>            

This add the block to the page as I would expect. 如我所料,这会将块添加到页面中。 But when I go to the products page I get the following error... 但是当我转到产品页面时,出现以下错误...

Fatal error: Cannot redeclare get_quatity_weight_string_view() (previously declared in /.../app/design/frontend/superchef/default/template/catalog/product/view.phtml:37) in /.../app/design/frontend/superchef/default/template/catalog/product/view.phtml on line 54

I have checked and that function is not declared anywhere else and this error message goes away as soon as I remove my new block. 我已经检查过了,在其他任何地方都没有声明该函数,并且在删除新块后,该错误消息就会消失。 Also note line 54 is the closing brace of the function. 另外请注意,第54行是该功能的右括号。

I have tried removing that function completely by putting its code inline but then I just get the magento error message page. 我试着通过将其代码内联来完全删除该功能,但随后我只得到了magento错误消息页面。

The only conclusion I can come to is that view.phtml is being loaded twice. 我唯一可以得出的结论是,view.phtml被加载两次。 I have searched for this and I have seen mentions of zend loader loading files twice. 我已经进行了搜索,并且看到两次提到zend loader加载文件的信息。

Can anybody help me fix this, it makes no sense to me. 谁能帮我解决这个问题,对我来说毫无意义。

I have now worked out how to solve this problem from reading this: http://www.bwigg.com/2010/01/magento-featured-products-in-sidebar/ 我现在通过阅读以下内容解决了该问题的解决方法: http : //www.bwigg.com/2010/01/magento-featured-products-in-sidebar/

So here is what I have done incase anybody else hits this weird problem. 因此,如果有人遇到这个奇怪的问题,这就是我要做的事情。

update the layout xml file so the block type is "catalog/navigation". 更新布局xml文件,使块类型为“目录/导航”。

So it now looks like this... 所以现在看起来像这样...

<block type="catalog/navigation" name="most_sold.leftnav" template="most_sold_list.phtml">
            <action method="setCategoryId"><category_id>18</category_id></action>
 </block>
  <remove name="category.products" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM