use*_*256 2 collections pagination product catalog magento
我正在尝试过滤list.phtml以满足我的需求,只显示基于属性值的产品.加载产品集合的原始代码是:
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
Run Code Online (Sandbox Code Playgroud)
要做过滤我得到了代码:
$_productCollection=$this->getLoadedProductCollection();
$cat_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('language', array('eq' => array('English')))
->addAttributeToSelect('*')
->addCategoryFilter(Mage::getModel('catalog/category')->load($cat_id));
$_helper = $this->helper('catalog/output');
Run Code Online (Sandbox Code Playgroud)
然而,这适用于分页和项目总数(从toolbar.phtml和pager.phtml生成不正确.例如,原始产品集合具有7页的正确分页和每页10个产品.
然而,当我使用上面显示的过滤器时,分页在一页上显示相同的7页和每个过滤的书(有18本英文书籍,因此18本书中的7页是重复的).
请有人帮我解决这个分页问题.
谢谢.
该集合的SQL如下:
SELECT `e`.*, `at_language`.`value` AS `language`, `cat_index`.`position`
AS `cat_index_position` FROM `catalog_product_entity`
AS `e` INNER JOIN `catalog_product_entity_varchar`
AS `at_language` ON (`at_language`.`entity_id` = `e`.`entity_id`)
AND (`at_language`.`attribute_id` = '1002')
AND (`at_language`.`store_id` = 0) INNER JOIN `catalog_category_product_index`
AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1
AND cat_index.visibility IN(2, 4) AND cat_index.category_id='38'
AND cat_index.is_parent=1 WHERE (at_language.value = 'English')
Run Code Online (Sandbox Code Playgroud)
在list.phtml文件中使用它:
$_productCollection->clear()
->addAttributeToFilter('attribute_set_id', array('eq' => 63))
->load();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13604 次 |
| 最近记录: |