Magento 和相关产品的帮助
我有一个客户产品页面,实际上位于catalog/product/view.phtml 页面旁边。它与该页面基本相同,但有一些小例外。它基本上是一个“每日产品”类型页面,因此我无法将其与常规产品页面结合起来,因为我必须从数据库中获取数据并执行加载以获取产品信息
$_product = Mage::getModel('catalog/product')->load($row['productid']);
长话短说,一切作品(包括所有子 html 块),但相关产品除外。
加载后,我将产品保存到注册表中
Mage::register('product', $_product);
,然后尝试使用以下内容加载相关产品:
echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('catalog/product/list/related.phtml')->toHtml();`
所有这些都会返回错误:
Fatal error: Call to a member function getSize() on a non-object in catalog/product/list/related.phtml on line 29`,
并且第 29 行是
<?php if($this->getItems()->getSize()): ?>`.
任何帮助加载相关产品的帮助。
I have a customer product page that literally lives beside the catalog/product/view.phtml page. It's basically identical to that page with a few small exceptions. It's basically a 'product of the day' type page so I can't combine it with the regular product page since I have to fetch the data from the DB and perform a load to get the product information
$_product = Mage::getModel('catalog/product')->load($row['productid']);
To make a long story short, everything works (including all children html blocks) with the singular exception of the related products.
After the load I save the product into the registry with
Mage::register('product', $_product);
and then attempt to load the related products with:
echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('catalog/product/list/related.phtml')->toHtml();`
All of which give back the error:
Fatal error: Call to a member function getSize() on a non-object in catalog/product/list/related.phtml on line 29`,
and line 29 is
<?php if($this->getItems()->getSize()): ?>`.
Any help getting the relateds to load would be appreicated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太明白你想要做什么,但我知道你为什么会遇到错误。您正在创建一个块,其类别名/类为
,但您将此块的模板设置为
Stock
catalog/product/list/lated.phtml
模板是为了与一起使用而构建的>catalog/product_list_lated
块仅,而不是catalog/product_view
块。如果您查看
catalog/product_list_lated
块(即Mage_Catalog_Block_Product_List_Related
)的类定义,您可以看到有一个getItems()方法。
它返回一个集合。该集合是在
_prepareData
方法中设置的。此集合从未使用
catalog/product_view
块进行设置,这就是您收到错误的原因。在上面的代码中,如果您切换到创建
catalog/product_list_lated
块,您的错误应该会消失。I didn't quite follow what you're trying to do, but I know why you're getting your errors. You're creating a block whose class-alias/class is
but you're setting this block's template as
The stock
catalog/product/list/related.phtml
template was built to be used with acatalog/product_list_related
Block only, and not acatalog/product_view
Block.If you take a look at the class definition for a
catalog/product_list_related
Block (which is aMage_Catalog_Block_Product_List_Related
), you can see that there's agetItems()
method.which returns a collection. The collection is set in the
_prepareData
methodThis collection is never set with a
catalog/product_view
Block, which is why you're getting your errors.In your code above, if you switch to creating a
catalog/product_list_related
block, your errors should go away.当产品添加到购物车后,通过ajax调用获取相关块的html。可能相对有帮助。
Getting html of related block through ajax call, right after when product is added to cart. might be relatively helpful.