0

Magento 管理パネルでは、group列を使用して顧客を並べ替えました。

しかし、エラーのあるクエリが表示されます。

つまり、group列をクリックすると magento admin に移動しdashboardます。

そのため、[顧客の管理] リンクをもう一度クリックしましたが、クエリでエラーが表示されるようになりました。

以下は、エラーのあるクエリです。

SELECT `e`.*, `at_prefix`.`value` AS `prefix`, `at_firstname`.`value` AS `firstname`, `at_middlename`.`value` AS `middlename`, `at_lastname`.`value` AS `lastname`, `at_suffix`.`value` AS `suffix`, CONCAT(IF(at_prefix.value IS NOT NULL AND at_prefix.value != '', CONCAT(LTRIM(RTRIM(at_prefix.value)), ' '), ''), LTRIM(RTRIM(at_firstname.value)), ' ', IF(at_middlename.value IS NOT NULL AND at_middlename.value != '', CONCAT(LTRIM(RTRIM(at_middlename.value)), ' '), ''), LTRIM(RTRIM(at_lastname.value)), IF(at_suffix.value IS NOT NULL AND at_suffix.value != '', CONCAT(' ', LTRIM(RTRIM(at_suffix.value))), '')) AS `name`, `at_default_billing`.`value` AS `default_billing`, `at_billing_postcode`.`value` AS `billing_postcode`, `at_billing_city`.`value` AS `billing_city`, `at_billing_telephone`.`value` AS `billing_telephone`, `at_billing_region`.`value` AS `billing_region`, `at_billing_country_id`.`value` AS `billing_country_id`, `at_group_id`.`value` AS `group_id` FROM `customer_entity` AS `e`
 LEFT JOIN `customer_entity_varchar` AS `at_prefix` ON (`at_prefix`.`entity_id` = `e`.`entity_id`) AND (`at_prefix`.`attribute_id` = '4')
 LEFT JOIN `customer_entity_varchar` AS `at_firstname` ON (`at_firstname`.`entity_id` = `e`.`entity_id`) AND (`at_firstname`.`attribute_id` = '5')
 LEFT JOIN `customer_entity_varchar` AS `at_middlename` ON (`at_middlename`.`entity_id` = `e`.`entity_id`) AND (`at_middlename`.`attribute_id` = '6')
 LEFT JOIN `customer_entity_varchar` AS `at_lastname` ON (`at_lastname`.`entity_id` = `e`.`entity_id`) AND (`at_lastname`.`attribute_id` = '7')
 LEFT JOIN `customer_entity_varchar` AS `at_suffix` ON (`at_suffix`.`entity_id` = `e`.`entity_id`) AND (`at_suffix`.`attribute_id` = '8')
 LEFT JOIN `customer_entity_int` AS `at_default_billing` ON (`at_default_billing`.`entity_id` = `e`.`entity_id`) AND (`at_default_billing`.`attribute_id` = '13')
 LEFT JOIN `customer_address_entity_varchar` AS `at_billing_postcode` ON (`at_billing_postcode`.`entity_id` = `at_default_billing`.`value`) AND (`at_billing_postcode`.`attribute_id` = '30')
 LEFT JOIN `customer_address_entity_varchar` AS `at_billing_city` ON (`at_billing_city`.`entity_id` = `at_default_billing`.`value`) AND (`at_billing_city`.`attribute_id` = '26')
 LEFT JOIN `customer_address_entity_varchar` AS `at_billing_telephone` ON (`at_billing_telephone`.`entity_id` = `at_default_billing`.`value`) AND (`at_billing_telephone`.`attribute_id` = '31')
 LEFT JOIN `customer_address_entity_varchar` AS `at_billing_region` ON (`at_billing_region`.`entity_id` = `at_default_billing`.`value`) AND (`at_billing_region`.`attribute_id` = '28')
 LEFT JOIN `customer_address_entity_varchar` AS `at_billing_country_id` ON (`at_billing_country_id`.`entity_id` = `at_default_billing`.`value`) AND (`at_billing_country_id`.`attribute_id` = '27')
 LEFT JOIN `customer_entity_varchar` AS `at_group_id` ON (`at_group_id`.`entity_id` = `e`.`entity_id`) AND (`at_group_id`.`attribute_id` = '10') WHERE (`e`.`entity_type_id` = '1') ORDER BY `group_id` ASC LIMIT 20

このクエリ phpmyadmin->SQL を実行すると、次のようなエラーが返されます。

#1052 - Column 'group_id' in order clause is ambiguous

どうすればこれを解決できますか?

管理パネルに問題がある場合は?

アップデート

これは私たちが追加した機能です

D:\wamp\www\mysite\app\code\core\Mage\Adminhtml\Block\Customer\Grid.php:

protected function _groupFilter($collection, $column){
        $this->getCollection()->getSelect()->where(new Zend_Db_Expr("{$this->getColumn()->getFilterIndex()} like '{$column->getFilter()->getValue()}'"));
        return $this;
    }

 protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('customer/customer_collection')
            ->addNameToSelect()
            ->addAttributeToSelect('email')
            ->addAttributeToSelect('created_at')
            ->addAttributeToSelect('group_id')
            ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
            ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
            ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
            ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
            ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');

        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

これは の列_prepareColumns()です。

 $this->addColumn('group', array(
            'header'    =>  Mage::helper('customer')->__('Group'),
            'width'     =>  '100',
            'index'     =>  'group_id',
            'type'      =>  'options',
            'filter_index' => 'e.group_id',
            'filter_condition_callback' => array($this, '_groupFilter'),
            'options'   =>  $groups,
        ));

次に、このエラーが発生しました:

致命的なエラー: の非オブジェクトに対するメンバー関数 getFilterIndex() の呼び出しD:\wamp\www\mysite\app\code\core\Mage\Adminhtml\Block\Customer\Grid.php on line 65

これはログ ファイルのエラーです:

2013-08-30T06:48:26+00:00 ERR (3): Warning: Missing argument 1 for Mage_Adminhtml_Block_Widget_Grid::getColumn(), called in D:\wamp\www\mysite\app\code\core\Mage\Adminhtml\Block\Customer\Grid.php on line 65 and defined  in D:\wamp\www\mysite\app\code\core\Mage\Adminhtml\Block\Widget\Grid.php on line 431
2013-08-30T06:48:26+00:00 ERR (3): Notice: Undefined variable: columnId  in D:\wamp\www\mysite\app\code\core\Mage\Adminhtml\Block\Widget\Grid.php on line 433
4

3 に答える 3

1

デフォルトのグリッド機能を変更したようです。右の SQl クエリは以下のとおりです。e`.`group_idの代わりにある必要がありgroup_idます。

これがあなたを助けることを願っています。

SELECT e.*, at_prefix.value AS prefix, at_firstname.value AS firstname, at_middlename.value AS middlename, at_lastname.value AS lastname, at_suffix.value AS suffix, CONCAT(IF(at_prefix.value IS NOT NULL AND at_prefix.value != '', CONCAT(LTRIM(RTRIM(at_prefix.value)), ' '), ''), LTRIM(RTRIM(at_firstname.value)), ' ', IF(at_middlename.value IS NOT NULL AND at_middlename.value != '', CONCAT(LTRIM(RTRIM(at_middlename.value)), ' '), ''), LTRIM(RTRIM(at_lastname.value)), IF(at_suffix.value IS NOT NULL AND at_suffix.value != '', CONCAT(' ', LTRIM(RTRIM(at_suffix.value))), '')) AS name, at_default_billing.value AS default_billing, at_billing_postcode.value AS billing_postcode, at_billing_city.value AS billing_city, at_billing_telephone.value AS billing_telephone, at_billing_region.value AS billing_region, at_billing_country_id.value AS billing_country_id, at_group_id.value AS group_id FROM customer_entity AS e LEFT JOIN customer_entity_varchar AS at_prefix ON (at_prefix.entity_id = e.entity_id) AND (at_prefix.attribute_id = '4') LEFT JOIN customer_entity_varchar AS at_firstname ON (at_firstname.entity_id = e.entity_id) AND (at_firstname.attribute_id = '5') LEFT JOIN customer_entity_varchar AS at_middlename ON (at_middlename.entity_id = e.entity_id) AND (at_middlename.attribute_id = '6') LEFT JOIN customer_entity_varchar AS at_lastname ON (at_lastname.entity_id = e.entity_id) AND (at_lastname.attribute_id = '7') LEFT JOIN customer_entity_varchar AS at_suffix ON (at_suffix.entity_id = e.entity_id) AND (at_suffix.attribute_id = '8') LEFT JOIN customer_entity_int AS at_default_billing ON (at_default_billing.entity_id = e.entity_id) AND (at_default_billing.attribute_id = '13') LEFT JOIN customer_address_entity_varchar AS at_billing_postcode ON (at_billing_postcode.entity_id = at_default_billing.value) AND (at_billing_postcode.attribute_id = '30') LEFT JOIN customer_address_entity_varchar AS at_billing_city ON (at_billing_city.entity_id = at_default_billing.value) AND (at_billing_city.attribute_id = '26') LEFT JOIN customer_address_entity_varchar AS at_billing_telephone ON (at_billing_telephone.entity_id = at_default_billing.value) AND (at_billing_telephone.attribute_id = '31') LEFT JOIN customer_address_entity_varchar AS at_billing_region ON (at_billing_region.entity_id = at_default_billing.value) AND (at_billing_region.attribute_id = '28') LEFT JOIN customer_address_entity_varchar AS at_billing_country_id ON (at_billing_country_id.entity_id = at_default_billing.value) AND (at_billing_country_id.attribute_id = '27') LEFT JOIN customer_entity_varchar AS at_group_id ON (at_group_id.entity_id = e.entity_id) AND (at_group_id.attribute_id = '10') WHERE (e.entity_type_id = '1') ORDER BY e.group_id ASC LIMIT 20

于 2013-08-26T13:15:06.970 に答える
0

列に次を追加する必要があります。

$this->addColumn(
   'filter_index' =>'e.group'
)

フィルタリングするために、それでもうまくいかない場合は、これを列に追加してみてください。

$this->addColumn(...
    'filter_condition_callback' => array($this, '_groupFilter'),
     ...
)  

そして、グリッド クラスに関数を追加します。

private function _groupFilter($collection, $column){
    $this->getCollection->getSelect()->where(new Zend_Db_Expr("{$this->getColumn()->getFilterIndex()} like '{$column->getFilter()->getValue())}'"));
    return $this;
}
于 2013-08-26T20:11:13.330 に答える
0

この関数を使用する場合は、この関数$this->getColumn()に機能パラメータを追加する必要がありますcolumnId。ということで、実際の機能はこんな感じで、

public function getColumn($columnId)
{
    if (!empty($this->_columns[$columnId])) {
        return $this->_columns[$columnId];
    }
    return false;
}

getFilterIndex()も同じ。コラムを知らずに指摘することはできません。このように見えます$column->getFilterIndex()

SQL 構文エラーの場合は、最初に order 句を削除してください。その後、もう一度テストします。エラーをお知らせください。

このスニペットがお役に立てば幸いです。

于 2013-08-30T09:14:19.083 に答える