- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们想做的事情看起来很简单,我们想展示菜单中每个类别的热门产品。我们希望获得其中 5 个产品,因为这就是 UI 的设计目的。我们希望它们按受欢迎程度排序,我相信这是 Magento 中产品的浏览次数。
在很多情况下,我们请求的菜单类别本身没有产品。因此,它也必须支持为其 child 引入产品。我们的类别布局的一个分支的示例是:
此代码当前的作用是返回相同的热门产品列表,无论我们传递给过滤器的类别是什么。删除 ->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
快速查看产品数据会发现 $products->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
最佳答案
好吧,我找到了一个基本上可以通过缺乏工作和/或多类别过滤来解决的答案。它很脏,但是有用。它基于此处的博客文章:http://asia-connect.com.vn/2009/07/magento-filter-by-multiple-categories/
我不能说我对这个解决方案感到满意。我不明白为什么 Magento 会删除以有用的方式对类别进行过滤的功能。事实上,它似乎根本没有过滤任何东西,这让我的问题更加复杂。请随意提出更明智的解决方案。我很乐意用它替换这个解决方案。
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->addAttributeToSelect(array('name','small_image'))
->setStoreId($storeId)
->addStoreFilter($storeId)
// ->addCategoryFilter($category)
->addViewsCount()
->setPageSize($productCount);
$alias = 'cat_index';
$categoryCondition = $products->getConnection()->quoteInto(
$alias.'.product_id=e.entity_id AND '.$alias.'.store_id=? AND ',
$storeId
);
$cats = array( $category->getId() );
foreach($category->getChildren() as $catChild) {
$cats[] = $catChild->getId();
}
$categoryCondition.= $alias.'.category_id IN ('.implode(',',$cats).')';
$products->getSelect()->joinInner(
array($alias => $products->getTable('catalog/category_product_index')),
$categoryCondition,
array('position'=>'position')
);
$products->_categoryIndexJoined = true;
关于magento - 在 Magento 中按类别筛选热门产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5476694/
我正在研究这个领域以获得实时对象检测。 视频示例: http://www.youtube.com/watch?v=Bm5qUG-06V8 http://www.youtube.com/watch?v=
问题 我正在为 C 语言的项目寻找一种数据结构来存储列表列表。我需要能够访问仅给定 n 的第 n 个列表(这些术语将被乱序访问)。各个列表将包含 1 到 M 之间的整数(为了具体起见,假设 M = 2
我有一个List (Maybe a),我想过滤出Nothing的实例。我大概已经做到了,但是对所需的代码量却不满意: removeNothingFromList : List (Maybe a) ->
我对 Blazor 有基本的输入 当我输入我认为无效的字符(例如“/”或“:/\\""|?* ]"; Search = Regex.Replace(args.Value.ToSt
我有一个主应用程序,允许用户编辑所有数据(大约 20 个字段)。更新后,我将其添加到服务总线主题中,系统的其他区域也订阅了该主题。 其中一个订阅仅关心单个字段(电话号码)是否更新。我想知道处理这个问题
我是ElasticSearch的新手,需要帮助解决以下问题: 我有一组包含多个产品的文档。我想通过“Apple”过滤产品属性product_brand并获取与过滤器匹配的产品数量。但是,结果应按文档I
我想过滤查询集中特定范围内的项目。这就是我的模型的样子 class modelEmployee(models.Model): user = models.ForeignKey(User, on
尽管数组 a 的大小不断增加,但我无法找到 8 位素数。它适用于较小的数字: #include #include int main() { int n,a[100000],i,m,k;
我不希望能够使用代码隐藏来搜索我的 gridview 结果。 我有一个按钮和一个 GridView :
我想使用 sift/surf 进行模板匹配。图像可以有 1...n 个目标。使用 surf/sift 只能提取一个目标。一种想法是将图像分割成多个片段,然后寻找筛选/冲浪匹配。它有效,但显然由于速度和
这是使用 Xodus API 限制实体查询的方法: final EntityIterable allUsers = txn.getAll(storeName).skip(skip).take(limi
我有 2 个 excel 文件:IDList.csv 和 Database.csv。 IDList 包含我要从数据库中过滤掉的 300 个 ID 号的列表,其中包含 2000 个条目(在数据库中留下
过滤 Treeview 节点的最佳/有效方法是什么? 例如:我输入“abc”,只有包含“abc”的节点可见。然后我输入 “abcd”,我应该会看到唯一包含 “abcd” 文本的节点。依此类推,所以每次
我有两个关于报告的 tablix,以及一个用于向 tablix 提供数据的数据集。我在报告中有一个多选参数,我需要根据该参数中的值过滤结果。 有什么区别,如果有,什么是更好的解决方案: 直接在数据集或
我对 flex 搜索/ NEST还是很陌生,需要一些帮助才能查询/过滤我的数据。 我有一个产品 list 。而且这些产品可以具有任意数量的选项,并具有与之相关的值。而且我需要能够按选项名称及其值来过滤
我正在使用过滤条件从原始表创建一个表,其中我的过滤值来自 SELECTEDVALUE 表格没有根据 SELECTEDVALUE 进行过滤,如果我用一个真实的值替换它就可以了。 代码(不起作用) Tra
我正在设置一个 MSBuild 项目来运行一些 NUnit 测试,使用 MSBuild Community Tasks Project 。 通过这些设置,我将能够运行 NUnit 测试:
我正在使用过滤条件从原始表创建一个表,其中我的过滤值来自 SELECTEDVALUE 表格没有根据 SELECTEDVALUE 进行过滤,如果我用一个真实的值替换它就可以了。 代码(不起作用) Tra
例如,我们有一个列表,我们想用特定的谓词将其分成两部分。 首先,我们可以使用filter和filterNot。 val trueList = list.filter(predicate) val fa
我尝试为 [Start] 使用某种范围: var calendar = outlookApplication.GetNamespace("MAPI").GetDefaultFolder(OlDefau
我是一名优秀的程序员,十分优秀!