2012-10-17 56 views
9

Tôi muốn thêm thuộc tính vào đơn hàng sẽ không hiển thị với khách hàng. Tôi chỉ muốn sử dụng nó trong cơ sở dữ liệu và lưu trữ một giá trị cụ thể cho mỗi đơn đặt hàng. Tôi muốn in thứ tự theo giá trị này. Vậy làm thế nào tôi có thể thêm một thuộc tính thứ tự trong Magento. Thuộc tính cũng giống như trạng thái của đơn đặt hàng. Hơn nữa nếu tôi muốn hiển thị thuộc tính đó trong admin/sales/orders làm thế nào tôi có thể làm điều đó?Thêm thuộc tính mới vào đơn đặt hàng trong Magento

+0

@MJG: Đã giải quyết được sự cố của bạn chưa? – Rathinam

Trả lời

16

Giả sử bạn muốn thêm my_custom_input_field vào đơn đặt hàng của bạn và thêm trường vào trang quản trị tạo trang đặt hàng (để thêm trường vào giao diện người dùng, bạn chỉ cần thêm trường nhập vào mẫu phía trước và kiểm tra kỹ người quan sát)

Trong /app/code/local/MageIgniter/CustomOrderStatus/etc/config.xml

<?xml version="1.0"?> 
<config> 
    <modules> 
     <MageIgniter_CustomOrderStatus> 
      <version>1.1</version> 
     </MageIgniter_CustomOrderStatus> 
    </modules> 

    <global> 
     <fieldsets> 
      <sales_convert_quote>       
       <my_custom_input_field><to_order>*</to_order></my_custom_input_field> 
      </sales_convert_quote> 

      <sales_convert_order>            
       <my_custom_input_field><to_quote>*</to_quote></my_custom_input_field> 
      </sales_convert_order> 
     </fieldsets> 
     <helpers> 
      <customorderstatus> 
       <class>MageIgniter_CustomOrderStatus_Helper</class> 
      </customorderstatus>    
     </helpers> 

     <models> 
      <customorderstatus> 
       <class>MageIgniter_CustomOrderStatus_Model</class> 
       <resourceModel>customorderstatus_mysql4</resourceModel> 
      </customorderstatus> 
     </models> 
     <resources> 
      <customorderstatus_setup> 
       <setup> 
        <module>MageIgniter_CustomOrderStatus</module> 
        <class>Mage_Sales_Model_Mysql4_Setup</class> 
       </setup> 
       <connection> 
        <use>core_setup</use> 
       </connection> 
      </customorderstatus_setup> 
      <customorderstatus_write> 
       <connection> 
        <use>core_write</use> 
       </connection> 
      </customorderstatus_write> 
      <customorderstatus_read> 
       <connection> 
        <use>core_read</use> 
       </connection> 
      </customorderstatus_read> 
     </resources> 

     <events> 
      <adminhtml_sales_order_create_process_data_before> 
       <observers> 
        <customorderstatus> 
         <type>singleton</type> 
         <class>customorderstatus/observer</class> 
         <method>saveCustomData</method> 
        </customorderstatus> 
       </observers> 
      </adminhtml_sales_order_create_process_data_before> 
     </events> 

     <blocks> 
      <customorderstatus> 
       <class>MageIgniter_CustomOrderStatus_Block</class> 
      </customorderstatus> 
     </blocks> 
    </global> 
</config> 

Trong /app/code/local/MageIgniter/CustomOrderStatus/sql/customorderstatus_setup/mysql4-install-1.1. php

<?php 
$installer = $this; 
$installer->startSetup(); 

$installer->addAttribute("order", "my_custom_input_field", array("type"=>"varchar")); 
$installer->addAttribute("quote", "my_custom_input_field", array("type"=>"varchar")); 
$installer->endSetup(); 

Trong /app/code/local/MageIgniter/CustomOrderStatus/Model/Observer.php

class MageIgniter_CustomOrderStatus_Model_Observer 
{ 
    public function saveCustomData($event) 
    { 
     $quote = $event->getSession()->getQuote(); 
     $quote->setData('my_custom_input_field', $event->getRequestModel()->getPost('my_custom_input_field')); 

     return $this; 
    } 
} 

(Bạn nên tránh thay đổi mặc định cốt lõi - bạn nên làm một số nghiên cứu về khoảng cách này)

Trong /app/design/adminhtml/default/default/template/sales/order/view/info.phtml

<?php if($_order->getMyCustomInputField()): ?> 
<tr> 
    <td class="label"><label><?php echo Mage::helper('sales')->__('My Custom Input Field') ?></label></td> 
    <td class="value"><strong><?php echo $_order->getMyCustomInputField() ?></strong></td> 
</tr> 
<?php endif; ?> 

Trong/app/thiết kế/adminhtml/default/default/template/bán hàng/theo thứ tự/tạo /form/account.phtml

(để thêm vào frontend thay đổi value="<?php echo Mage...>")

<input id="my_custom_input_field" name="my_custom_input_field" value="<?php echo Mage::getSingleton('adminhtml/session_quote')->getQuote()->getMyCustomInputField() ?>" class="input-text" type="text"> 
+1

Cảm ơn bạn đã chia sẻ mã. Tôi muốn đề cập đến một phần mở rộng ở đây cho những người ít kỹ thuật để thêm các lĩnh vực thanh toán thêm với nhấp chuột duy nhất từ ​​văn phòng trở lại. http://www.fmeextensions.com/magento-additional-checkout-attributes-fields.html –

+0

Làm cách nào để bạn thêm/ghi vào cột tùy chỉnh vào bảng sales_flat_order_grid? – user2963379

+0

@ user2963379 ... Magento sẽ tự động cập nhật nếu bạn cập nhật cột có cùng tên trong sales_flat_order –

0

Thêm thuộc tính tuỳ chỉnh để đặt hàng bao gồm nhiều bước. Trước tiên, bạn cần thêm trường văn bản vào tệp billing.phtml. Sau đó, bạn phải thêm trường đó vào các bảng Trích dẫn và Đặt hàng và tạo các lớp Observer. Một vài tệp khác như custom.xm l và order.phtml cần được chỉnh sửa để hiển thị thuộc tính đó.

Để biết hướng dẫn đầy đủ, hãy xem

Các vấn đề liên quan