2013-07-11 23 views
16

注文にカスタムフィールドを追加しようとしています。この時点で、私は私のデータベースにそのような属性を作成するために私を助けたポスト怒鳴るが見つかりました:上記のコードを実行すると、いくつかの注文を作成した後 http://fabrizioballiano.net/2011/11/15/create-a-custom-order-attribute-in-magento/Magento - 注文にカスタム属性を追加

require_once('app/Mage.php'); 
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID)); 

$installer = new Mage_Sales_Model_Mysql4_Setup; 
$attribute = array(
    'type'   => 'int', 
    'backend_type' => 'text', 
    'frontend_input' => 'text', 
    'is_user_defined' => true, 
    'label'   => 'My Label', 
    'visible'  => true, 
    'required'  => false, 
    'user_defined' => true, 
    'searchable' => true, 
    'filterable' => true, 
    'comparable' => true, 
    'default'  => 0 
); 
$installer->addAttribute('order', 'special_attribute', $attribute); 
$installer->endSetup(); 

を、私はすべての注文をループすることが可能だと見すべての注文のデフォルト値。

問題は、このフィールドに必要なデータを保存するにはどうすればいいですか?どのようにしてそのようなデータを取得できますか?

ありがとうございます!

答えて

27

これをconfig.xmlのgobalスコープに追加します。その後、見積もりに属性を設定するだけで、自動的に見積り→注文変換プロセスのオーダーに転送されます。

<global> 
... 
    <fieldsets> 
     <sales_convert_quote> 
      <your_special_attribute> 
       <to_order>*</to_order> 
      </your_special_attribute> 
     </sales_convert_quote> 
    </fieldsets> 
... 
</global> 

属性は、魔法のゲッター/セッターなどでいつでも取得/設定できます。あなたはbilling.phtmlファイルにテキストフィールドを追加し、見積もりと注文表にフィールドを保存した後

$quote->getYourSpecialAttribute() 
$order->getYourSpecialAttribute() 

$quote->setYourSpecialAttribute() 
+1

を参照してください!ありがとう男:) – MatheusJardimB

+2

私の問題は今です:私はあなたのXML行を追加したか、または私も貢献したためにのみ働いたのですか? – MatheusJardimB

+4

もちろん、インストーラスクリプトを使って属性を追加しました。私があなたに与えたxml行は、変換を注文するために見積もりを通じて自動的に属性をプッシュします。引用符もdbに保存されているので、属性も引用符で作成する必要があります!受注見積dbテーブルを確認するだけです。 –

0

、あなたは属性を表示することができます。 [マイアカウント] - > [オーダーの表示]にフィールドを表示することができます。 custom.xml fieに次の変更を加えます。より多くの場合

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <sales_order_view> 
     <reference name="my.account.wrapper"> 
      <block type="custom/custom_order" name="custom.order" template="custom/order.phtml" after='sales.order.info' /> 
     </reference> 
    </sales_order_view> 
</layout> 

、それが働いたブログHow to add custom attribute to order in Magento

関連する問題