opencart 2.1 中的 selected="selected" 字段

selected="selected" field in opencart 2.1

我正在使用一个模块 AJAX d_quickcheckout 来加快 opencart 2.1 上的结帐页面(不是默认模块)。问题是 payment address 部分的一个字段未被 default 选择,这是 region/state 字段。目前,该字段包含商店所在的 region/state。

即使我删除该字段,此 region/state 也不会显示在结帐页面上,但会显示在 invoice 上!

我希望此字段类似于 --Select State-- 或默认 value="0"$text_none

这是我认为必须更改的两个代码块:

HTML

<select name="payment_address[address_id]" style="width: 100%; margin-bottom: 15px;" data-refresh="3">
          <?php foreach ($addresses as $address) { ?>
              <option value="<?php echo $address['address_id']; ?>" <?php echo ($address['address_id'] == $payment_address['address_id']) ? 'selected="selected"' : ''; ?>> 
                <?php echo $address['firstname']; ?> 
                <?php echo $address['lastname']; ?>, 
                <?php echo $address['address_1']; ?>, 
                <?php echo $address['city']; ?>, 
                <?php echo $address['zone']; ?>, 
                <?php echo $address['country']; ?> 
              </option>
          <?php } ?>
        </select>

AJAX:

function refreshPaymentAddessZone(value) {

    $.ajax({
        url: 'index.php?route=module/quickcheckout/country&country_id=' + value,
        dataType: 'json',
        beforeSend: function() {

        },
        complete: function() {

        },      
        success: function(json) {

            if (json['postcode_required'] == '1') {
                $('#payment-postcode-required').show();
            } else {
                $('#payment-postcode-required').hide();
            }

            html = '<option value=""><?php echo $text_select; ?></option>';

            if (json['zone'] != '') {

                for (i = 0; i < json['zone'].length; i++) {
                    html += '<option value="' + json['zone'][i]['zone_id'] + '"';
                    if (json['zone'][i]['zone_id'] == '<?php echo $payment_address['fields']['zone_id']['value']; ?>') {
                        html += ' selected="selected"';
                    }

                    html += '>' + json['zone'][i]['name'] + '</option>';
                }
            } else {
                html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
            }

            $('#payment_address_wrap select[name=\'payment_address[zone_id]\']').html(html);
        },
        error: function(xhr, ajaxOptions, thrownError) {
            console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
        });
}

您可以评论 $.ajax 调用,下拉列表将始终为空。

您可以试试这个代码块,而不是您当前的 select:

<select name="payment_address[address_id]" style="width: 100%; margin-bottom: 15px;" data-refresh="3">
    <option value="0">-- Select State --</option>
      <?php foreach ($addresses as $address) { ?>
          <option value="<?php echo $address['address_id']; ?>"> 
            <?php echo $address['firstname']; ?> 
            <?php echo $address['lastname']; ?>, 
            <?php echo $address['address_1']; ?>, 
            <?php echo $address['city']; ?>, 
            <?php echo $address['zone']; ?>, 
            <?php echo $address['country']; ?> 
          </option>
      <?php } ?>
    </select>

如果这还不够,请同时删除 AJAX-call。