Open Cart - Receiving radio value at checkout page

2019-09-20 19:36发布

I need help to create a radio box during the checkout. I have no idea how to have the result of the radio box send along with my other information in the checkout page such as billing address and many more.

this is what i do ,

<input type="radio" name="shipping_address" value="existing" id="shipping-address-existing" checked="checked" class="radio inline" />
<b><?php echo $text_delivery2; ?></b>

<input type="radio" name="shipping_address" value="existing" id="shipping-address-existing" checked="checked" class="radio inline" />
<b><?php echo $text_delivery3; ?></b>
</label>

but there is nothing shown. thanks

1条回答
We Are One
2楼-- · 2019-09-20 19:51

First be specic on question because the checkout page contains list of conditions along with various section (login,register,payment address, payment method, shipping address, shipping method, quick confirm etc)

There are list of action and their regarding template, So you need to change in the regarding file, Suppose you are adding radio button on billing address

Find regarding template file and add radio

//template>checkout>payment_address.tpl 
<input type="radio" name="shipping_address" value="existing1" id="shipping-address-existing" checked="checked" class="radio inline" />
<b><?php echo 'Delivery2'; ?></b>

<input type="radio" name="shipping_address" value="existing2" id="shipping-address-existing" checked="checked" class="radio inline" />
<b><?php echo 'Delivery3'; ?></b>
</label>

Now in checkout page you can see your radio buttons, It uses the ajax method to parse data to function

//in line 350 of template>checkout>checkout.tpl 

you can see a ajax function function

$('#button-payment-address').live('click', function() {
    $.ajax({
        url: 'index.php?route=checkout/payment_address/validate',
        type: 'post',
        data: $('#payment-address input[type=\'text\'], #payment-address input[type=\'password\'], #payment-address input[type=\'checkbox\']:checked, #payment-address input[type=\'radio\']:checked, #payment-address input[type=\'hidden\'], #payment-address select'),
        dataType: 'json',

Here the url repreesnts the controller function

// controller>checkout>payment_address.php and function is validate()

Here you can fetch your radio value $_POST['shipping_address'] because in ajax we have defined type: 'post'

Hope this helps

查看更多
登录 后发表回答