customer_entity_varcharテーブルにsales_flat_order_gridテーブルに参加するのに問題がある

magento.stackexchange https://magento.stackexchange.com//questions/63345

  •  12-12-2019
  •  | 
  •  

質問

クライアントは、customer_entity_varcharテーブルからの特定のデータを受注グリッド内の顧客の姓の代わりに表示します。customer_entity_varcharテーブルをsales_flat_order_gridテーブルに参加しようとしていますが、問題に遭遇しました。sales_flat_order_paymentテーブルにsales_flat_order_gridテーブルに正常に参加して、グリッド内のPO番号を表示できました。おそらく表の類似性のために。これが最初にMage_Adminhtml_Block_Sales_Order_Gridクラスから試行されました。そして、はい、私はコアファイルを変更しないことを知っています。コードがフレームワークを拡張する前にコードが正しいことを確認したいだけです。:)

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $resource = Mage::getSingleton('core/resource');
    $collection->getSelect()->join('customer_entity_varchar', 'main_table.customer_id = customer_entity_varchar.entity_id', array('value'));
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
.

役に立ちましたか?

解決

属性code of PO Number is po_numberを仮定します

を使用して属性の詳細を取得する必要があります。
Mage::getResourceModel('customer/customer') Model by attribute code .
.

属性コードがstore_stateの場合は、下記のコードを使用して属性テーブル名と属性を取得できます。

$po_number  = Mage::getResourceModel('customer/customer')->getAttribute('po_number');
$tablename=$po_number->getBackend()->getTable();
.

$ table staticで撮影されています。

$attributeId=$po_number>getAttributeId() 
.

customer_entity_varcharテーブルには、lots of recordsを搭載したdifferent attribute so you need to put attribute id in join query conditionがあります。

$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection>getSelect()->joinLeft(
    array('ccp' =>$po_number->getBackend()->getTable()),
    'ccp.entity_id = main_table.customer_id
    AND ccp.attribute_id = '.(int) $po_number->getAttributeId() . '
    ',
    array('$po_number-'=>'value')); 
.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top