在Magento中将订单商品添加到订单网格

时间:2013-04-17 16:22:10

标签: magento

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

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

我也在此视图中添加了另一个客户属性。当我添加产品列表时,找到的订单数量始终设置为1,并且不允许我转到订单的下一页。

enter image description here

这是我设法添加的代码。

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',

    ));

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

1 个答案:

答案 0 :(得分: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();
        }