2011-06-26 5 views
5

Ivanのチュートリアル(Adding order attribute to the orders grid in Magento 1.4.1)を使用して、sales_order_gridテーブル(Shipping Descriptionテキスト)に余分な列を追加しています。これは、古いデータをsales_flat_orderからsales_order_gridの新しい列に渡すことを除いて動作します。Magentoでは、sales_order_gridの新しい列にsales_flat_orderのデータを入力するにはどうすればよいですか?

私のSQLインストールスクリプトでは列が正しく追加されています。私はsales_flat_orderと同じフィールド名を使用しているため、オブザーバが必要ではないと思いますが、既存の出荷説明データをすべてshipping_descriptionフィールドが実行されていません。

私は間違っていますか?

マイSQLスクリプトをインストールします。私は、Magentoの1.5.1 Community Editionを使用しています

<?php 
/** 
* Setup scripts, add new column and fulfills 
* its values to existing rows 
* 
*/ 
/* @var $this Mage_Sales_Model_Mysql4_Setup */ 
$this->startSetup(); 

// Add column to grid table 
$this->getConnection()->addColumn(
    $this->getTable('sales/order_grid'), 
    'shipping_description', 
    "varchar(255) not null default ''" 
); 

// Add key to table for this field, 
// it will improve the speed of searching & sorting by the field 
$this->getConnection()->addKey(
    $this->getTable('sales/order_grid'), 
    'shipping_description', 
    'shipping_description' 
); 


// fill existing rows with data 
$select = $this->getConnection()->select(); 
$select->join(
    array('order'=>$this->getTable('sales/order')), 
    $this->getConnection()->quoteInto('order.entity_id = order_grid.entity_id',''), 
    array('shipping_description' => 'shipping_description') 
); 

$this->getConnection()->query(
    $select->crossUpdateFromSelect(
     array('order_grid' => $this->getTable('sales/order_grid')) 
    ) 
); 

$this->endSetup(); 

を!

ありがとうございました!これは動作するはずです

答えて

4

$select = $this->getConnection()->select(); 
$select->join(
    array('order_shipping'=>$this->getTable('sales/order')),//alias=>table_name 
    $this->getConnection()->quoteInto(
     'order_shipping.entity_id = order_grid.entity_id', 
     Mage_Sales_Model_Quote_Address::TYPE_SHIPPING 
    ),//join clause 
    array('shipping_description' => 'shipping_description')//fields to get 
); 
$this->getConnection()->query(
    $select->crossUpdateFromSelect(
     array('order_grid' => $this->getTable('sales/order_grid')) 
    ) 
); 

をしたい場合は、私のextensionを見てみましょう:)
HTH

+0

パーフェクト!私は自分のエクステンションを見ていましたが、私が一緒にいて、イワンのポストとあなたのエクステンションとの間に私はとても近づきました。ちょうど間違ってデータを入力しました:-)私はあなたのスーパーシンプルバージョンをあとでオープンします。ありがとう!値 //ワークアウト ます$ this-> AddColumn関数(「倉庫」、配列との倉庫( : – simonyoung

+0

は実際に私がsales_flat_orderとsales_flat_order_gridテーブル の列名の倉庫を作成し、属性を作成し 販売注文グリッド内の1つのフィールドの倉庫が必要'header' => Mage :: helper( 'sales') - > __( 'Warehouse')、 'index' => '倉庫'、 'type' => 'options'、 'width' => (Maven :: getSingleton( 'eav/config') - > getAttribute( 'catalog_product'、 'warehouse')); )); まだ動作していません。従う必要がある手順はありますか? – Rathinam

+0

https://i.snag.gy/H0Sqrh.jpg – Rathinam

関連する問題