如何从 magento 电子商务中的特定类别获取产品
I'd like to get a list of random products from the same category as the current product for displaying within the product view - so far all I've dug up is
Magento products by categories
Does anyone know how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您基本上加载类别,获取产品集合,然后进行适当的过滤。
You basically load up the category, get the Product Collection and then filter appropriately.
以下是从任何特定类别获取产品的代码:-
Here is the code to get products from any particular category:-
我最终做的是在 app/design/frontend/default/theme_name/template/catalog/product/list_random.phtml 中
执行以下操作:
这将为您提供一系列产品 id。 您可以循环遍历它们并使用以下方法动态创建产品:
然后,在 cms 中创建包含以下内容的静态块
最后,在目录 -> 管理类别部分中,选择类别,然后选择显示设置选项卡。 将显示模式切换为“静态块和产品”,然后从下拉列表中选择您的块。
那应该可以了。
what I ended up doing is in app/design/frontend/default/theme_name/template/catalog/product/list_random.phtml
doing something like:
this will get you an array of product id's. You can loop through them and create products on the fly using:
then, create a static block in the cms with the following content
Finally, in the Catalog->Manage categories section, choose the category, then the display settings tab. Switch the display mode to "Static block and products" and then choose your block from the drop list.
And that should do it.
这是迄今为止获取特定类别的产品详细信息的便捷代码。希望它对您有所帮助。
This is the by far the convenient code in order to fetch product details of perticular category.Hope it helps you.
在这种情况下,您应该通过调用
Mage::getModel('catalog/product')
来实例化模型,因为这样您就会获得一个已配置的对象实例,并由任何已配置的模块进行扩展。如果您像
new Mage_Catalog_Model_Product()
那样执行,这将忽略模块并绕过 Magento API。You should instantiate a model by calling
Mage::getModel('catalog/product')
in this case because then you get a configured object instance, extended by any configured modules.If you do it like
new Mage_Catalog_Model_Product()
this will ignore modules and bypass the Magento API.此代码将帮助您从类别 ID 2 获取产品。 这里还使用模板文件list_home.phtml来显示产品列表。
list_home.phtml
This code will helps you to get products from category id 2. And also here uses a template file list_home.phtml for the product listing.
list_home.phtml