搜索销售订单网格重定向到magento 1.7中的仪表板

时间:2013-03-11 16:45:32

标签: magento magento-1.7

我使用自定义模块向Magento中的Sales_Order_Grid添加新列,但如果我搜索Order_Id,页面会重定向到仪表板。

如果我再次尝试选择销售/订单,我会收到错误:

a:5:{i:0;s:104:"SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'increment_id' in where clause is ambiguous";i:1;s:6229:"#0

我不知道如何解决这个问题,并且可以做一些指导吗?

这是Grid.php代码:

<?php
class Excellence_Salesgrid_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{


    protected function _addColumnFilterToCollection($column)
    {
        if ($this->getCollection()) {
            if ($column->getId() == 'shipping_telephone') {
                $cond = $column->getFilter()->getCondition();
                $field = 't4.telephone';
                $this->getCollection()->addFieldToFilter($field , $cond);
                return $this;
            }else if ($column->getId() == 'shipping_city') {
                $cond = $column->getFilter()->getCondition();
                $field = 't4.city';
                $this->getCollection()->addFieldToFilter($field , $cond);
                return $this;
            }else if ($column->getId() == 'shipping_region') {
                $cond = $column->getFilter()->getCondition();
                $field = 't4.region';
                $this->getCollection()->addFieldToFilter($field , $cond);
                return $this;
            }else if ($column->getId() == 'shipping_postcode') {
                $cond = $column->getFilter()->getCondition();
                $field = 't4.postcode';
                $this->getCollection()->addFieldToFilter($field , $cond);
                return $this;
            }else if($column->getId() == 'product_count'){
                $cond = $column->getFilter()->getCondition();
                $field = ( $column->getFilterIndex() ) ? $column->getFilterIndex() : $column->getIndex();
                $this->getCollection()->getSelect()->having($this->getCollection()->getResource()->getReadConnection()->prepareSqlCondition($field, $cond));
                return $this;
            }else if($column->getId() == 'skus'){
                $cond = $column->getFilter()->getCondition();
                $field = 't6.sku';
                $this->getCollection()->joinSkus();
                $this->getCollection()->addFieldToFilter($field , $cond);
                return $this;
            }else{
                return parent::_addColumnFilterToCollection($column);
            }
        }
    }

    protected function _prepareColumns()
    {

        $this->addColumnAfter('shipping_description', array(
                'header' => Mage::helper('sales')->__('Shipping Method'),
                'index' => 'shipping_description',
        ),'shipping_name');
        $this->addColumnAfter('method', array(
                'header' => Mage::helper('sales')->__('Payment Method'),
                'index' => 'method',
                'type'  => 'options',
                'options' => Mage::helper('payment')->getPaymentMethodList()
        ),'shipping_description');

        $this->addColumnAfter('shipping_city', array(
                'header' => Mage::helper('sales')->__('Shipping City'),
                'index' => 'shipping_city',
        ),'method');

        $this->addColumnAfter('shipping_telephone', array(
                'header' => Mage::helper('sales')->__('Shipping Telephone'),
                'index' => 'shipping_telephone',
        ),'method');

        $this->addColumnAfter('shipping_region', array(
                'header' => Mage::helper('sales')->__('Shipping Region'),
                'index' => 'shipping_region',
        ),'method');

        $this->addColumnAfter('shipping_postcode', array(
                'header' => Mage::helper('sales')->__('Shipping Postcode'),
                'index' => 'shipping_postcode',
        ),'method');

        /*$this->addColumnAfter('product_count', array(
                'header' => Mage::helper('sales')->__('Product Count'),
                'index' => 'product_count',
                'type' => 'number'
        ),'increment_id');

        /*$this->addColumnAfter('skus', array(
                'header' => Mage::helper('sales')->__('Product Purchased'),
                'index' => 'skus',
        ),'increment_id');*/

        return parent::_prepareColumns();

    }


}

2 个答案:

答案 0 :(得分:3)

这就是我的情况:

$ collection-&gt; addFilterToMap('increment_id','main_table.increment_id');

答案 1 :(得分:2)

看起来您要向管理销售网格添加更多列?听起来您正在使用包含第二个表的连接的集合,您需要将表别名添加到带有increment_id列定义的where语句中,因此table_alias.increment_id

要检查这一点,并假设从$this->getCollection()调用Excellence_Salesgrid_Block_Adminhtml_Sales_Order_Grid返回集合,请从集合中获取select对象:

$select = $this->getCollection()->getSelect();

希望您使用带有IDE的xdebug并在代码中设置断点。如果是这样,设置断点并检查上面一行拉出的$select对象。在此对象中,您将看到一个_parts数组,它描述了构造select语句的方式。在此内部,您将看到一个from数组,其中包含有关作为语句一部分的表的信息。如果您有JOIN,则会包含多个条目。

在这里你还可以看到where,它将描述作为声明一部分的where子句 - 这就是问题可能存在的地方。您需要在from数组中找到正确表的别名,然后在where子句的位置添加,而不是执行以下操作:

$this->getCollection()->getSelect()->where('increment_id = ?', $id);

代替:

$this->getCollection()->getSelect()->where('table_alias.increment_id = ?', $id);