1

我正在尝试使用 Grid.php 将订购的产品添加到管理员中的订单网格。

app\code\core\Mage\Adminhtml\Block\Sales\Order\Grid.php

我还向此视图添加了另一个客户属性。当我添加产品列表时,找到的订单数量总是设置为一个,它不会让我转到下一页订单。

在此处输入图像描述

这是我设法添加的代码。

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('name'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.name SEPARATOR ", ")')));
    $collection->getSelect()->group('entity_id');
    $collection->getSelect()->joinLeft(
                array('cev' => 'customer_entity_varchar'),
                '(main_table.customer_id = cev.entity_id AND cev.attribute_id = 141 AND main_table.customer_id IS NOT NULL)',
                array(
                    'admin_number' => 'cev.value',
                )
            );

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

   $this->addColumn('admin_number', array(
            'header' => Mage::helper('sales')->__('Admin Number'),
            'filter_index' => 'cev.value',
            'index' => 'admin_number'
    ));

$this->addColumn('name', array(
        'header'    => Mage::helper('Sales')->__('Products'),
        'width'     => '100px',
        'index'     => 'name',
        'type'        => 'text',

    ));

希望有人能帮我看看有什么问题。

4

1 回答 1

2
    protected function _prepareCollection()
        {
    $userArray = Mage::getSingleton('admin/session')->getData();
    $user = Mage::getSingleton('admin/session');
    $userId = $user->getUser()->getUserId();

    $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
    $sql        = "Select * from sales_flat_order_grid as sss, junaidbhura_jbmarketplace_products as vitem, sales_flat_order_item as item WHERE vitem.product_id = item.product_id and sss.entity_id = item.order_id and vitem.user_id = $userId";
    $rows       = $connection->fetchAll($sql); //fetchRow($sql), fetchOne($sql),...
    //Zend_Debug::dump($rows);
    $pk = 0;
    foreach($rows as $value){
    $pkorder[] = $rows[$pk]['order_id'];
    $pk++;
    }

    //print_r( $pkorder);


    //print_r($userId);
    //die;

            $collection = Mage::getResourceModel($this->_getCollectionClass());
            if($userId == 1 ){ }else{
            $collection->addFieldToFilter('entity_id', array('in' => array( $pkorder )));
            }
            $this->setCollection($collection);
            return parent::_prepareCollection();
        }
于 2013-12-28T10:22:00.753 回答