我在shipping方法的模板文件中添加了一个下拉框。现在我想把它变成必填项。我已经尝试了很多方法。但是没有成功。任何帮助都将不胜感激。
下面是模板文件。
<?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>
这段代码总是会起作用的,因为它总是会在$_POST数组中设置它似乎变成了一个名为$pickupData的数组
你需要修改你的代码,以确保$pickupData['store']不是零
//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;
}
在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;
},