2012-03-24 8 views
0

私は既にこれを一日中使い続けています。オーダーにカスタムEAVアトリビュートを追加する可能性がなくなったため、これを実行できません。 少なくとも、私はsales_order_entityが見つからないことに気付きました。Magento 1.6.2.0 Sales Ordersカスタムアトリビュートが動作しない

私がしようとしているのは、受注にカスタムフィールドを追加することです。カテゴリ製品と同じように動作すると思っていましたが、nopeのように見えます。 私が全体的に言っていることは、誰がカタログに商品を追加しているのかを追跡し、特定の注文を特定のユーザ(顧客ではない)と関連させたいからです。

public function getDefaultEntities() 
{ 
    return array(
     'catalog_product' => array(
      'entity_model'  => 'catalog/product', 
      'attribute_model' => 'catalog/resource_eav_attribute', 
      'table'    => 'catalog/product', 
      'additional_attribute_table' => 'catalog/eav_attribute', 
      'entity_attribute_collection' => 'catalog/product_attribute_collection', 
      'attributes'  => array(
       'seller_id' => array(
        'group'    => 'MyCustom', 
        'label'    => 'Seller ID', 
        'type'    => 'int', 
        'input'    => 'text', 
        'default'   => '0', 
        'class'    => '', 
        'backend'   => '', 
        'frontend'   => '', 
        'source'   => '', 
        'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 
        'visible'   => false, 
        'required'   => true, 
        'user_defined'  => true, 
        'searchable'  => true, 
        'filterable'  => true, 
        'comparable'  => false, 
        'visible_on_front' => false, 
        'visible_in_advanced_search' => false, 
        'unique'   => false, 
       ), 
      ), 
     ), 
     'order' => array(
      'entity_model'  => 'sales/order', 
      'table'    => 'sales/order', 
      'increment_model' => 'eav/entity_increment_numeric', 
      'attributes'  => array(
       'seller_id' => array(
        'group'    => 'MyCustom', 
        'label'    => 'Seller ID', 
        'type'    => 'int', 
        'input'    => 'text', 
        'default'   => '0', 
        'class'    => '', 
        'backend'   => '', 
        'frontend'   => '', 
        'source'   => '', 
        'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 
        'visible'   => false, 
        'required'   => true, 
        'user_defined'  => true, 
        'searchable'  => true, 
        'filterable'  => true, 
        'comparable'  => false, 
        'visible_on_front' => false, 
        'visible_in_advanced_search' => false, 
        'unique'   => false, 
       ), 
      ), 
     ), 
    ); 
} 

これは製品には適用されますが、注文には適用されません。私はeav_attributeテーブルにエントリが必要です。 私は何か間違っているのか、これはただ不可能なのか分かりませんか? 私はまた、ユーザーオーダーの製品間の関係を追跡するために追加のテーブルを作成することによって、この異なる方法を解決することを考えました。これにより、より厳しい作業が必要になります。

アイデア?おかげさまで

答えて

3

私はこれが古い投稿だと知っていますが、私は同じ問題の答えを探していたときにそれを見つけたので、私の解決策を共有すると思いました。

例として、受注に属性を追加することができます。あなたは、コア/メイジ/販売を見れば

まず、Magentoのはもはやユーザーは、販売のためのエンティティをEAVの/ etc/config.xmlにsales_entity(EAV)、それ今の点で

<sales> 
     <class>Mage_Sales_Model</class> 
     <resourceModel>sales_resource</resourceModel> 
</sales> 

resouceModelもはやポイントsales_resource(フラット)。あなたはsales_resourceノードの子を見れば、あなたは注文のノードを見つける:

<order> 
     <table>sales_flat_order</table> 
</order> 

これはMage_Sales_Model_Orderはsales_flat_orderのテーブルを持っているMage_Sales_Model_Resource_Orderのリソースモデルを有することを意味します。

Magentoの開発者は、あなたがEAV構造に属性を追加しているだろうほとんど同じ方法で、この新しい「フラット」構造に属性を追加することができますクラスMage_Sales_Model_Resource_Setupを提供してきました。あなたは今、それは単にMage_Sales_Model_Resource_Setupのインスタンスを取得し、有効なパラメータとそのパブリックaddAttributeメソッドを呼び出した場合であることを確認する必要があり、この情報を使用して

/** 
* Add entity attribute. Overwrited for flat entities support 
* 
* @param int|string $entityTypeId 
* @param string $code 
* @param array $attr 
* @return Mage_Sales_Model_Resource_Setup 
*/ 
public function addAttribute($entityTypeId, $code, array $attr) 
{ 

    if (isset($this->_flatEntityTables[$entityTypeId]) && 
     $this->_flatTableExist($this->_flatEntityTables[$entityTypeId])) 
    { 
     $this->_addFlatAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr); 
     $this->_addGridAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr, $entityTypeId); 
    } else { 
     parent::addAttribute($entityTypeId, $code, $attr); 
    } 
    return $this; 
} 

:あなたはMage_Sales_Model_Resource_Setup内で見てみる場合は、以下の機能が表示されます。

受注にfranchise_id属性を追加するコードスニペット:>あなたはsales_flat_orderテーブルの列を作成する必要があります1.4.1.0のバージョンの

$salesResourceSetupModel = Mage::getModel('sales/resource_setup', 'core_setup'); 

$data=array(
    'type'=>'int', 
    'input'=>'text', 
    'label'=>'Franchise', 
    'global'=> 1, 
    'is_required'=>'0', 
    'is_comparable'=>'0', 
    'is_searchable'=>'0', 
    'is_unique'=>'0', 
    'is_configurable'=>'0', 
    'user_defined'=>'1', 
    //whether it should be including in the sales order grid 
    'grid'=>1 
); 

//first param should relate to a key of the protected $_flatEntityTables array 
$salesResourceSetupModel->addAttribute('order', 'franchise_id', $data); 
+0

ありがとう、本当に! – Ivo

関連する問題