0

我在配送方式的模板文件中添加了一个下拉框。现在我想让它成为必填字段。我已经尝试了很多方法。但没有奏效。任何帮助将不胜感激。

下面是模板文件。

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

2 回答 2

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;
    },
于 2013-03-21T11:09:32.810 回答
0

这段代码总是可以工作的,因为它总是被设置在 $_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;
}
于 2013-03-20T16:30:29.370 回答