Magento 中按类别分类的新产品
这应该是一件愚蠢的事情,但它让我发疯!
我只想展示指定类别的新产品,但我得到的只是任何类别的新产品。
假设我想显示类别 74,我几乎尝试了该代码的任何组合
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" category_id="74" template="catalog/product/new.phtml"}}
直接分配了category_id
{{block type="catalog/product_new" category_id="74" template="catalog/product/new.phtml"}}
类别隐式取决于或我正在访问哪个类别
{{block type="catalog/product_new" template="catalog/product/new.phtml"}}
此代码已经过测试,在主页代码中硬编码,创建一个静态块,并通过类别面板(静态块和产品)包含它......但毫无价值。我测试了在这个论坛和其他论坛中找到的几乎所有代码,但没有结果。
无论任何代码(分配了category_id =“74”或未分配),我总是得到相同的结果。类别过滤器不起作用,并显示来自任何类别的新产品,而不是当前类别的新产品,也不是手动编码类别的产品(例如category_id =“74”)
另一方面,如果我使用列表产品而不是新产品,在主页和静态块中工作正常,因此类别似乎创建得很好
{{block type="catalog/product_list" category_id="74" template="catalog/product/list.phtml"}}
这向我显示了属于类别 74 的产品
我正在使用 magento Magento 版本。 1.3.2.4,即使使用不同的模板也显示相同的结果。
任何建议都会受到欢迎祝你
有美好的一天,J.PS
我也尝试过其他类别,不仅是74。有父类别,子类别......但根本没有结果
This should be supposed to be silly thing but it’s driving me nuts!
All I want is to show the new products for a specified category, but all I get is new products from any category.
Supposing I want to show up the category 74, I’ve tried almost any combination of that code
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" category_id="74" template="catalog/product/new.phtml"}}
With a category_id directly assigned
{{block type="catalog/product_new" category_id="74" template="catalog/product/new.phtml"}}
With category implicit depending or which category I’m accessing
{{block type="catalog/product_new" template="catalog/product/new.phtml"}}
This code has been tested, hardcoded in home page code, creating a static block with it and including it through category panel (static block and products)…but worthless. I’ve tested almost any code I’ve found in this and other forums but no result.
Regardless of any code (with category_id="74" assigned and not), I’m all the time getting the same result. The category filter doesn’t work and shows me new products from any category, not the new products of the current category, neither the products of a handcoded category (for instance category_id="74")
On the other hand if I use list products instead of new products, works OK in home page and as static block, so categories seem to be well created
{{block type="catalog/product_list" category_id="74" template="catalog/product/list.phtml"}}
That shows me products that belong to category 74
I’m using magento Magento ver. 1.3.2.4, and shows me the same result even using different templates.
Any advice will be welcomed
Have a nice day, J.
PS I've tried also with other categories, not only 74. With parent categories, child categories...but no result at all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最后非常简单...
使用下面的定义块:
要检索category_id,您应该像这样修改新类的_beforeToHtml函数:
File in \app\code\core\Mage\Catalog\Block\Product\New.php
首选在本地路径中附加此文件
您可以看到已添加 if 语句:
您使用函数 $this->getData('category_id') 检索category_id
享受...
Finally very simple...
Use the definition block below :
To retrieve the category_id, you should modifiy the _beforeToHtml function of the new class like this :
File in \app\code\core\Mage\Catalog\Block\Product\New.php
Prefer surcharge this file in local path
You can see that an if statement has been added :
You retrieve the category_id with the function $this->getData('category_id')
Enjoy...
catalog/product_new
块不接受category_id 作为参数。如果您想对单个类别执行此操作,则需要创建自己的源自catalog/product_new
的自定义块,并重写方法_beforeToHtml
以利用 Category_id 。希望有帮助!
谢谢,
乔
The
catalog/product_new
block doesn't accept a category_id as a parameter. If you want to do this for a single category, you'll need to create your own custom block that descends fromcatalog/product_new
and override the method_beforeToHtml
to utilize a category_id.Hope that helps!
Thanks,
Joe
我认为您想像这样更改 New.php:
$collection = Mage::getResourceModel('catalog/product_collection');
变成这样(getStoreId 可选)...
$featCat = Mage::getModel('目录/类别')->load($this->getCategory());
$collection = Mage::getResourceModel('catalog/product_collection')->setStoreId($this->getStoreId())->addCategoryFilter($featCat);
...显然你必须创建像“setCategory”、“getCategory”这样的 getter 和 setter
I think that you want to alter the New.php like this:
$collection = Mage::getResourceModel('catalog/product_collection');
becomes this (getStoreId optional)...
$featCat = Mage::getModel('catalog/category')->load($this->getCategory());
$collection = Mage::getResourceModel('catalog/product_collection')->setStoreId($this->getStoreId())->addCategoryFilter($featCat);
...obviously you will have to create getter and setter like 'setCategory', 'getCategory'
这对我有用。
This works for me.