2013-03-20 63 views
0

我在發貨方式的模板文件中添加了一個下拉框。現在我想讓它成爲必需的領域。我嘗試了很多方法。但沒有奏效。任何幫助將不勝感激。Magento如何將一個必填字段添加到發運方法?

以下是模板文件。

<?php 
    $_code=$this->getMethodCode(); 
    $carrier = $this->getMethodInstance(); 
    $pickupData = $this->getQuote()->getPickupData(); 
    $_rate = $this->getRate(); 
    if(!isset($pickupData['store'])) 
    { 
     $pickupData['store'] = -1; 
    } 
    if(!isset($pickupData['name'])) 
    { 
     $pickupData['name'] = ''; 
    } 
?> 
<ul class="form-list" id="shipping_form_<?php echo $_rate->getCode() ?>" style="display:none;"> 
    <li> 
     <label for="shipping_pickup[store]" class="required"><em>*</em><?php echo $this->__('Choose Store Location:') ?></label> 
     <span class="input-box" style="float:left ;"> 
      <select class="required-entry" name="shipping_pickup[store]" id="shipping_pickup[store]"> 
       <option value='0'><?php echo $this->__('Select Store..');?></option> 
       <?php 
        $collection = $this->getAllLocations(); 
        foreach($collection as $coll) 
        { 
         $data = $coll->getData(); 
         ?> 
         <option value='<?php echo $data['location_id']; ?>'><?php echo $this->__($data['location_name']);?></option> 
         <?php 
        } 
        ?> 
      </select> 
     </span> 
    </li> 
</ul> 

回答

0

在opcheckout.js編輯線663至763。

validate: function() { 
     var methods = document.getElementsByName('shipping_method'); 

     if (methods.length==0) { 
      alert(Translator.translate('Your order cannot be completed at this time as there is no shipping methods available for it. Please make necessary changes in your shipping address.').stripTags()); 
      return false; 
     } 

     if(!this.validator.validate()) { 
      return false; 
     } 

     for (var i=0; i<methods.length; i++) { 
      if (methods[i].checked) { 

       var methodName = methods[i].value; 
       if(methodName == 'pickup_pickup') 
        { 
       var locationOpt = document.getElementById('shipping_pickup[store]'); 
       var selectedOpt = locationOpt.options[locationOpt.selectedIndex].text; 

       if(selectedOpt == 'Select Store..') 
        { 
         alert(Translator.translate('Please specify a location.').stripTags()); 
         return false; 

        } 
       else 
        { 
        return true; 
        } 
        } 
       else 
        { 
       return true; 
        } 
      } 
     } 
     alert(Translator.translate('Please specify shipping method.').stripTags()); 
     return false; 
    }, 
0

該代碼總是要工作,因爲它總是會被$ _POST數組,這似乎變成名爲$ pickupData一個數組中設置

你需要改變你的代碼,以確保即$ pickupData [ '存儲']不是零

//make sure this variable is available in the array to avoid errors 
//check to make sure variable is not a zero still 
if(isset($pickupData['store']) && $pickupData['store'] == 0){ 
    $pickupData['store'] = -1; 
} 
+0

釷謝謝你的回覆。這是行不通的。我想在用戶沒有選擇商店並點擊結賬按鈕時顯示javascript警報。與用戶未選擇送貨方式並試圖結帳時相同。 – Sukeshini 2013-03-21 04:02:58

+0

嗨,我找到了解決方案 – Sukeshini 2013-03-21 11:06:42