Magento - 从当前查看的产品属性中获取集合
我试图在产品视图页面中返回一个产品集合,这些产品集合是由当前查看的产品中的属性组成的。
换句话说,假设我销售 CD,并且正在查看 Ray Charles CD。
在这个产品页面中,我想向其他人展示在“艺术家”中具有值“Ray Charles”的产品' 属性。但该值必须从当前查看的产品的“艺术家”值中动态提取。
我刚刚学会了这样做:
<?php
$model = Mage::getModel('catalog/product');
$collection = $model->getCollection();;
$collection->addFieldToFilter('artist', '81');
$collection->load();
?>
它可以根据 ID 为“81”的艺术家属性返回产品集合。但这是静态的。
如何告诉我的收藏检查当前查看的产品的“艺术家”值并使用它来过滤结果?
产品/view.phtml
非常感谢您的帮助。
I'm trying to return a collection of products, in the product view page, made from an attribute taken from the current viewed product.
In other words, let's say I sell CDs, and I'm viewing a Ray Charles CD.
In this very product page, I'd like to show others products that have the value 'Ray Charles', in the 'artist' attribute. Except this value has to be dynamically pulled from the current viewed product's 'artist' value.
I've just learned to do this:
<?php
$model = Mage::getModel('catalog/product');
$collection = $model->getCollection();;
$collection->addFieldToFilter('artist', '81');
$collection->load();
?>
Which can return a collection of products based on the artist attribute with an ID of '81'. But this is static.
How can I tell my collection to check for the 'artist' value of the current viewed product and use it to filter its results?
product/view.phtml
Thanks much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
产品页面已经注册了查看过的产品,因此您只需检索它:
Product pages register the viewed product already so you only need to retrieve it: