2

カスタム モジュールを使用して、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();

    }


}
4

2 に答える 2

4

これは私の場合にうまくいったものです:

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

于 2014-02-07T07:23:17.437 に答える
2

管理販売グリッドにさらに列を追加しているように見えますか? また、2 番目のテーブルに対する結合を含むコレクションを操作しているように思えます。テーブル エイリアス名を、increment_id 列定義を使用して where ステートメントに追加する必要がありますtable_alias.increment_id

これを確認するには、 $this->getCollection()fromを呼び出すと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);

于 2013-03-11T17:33:59.213 に答える