Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
magento管理产品网格将类别筛选器添加到管理网格,而不添加列_Magento_Magento 1.7 - Fatal编程技术网

magento管理产品网格将类别筛选器添加到管理网格,而不添加列

magento管理产品网格将类别筛选器添加到管理网格,而不添加列,magento,magento-1.7,Magento,Magento 1.7,我正在尝试在不添加类别列的情况下按类别筛选网格,是否有一种方法可以对网格执行此自定义筛选 下面是我所做的 function prepareCollection() { $catIdArray = getRequest()->getParam('cat_id'); //i.e $catIdArray = array(26, 27, 17); $collection = Mage::getModel('catalog/product')->getCollection(); $co

我正在尝试在不添加类别列的情况下按类别筛选网格,是否有一种方法可以对网格执行此自定义筛选

下面是我所做的

function prepareCollection()
{
$catIdArray = getRequest()->getParam('cat_id');
//i.e  $catIdArray = array(26, 27, 17);

$collection = Mage::getModel('catalog/product')->getCollection(); 

$collection->joinField(
    'category_id',
    'catalog/category_product',
    'category_id',
    'product_id=entity_id',
    null,
    'left'
)
->addAttributeToFilter( 
    'category_id',
    array('in' => $catIdArray)
)
->addAttributeToSelect('*');
$this->setCollection($collection);

这里的过滤器工作正常,但分页在这种情况下不起作用。请告诉我我做错了什么???

为了在扩展Magento后台办公室中的网格后修复分页,您需要扩展lib/Varien/Data/Collection/Db.php

Db.php复制到路径app/code/local/Varien/Data/Collection/Db.php,并将函数
getSelectCountSql
替换为以下内容:-

public function getSelectCountSql()
{   
    $this->_renderFilters();
    $countSelect = clone $this->getSelect();
    $countSelect->reset(Zend_Db_Select::ORDER);
    $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
    $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
    $countSelect->reset(Zend_Db_Select::COLUMNS);

    // Count doesn't work with group by columns keep the group by 
    if(count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
        $countSelect->reset(Zend_Db_Select::GROUP);
        $countSelect->distinct(true);
        $group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
        $countSelect->columns("COUNT(DISTINCT ".implode(", ", $group).")");
    } else {
        $countSelect->columns('COUNT(*)');
    }
    return $countSelect;
}

为了在Magento后台扩展网格后修复分页,您需要扩展lib/Varien/Data/Collection/Db.php

Db.php复制到路径app/code/local/Varien/Data/Collection/Db.php,并将函数
getSelectCountSql
替换为以下内容:-

public function getSelectCountSql()
{   
    $this->_renderFilters();
    $countSelect = clone $this->getSelect();
    $countSelect->reset(Zend_Db_Select::ORDER);
    $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
    $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
    $countSelect->reset(Zend_Db_Select::COLUMNS);

    // Count doesn't work with group by columns keep the group by 
    if(count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
        $countSelect->reset(Zend_Db_Select::GROUP);
        $countSelect->distinct(true);
        $group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
        $countSelect->columns("COUNT(DISTINCT ".implode(", ", $group).")");
    } else {
        $countSelect->columns('COUNT(*)');
    }
    return $countSelect;
}