2014-04-03 45 views
0

我正在使用Magento 1.7 - 我是Magento模塊開發的新手。如何在Magento後臺顯示自定義訂單屬性

我已經創建了一個新的訂單自定義EAV屬性,稱爲Deliverydate,客戶將在購物車頁面上輸入該訂單。我創建了一個自定義模塊和安裝程序腳本,並可以在eav_attribute表中看到它。

$installer = $this; 
$installer->startSetup(); 
$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 

$setup->addAttribute('order', 'deliverydate', array(
'position'  => 1, 
'input'   => 'text', 
'backend_type' => 'varchar', 
'type'   => 'varchar', 
'label'   => 'Choose delivery date', 
'visible'  => 1, 
'required'  => 0, 
'user_defined' => 1, 
'global'  => 1, 
'visible_on_front' => 1, 
)); 

$installer->endSetup(); 

但我讀過許多來源,不能弄清楚如何 1)除由客戶輸入的值。 2)檢索Admin中顯示的值。

我已閱讀這些教程關於觀察員,但似乎無法得到一個工作:

這是我的config.xml文件

<?xml version="1.0"?> 
<config> 
    <modules> 
    <Mycompany_Deliverydate> 
     <version>0.1.0</version> 
    </Mycompany_Deliverydate> 
    </modules> 
    <global> 
<resources> 
    <deliverydate_setup> 
    <setup> 
     <module>Mycompany_Deliverydate</module> 
     <class>Mycompany_Deliverydate_Model_Resource_Mysql4_Setup</class> 
    </setup> 
    <connection> 
     <use>core_setup</use> 
     </connection> 
     </deliverydate_setup> 
    </resources> 
    <events> 
    <checkout_type_onepage_save_order> 
     <observers> 
      <Deliverydate_observer> 
       <type>singleton</type> 
       <class>deliverydate/observer</class> 
       <method>Deliverydate</method> 
      </Deliverydate_observer> 
     </observers> 
    </checkout_type_onepage_save_order> 
    </events> 
    </global> 
</config> 

而且我Observer.php文件,其中大部分我從本網站的另一篇教程/問題中借用。

class Mycompany_Deliverydate_Model_Observer { 
    public function Deliverydate($observer) { 

    $event = $observer->getEvent(); 
    $order = $event->getOrder(); 

    $order->setDeliverydate(Mage::app()->getRequest()->getPost('delivery_date')); 


    } 
} 

我不認爲這是正在進入在所有 - 我把一個throw new Exception並通過整個訂單去沒有看到過例外。在任何情況下,我都不確定我正在檢查正確的事件 - checkout_type_onepage_save_order - 何時會被解僱?我不知道setDeliverydate()函數將在哪裏定義,但正如我所說,這種類型來自另一個來源,它也沒有在那裏定義。

輸入值存儲在哪裏?

+1

有你有在觀察者deliverydate屬性值方法? – DRAJI

回答

1

請檢查下面的帖子,它會幫助你。如果不從這個問題提升你,請順序是由客戶放置後在這裏評論

http://chillydraji.wordpress.com/2014/03/03/how-to-create-new-attribute-to-order-in-magento/

+0

嗨,感謝您的信息。它引導了我大部分的方式,但我仍然無法讓觀察者工作,所以我最終不得不將'$ quote-> setDeliveryDate($ delivery_date);'放入OnePageController.php中(這是一個自定義檢出模塊 - 也許這就是爲什麼我的觀察員不工作) – colmde

+0

是不是你的觀察者方法工作? – DRAJI

+0

我們只能使用一個自定義觀察者方法來定製屬性 – DRAJI

0

,自定義字段需要在我的帳戶中。所以要在模塊前端佈局文件中執行此操作,在此例中爲custom.xml

<?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> 

這裏我們基本上參考了my.account.wrapper塊並添加了一個子塊。我們的塊類型是custom/order_view,模板文件是custom/order.phtml

因此,我們需要建立我們的塊級

<?php 

class Excellence_Custom_Block_Custom_Order extends Mage_Core_Block_Template{ 

public function getCustomVars(){ 

$model = Mage::getModel('custom/custom_order'); 

return $model->getByOrder($this->getOrder()->getId()); 

} 

public function getOrder() 

{ 

return Mage::registry('current_order'); 

} 

} 

和我們order.phtml文件

<div class="col-set order-info-box"> 

<div class="col"> 

<div class="box"> 

<div class="box-title"> 

<h2><?php echo $this->__('Custom Fields') ?></h2> 

</div> 

<div class="box-content"> 



<?php 

$custom = $this->getCustomVars(); 

foreach($custom as $key => $value){ 

?> 

<b><?php echo $this->__($key);?></b> : <?php echo $value;?> <br/> 

<?php } ?> 


</div> 

</div> 

</div> 

</div> 

僅供參考,請訪問:http://www.demagento.com/tutorial-magento-add-custom-field-to-order-checkout-page/

相關問題