我们试图做的事似乎很简单,我们希望在菜单中显示来自每个类别的热门产品。我们希望获得这些产品中的5款,因为这就是UI设计要处理的内容。我们希望他们按照受欢迎程度排序,我相信这是Magento产品的视图数量。按照Magento中的分类筛选热门产品
很多情况下,我们要求的菜单类别本身没有产品。因此,它必须支持为其孩子提供产品。我们的类布局的一个分支的例子是:
- 男士,#2(没有物品)
- 恤衫,#5(具有项)
- 附件,#6(具有项)
- 裤子,#7(有项目)
- 等,#8(有项目)
这段代码CUR不管我们通过它过滤的类别,它都会返回相同的热门产品列表。删除 - > addCategoryFilter(...)可以有效地返回相同的结果。我怀疑如果我们能够解决如何按类别过滤,其余的将落到位。
$storeId = 1;
$category; // Category Object for id = 2 passed to this code
$productCount = 5;
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->addAttributeToSelect(array('name','small_image'))
->setStoreId($storeId)
->addStoreFilter($storeId)
->addCategoryFilter($category)
->addViewsCount()
->setPageSize($productCount);
我们已经对此尝试了一些变化。我不确定addCategoryFilter(...)方法是否考虑了子类别。如果不是,那应该很容易查询和解决。当然,就目前来看,它只是总是返回相同的产品,而没有对类别进行过滤......首先,他们会说。
运行Magento的1.4.0.1
快速查看产品的数据显示,这些键的$产品 - > getFirstItem() - >的getData()是:
Array
(
[0] => entity_id
[1] => entity_type_id
[2] => attribute_set_id
[3] => type_id
[4] => sku
[5] => has_options
[6] => required_options
[7] => created_at
[8] => updated_at
[9] => name
[10] => url_key
[11] => gift_message_available
[12] => meta_title
[13] => meta_description
[14] => image
[15] => small_image
[16] => thumbnail
[17] => custom_design
[18] => page_layout
[19] => options_container
[20] => url_path
[21] => image_label
[22] => thumbnail_label
[23] => small_image_label
[24] => description
[25] => short_description
[26] => meta_keyword
[27] => custom_layout_update
[28] => weight
[29] => price
[30] => special_price
[31] => cost
[32] => news_from_date
[33] => news_to_date
[34] => special_from_date
[35] => special_to_date
[36] => custom_design_from
[37] => custom_design_to
[38] => exclusive
[39] => size
[40] => color
[41] => status
[42] => visibility
[43] => is_imported
[44] => tax_class_id
[45] => enable_googlecheckout
[46] => is_recurring
[47] => is_salable
[48] => stock_item
)
可悲的是没有category_ids
我试过这种变化,它会抛出一个异常,并显示以下消息:“无效的属性名称:category_ids。” – jsapara 2011-03-29 19:56:42
实际上,它看起来像Magento 1.4的category_ids字段已被删除。 – jsapara 2011-03-29 20:25:34
soory,有一个关于category_id的bug跟踪问题,因为1.4.2升级 http://www.magentocommerce.com/bug-tracking/issue?issue=10662 – 2011-03-29 20:52:37