我对Magento比较陌生,所以如果以下是一个愚蠢明显的问题,请放轻松我!
我希望移动输出:
$this->getReviewsSummaryHtml($this->getProduct(), false, true);
目前它位于我的主view.phtml中,如此代码部分所示(它是从底部开始的五行):
<div class="product-shop">
<div class="product-name">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
<div class="coda-slider-wrapper">
<div class="coda-slider preload" id="coda-slider-1">
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
<div class="panel box-collateral <?php echo "box-{$alias}"?>">
<div class="panel-wrapper">
<?php if ($title = $this->getChildData($alias, 'title')):?>
<h2><?php echo $this->escapeHtml($title); ?></h2>
<?php endif;?>
<?php echo $html; ?>
</div>
</div>
<?php endforeach;?>
</div><!-- .coda-slider -->
</div><!-- .coda-slider-wrapper -->
</div>
<?php echo $this->getReviewsSummaryHtml($this->getProduct(), false, true); ?>
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getTierPriceHtml() ?>
<?php echo $this->getChildHtml('extrahint') ?>
在此位置输出的行是正确的,在页面上生成正确的“1 Review(s)| Add Your Review”。
我已将该代码包含在该行上方,因为它与此问题相关。正如你所看到的,我正在使用coda-slider,它可以处理,并生成4个选项卡。 XML相关的是:
<block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />
<block type="catalog/product_view_description" name="product.description" as="description" template="catalog/product/view/description.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
</block>
<block type="catalog/product_view_description" name="product.tips" as="tips" template="catalog/product/view/tips.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
</block>
<block type="catalog/product_view_description" name="product.delivery" as="delivery" template="catalog/product/view/delivery.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
</block>
<block type="review/product_view_list" name="product.reviews" as="reviews" template="catalog/product/view/reviews.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
</block>
<block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>
我想要做的是移动代码,将其包含在其中一个选项卡中,使用“reviews.phtml”在上面的XML中创建的代码,其代码为:
<h2 class="title"><?php echo $this->__('Reviews') ?></h2>
<?php $_items = $this->getReviewsCollection()->getItems();
if( count( $_items ) ){
// Once we've stored the reviews, we can loop through them and get the data we need from each
foreach( $_items as $_review ){?>
<p><strong><?php echo $this->htmlEscape( $_review->getTitle() );?></strong> by <?php echo $this->htmlEscape( $_review->getNickname() );?></p>
<p class="reviewBody"><?php echo $this->htmlEscape( $_review->getDetail() ); ?> </p>
<?php
}
}
echo $this->getReviewsSummaryHtml($this->getProduct(), false, true);
?>
现在问题是,在这个位置,代码抛出以下错误并调用堆栈:
Fatal error: Call to a member function assign() on a non-object in /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Review/Block/Product/View.php on line 67
Call Stack:
0.0010 632248 1. {main}() /home/default/littledickybird.co.uk/user/htdocs/1.6/index.php:0
0.0090 667600 2. Mage::run() /home/default/littledickybird.co.uk/user/htdocs/1.6/index.php:81
0.0340 887168 3. Mage_Core_Model_App->run() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/Mage.php:640
0.6510 3469248 4. Mage_Core_Controller_Varien_Front->dispatch() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Model/App.php:347
0.6610 3615704 5. Mage_Core_Controller_Varien_Router_Standard->match() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Controller/Varien/Front.php:176
0.6680 3693584 6. Mage_Core_Controller_Varien_Action->dispatch() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php:250
0.7280 4461864 7. Mage_Catalog_ProductController->viewAction() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Controller/Varien/Action.php:420
0.7290 4477472 8. Mage_Catalog_Helper_Product_View->prepareAndRender() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Catalog/controllers/ProductController.php:132
1.3449 14029888 9. Mage_Core_Controller_Varien_Action->renderLayout() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Catalog/Helper/Product/View.php:147
1.3449 14031072 10. Mage_Core_Model_Layout->getOutput() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Controller/Varien/Action.php:391
1.3449 14031152 11. Mage_Core_Block_Abstract->toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Model/Layout.php:529
1.3449 14031952 12. Mage_Core_Block_Template->_toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:863
1.3449 14031952 13. Mage_Core_Block_Template->renderView() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:286
1.3470 14032496 14. Mage_Core_Block_Template->fetchView() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:272
1.3479 14076336 15. include('/home/default/littledickybird.co.uk/user/htdocs/1.6/app/design/frontend/base/default/template/page/1column.phtml') /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:241
1.4389 14679288 16. Mage_Core_Block_Abstract->getChildHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/design/frontend/base/default/template/page/1column.phtml:48
1.4389 14679384 17. Mage_Core_Block_Abstract->_getChildHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:526
1.4389 14679384 18. Mage_Core_Block_Abstract->toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:582
1.4389 14679616 19. Mage_Core_Block_Text_List->_toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:863
1.4389 14679792 20. Mage_Core_Block_Abstract->toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Text/List.php:43
1.4389 14680024 21. Mage_Core_Block_Template->_toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:863
1.4389 14680024 22. Mage_Core_Block_Template->renderView() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:286
1.4399 14680160 23. Mage_Core_Block_Template->fetchView() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:272
1.4409 14722936 24. include('/home/default/littledickybird.co.uk/user/htdocs/1.6/app/design/frontend/LDB_default/default/template/catalog/product/view.phtml') /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:241
1.4589 14890792 25. Mage_Core_Block_Abstract->getChildGroup() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/design/frontend/LDB_default/default/template/catalog/product/view.phtml:57
1.4679 14919344 26. Mage_Core_Block_Abstract->getChildHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:785
1.4679 14919440 27. Mage_Core_Block_Abstract->_getChildHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:526
1.4679 14919440 28. Mage_Core_Block_Abstract->toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:582
1.4829 15243672 29. Mage_Review_Block_Product_View->_toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Abstract.php:863
1.4829 15243912 30. Mage_Core_Block_Template->_toHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Review/Block/Product/View.php:47
1.4829 15243912 31. Mage_Core_Block_Template->renderView() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:286
1.4829 15244056 32. Mage_Core_Block_Template->fetchView() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:272
1.4839 15286864 33. include('/home/default/littledickybird.co.uk/user/htdocs/1.6/app/design/frontend/LDB_default/default/template/catalog/product/view/reviews.phtml') /home/default/littledickybird.co.uk/user/htdocs/1.6/app/code/core/Mage/Core/Block/Template.php:241
1.4849 15287504 34. Mage_Review_Block_Product_View->getReviewsSummaryHtml() /home/default/littledickybird.co.uk/user/htdocs/1.6/app/design/frontend/LDB_default/default/template/catalog/product/view/reviews.phtml:12
我猜这是因为$这个现在是一个“Mage_Review_Block_Product_View_List”,而不是“Mage_Catalog_Block_Product_View”这个事实,但我完全不知道该怎么办!!!
请帮忙! (是的,这是一个相当绝望的请求!) 任何帮助将不胜感激。
亲切的问候所有人, 安迪。
答案 0 :(得分:2)
感谢您发布错误和堆栈跟踪,它使调试变得更加容易。
快速检查源代码显示以下行未返回块:
$this->getLayout()->getBlock('product_review_list.count')
如果您查看任何layout/review.xml
文件,您会看到review_product_list
部分包含一行来创建该丢失的块。
<block type="core/template" name="product_review_list.count" template="review/product/view/count.phtml" />
您可以将其复制到您希望计数显示的位置。如果您不想查看计数,则不需要模板,具有该名称的任何块都将执行:
<block type="core/abstract" name="product_review_list.count" />
答案 1 :(得分:1)
感谢clockworkgeek的帮助,这让我找到了寻找解决方案的正确途径。
他的解决方案为我提供了“1 Review(s)”,但没有提供“Add Your Review”。
经过调查,我发现“Mage_Review_Block_Product_View_List”会覆盖Mage_Catalog_Block_Product_Abstract中定义的函数getReviewsSummaryHtml。一个区别似乎是它没有调用“摘要”模板。
解决方案实际上是从内部转换XML:
<block type="review/product_view_list" name="product.reviews" as="reviews" template="catalog/product/view/reviews.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
为:
<block type="catalog/product_view" name="product.reviews" as="reviews" template="catalog/product/view/reviews.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
<block type="review/product_view_list" name="product.reviews_list" as="reviewslist" template="catalog/product/view/reviewslist.phtml" />
</block>
将reviews.phtml模板更改为:
<h2 class="title"><?php echo $this->__('Reviews') ?></h2>
<?php
echo $this->getReviewsSummaryHtml($this->getProduct(), false, true);
echo $this->getChildhtml('reviewslist');
?>
并添加第二个模板,reviewslist.phtml:
<?php
$_items = $this->getReviewsCollection()->getItems();
if( count( $_items ) ){
// Once we've stored the reviews, we can loop through them and get the data we need from each
foreach( $_items as $_review ){?>
<p><strong><?php echo $this->htmlEscape( $_review->getTitle() );?></strong> by <?php echo $this->htmlEscape( $_review->getNickname() );?></p>
<p class="reviewBody"><?php echo $this->htmlEscape( $_review->getDetail() ); ?> </p>
<?php
}
}
?>
然后我可以访问reviews.phtml中的正确getReviewsSummaryHtml()并访问reviewslist.phtml中的评论列表
好吧,它似乎有用,但我很乐意阅读任何人对我的解决方案的评论,特别是如果你看到我的方法中有任何明显的错误或者知道更有效/更优雅的解决方案。
此致 安迪