2011-12-08 29 views
7

Tôi đang phát triển một trang web với magento ver-1.6. Tôi cố gắng tạo ra các lĩnh vực mới để đăng ký khách hàng, nhưng nó không được tạo ra. Tôi theo cùng cách mà chúng ta đã làm theo trong ver-1.5.Cách tạo trường mới cho khách hàng

Bất kỳ biến thể nào trong tạo trường khách hàng trong 1.6?

Trả lời

22

Tôi không biết những gì bạn đã thử vì vậy tôi sẽ chỉ liệt kê tất cả các bước cần thiết để thêm thuộc tính khách hàng schooL mới vào biểu mẫu đăng ký Magento 1.6.1.

  1. Tạo mô-đun tốt nhất hoặc đặt mã tương tự vào tệp này trong một số tệp .phtml và chạy nó một lần. Nếu bạn đang làm đúng đắn này và tạo ra một mô-đun, đặt mã như thế này vào file mysql_install:

    <?php 
    $installer = $this; 
    $installer->startSetup(); 
    $setup = Mage::getModel('customer/entity_setup', 'core_setup'); 
    $setup->addAttribute('customer', 'school', array(
        'type' => 'int', 
        'input' => 'select', 
        'label' => 'School', 
        'global' => 1, 
        'visible' => 1, 
        'required' => 0, 
        'user_defined' => 1, 
        'default' => '0', 
        'visible_on_front' => 1, 
         'source'=> 'profile/entity_school', 
    )); 
    if (version_compare(Mage::getVersion(), '1.6.0', '<=')) 
    { 
         $customer = Mage::getModel('customer/customer'); 
         $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId(); 
         $setup->addAttributeToSet('customer', $attrSetId, 'General', 'school'); 
    } 
    if (version_compare(Mage::getVersion(), '1.4.2', '>=')) 
    { 
        Mage::getSingleton('eav/config') 
        ->getAttribute('customer', 'school') 
        ->setData('used_in_forms', array('adminhtml_customer','customer_account_create','customer_account_edit','checkout_register')) 
        ->save(); 
    } 
    $installer->endSetup(); 
    ?> 
    
  2. Trong file config.xml mô-đun của bạn. Lưu ý rằng tên của mô-đun của tôi là Excellence_Profile.

    <profile_setup> <!-- Replace with your module name --> 
    <setup> 
        <module>Excellence_Profile</module> <!-- Replace with your module name --> 
        <class>Mage_Customer_Model_Entity_Setup</class> 
    </setup> 
    </profile_setup> 
    
  3. Ở đây chúng tôi sẽ thêm thuộc tính của chúng tôi, vào biểu mẫu đăng ký khách hàng. Trong phiên bản 1.6.0 (+), tệp phtml được sử dụng là persistance/customer/register.phtml và trong phiên bản 1.6.0 (-) tệp phtml được sử dụng là customer/form/register.phtml Vì vậy, chúng tôi cần mở tệp phtml, dựa trên phiên bản magento và thêm mã này vào thẻ .

    <li> 
    <?php 
    $attribute = Mage::getModel('eav/config')->getAttribute('customer','school'); 
    ?> 
    <label for="school" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label> 
    <div class="input-box"> 
    <select name="school" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>"> 
    <?php 
    $options = $attribute->getSource()->getAllOptions(); 
    foreach($options as $option){ 
    ?> 
    <option value='<?php echo $option['value']?>' <?php if($this->getFormData()->getSchool() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option> 
    <?php } ?> 
    </select> 
    </div> 
    </li> 
    
  4. Đối với Magento 1.4.2 (+) là tất cả những gì cần thiết cho bước đăng ký. Nếu bạn tạo người dùng từ đây, bạn sẽ thấy trường văn bản trường học trong quản trị viên. Đối với Magento 1.4.1 (-), chúng ta cần phải làm điều khác mở file module của bạn config.xml và thêm:

    <global> 
         <fieldsets> 
          <customer_account> 
           <school><create>1</create><update>1</update><name>1</name></school> 
          </customer_account> 
         </fieldsets> 
    </global> 
    
  5. Một lần, người dùng đã tạo tài khoản của mình trong MyAccount-> phần Thông tin tài khoản anh ta cũng có thể chỉnh sửa trường học. Đối với điều này mở file phtml customer/form/edit.phtml và đưa vào mã kiểm tra vào:

    <?php 
    <li> 
    <?php 
    $attribute = Mage::getModel('eav/config')->getAttribute('customer','school'); 
    ?> 
    <label for="is_active" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label> 
    <div class="input-box"> 
    <select name="school" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>"> 
    <?php 
    $options = $attribute->getSource()->getAllOptions(); 
    foreach($options as $option){ 
    ?> 
    <option value='<?php echo $option['value']?>' <?php if($this->getCustomer()->getSchool() == $option['value']){ echo 'selected="selected"';}?>><?php echo $this->__($option['label'])?></option> 
    <?php } ?> 
    </select> 
    </div> 
    </li> 
    
  6. Một hình thức đăng ký cũng xuất hiện tại trang thanh toán trong Magento. Để thêm bạn lĩnh vực ở đây, bạn cần phải chỉnh sửa checkout/onepage/billing.phtml cho phiên bản Magento 1.6 (-) và persistant/checkout/onepage/billing.phtml cho phiên bản Magento 1.6 (+) tập tin và sau đó tìm thấy mã:

    <?php if(!$this->isCustomerLoggedIn()): ?> 
    

    bên này nếu tình trạng thêm lĩnh vực của bạn

    <li> 
    <li> 
    <?php 
    $attribute = Mage::getModel('eav/config')->getAttribute('customer','school'); 
    ?> 
    <label for="school" class="<?php if($attribute->getIsRequired() == true){?>required<?php } ?>"><?php if($attribute->getIsRequired() == true){?><em>*</em><?php } ?><?php echo $this->__('School') ?></label> 
    <div class="input-box"> 
    <select name="billing[school]" id="school" class="<?php if($attribute->getIsRequired() == true){?>required-entry<?php } ?>"> 
    <?php 
    $options = $attribute->getSource()->getAllOptions(); 
    foreach($options as $option){ 
    ?> 
    <option value='<?php echo $option['value']?>'><?php echo $this->__($option['label'])?></option> 
    <?php } ?> 
    </select> 
    </div> 
    </li> 
    

    Tiếp theo mở config.xml module của bạn hoặc bất kỳ file config.xml khác, thêm những dòng sau đây:

    <global> 
        <fieldsets> 
         <checkout_onepage_quote> 
         <customer_school> 
          <to_customer>school</to_customer> 
         </customer_school> 
         </checkout_onepage_quote> 
         <customer_account> 
          <school> 
           <to_quote>customer_school</to_quote> 
          </school> 
         </customer_account> 
         </fieldsets> 
        </global> 
    
  7. Tiếp theo chúng ta cần phải thực hiện một số thay đổi trong bảng báo giá tức là bảng sales_flat_quote trong Magento. Nếu bạn có một mô-đun sau đó tạo ra một phiên bản nâng cấp của file sql của bạn và đưa vào đoạn mã này:

    $tablequote = $this->getTable('sales/quote'); 
    $installer->run(" 
    ALTER TABLE $tablequote ADD `customer_school` INT NOT NULL 
    "); 
    

Sau khi làm điều này đảm bảo xóa bạn nhớ cache Magento, đặc biệt là “Flush Magento Cache” và “Flush Bộ nhớ Cache ". Bây giờ khi bạn đặt hàng, khách hàng được tạo với thuộc tính trường học chính xác.

+0

lớn thứ Cảm ơn! Đối với 'source' => 'profile/entity_school', chúng ta cần tạo ra một mô hình cụ thể cho cái đó, tôi không cần nó, nhưng đối với những người khác thì sẽ rất tuyệt khi đưa ra một ví dụ về điều đó. – Shadowbob

0

Tôi gặp sự cố khi lưu các trường mới trong biểu mẫu checkout_register.

tôi phải mở rộng toàn cầu diễn> fieldsets nút:

<global> 
    <fieldsets> 
     <checkout_onepage_quote> 
      <customer_school> 
       <to_customer>school</to_customer> 
      </customer_school> 
     </checkout_onepage_quote> 

     <checkout_onepage_billing> 
      <school> 
       <to_customer>*</to_customer> 
      </school> 
     </checkout_onepage_billing> 

     <customer_account> 
      <school> 
       <to_quote>customer_school</to_quote> 
      </school> 
     </customer_account> 

     <sales_convert_order> 
      <customer_school> 
       <to_quote>*</to_quote> 
      </customer_school> 
     </sales_convert_order> 
    </fieldsets> 
</global> 
Các vấn đề liên quan