Zen Cart Logo
Forums / Managing Customers and Orders / Question - adding radio buttons to checkout-shipping page

Question - adding radio buttons to checkout-shipping page

Locked

Views: 5,056

Results 1 to 20 of 23
This thread is locked. New replies are disabled.
2 Mar 2007, 9:39 PM
#1
bolson avatar

bolson

New Zenner

Join Date:
Feb 2007
Posts:
4
Plugin Contributions:
0

Question - adding radio buttons to checkout-shipping page

On the checkout page Step 1 of 3 I want to add 2 radio buttons one for Residential and one for Commercial. I have those on the site. What page do these items POST to so I can add them in to the database?

2 Mar 2007, 10:17 PM
#2
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,606
Plugin Contributions:
0

Re: Question - adding radio buttons to checkout-shipping page

What are they supposed to do if checked? Change the shipping rates or just give you the information?

2 Mar 2007, 11:18 PM
#3
bolson avatar

bolson

New Zenner

Join Date:
Feb 2007
Posts:
4
Plugin Contributions:
0

Re: Question - adding radio buttons to checkout-shipping page

It is just going to gather the information and put it in the invoice for the owner of the store to know...

3 Apr 2007, 6:40 PM
#4
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

Looking for the same thing. What would the procedure be?

6 Apr 2007, 1:39 PM
#5
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

Still looking for a solution, Anyone got an idea how to go about this?

Thaks,
Slabadoo

13 Apr 2007, 4:29 PM
#6
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

Need a little help here, Anyone got the answer for adding radio buttons.

Thanks,:smile:

14 Apr 2007, 11:58 PM
#7
theoracle avatar

theoracle

Suspended

Join Date:
Aug 2004
Posts:
3,180
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

If you can specify which template filename to add this checkbox feature, let me know and I'll see what I can do. :wink2:

16 Apr 2007, 3:15 PM
#8
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

Great! I am just going to use the flat.php preferably withot the prices showing up also.

Thanks,

17 Apr 2007, 8:56 PM
#9
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

Hi, still waiting for an answer on this one.:smile:

Thanks,

24 Apr 2007, 8:23 AM
#10
thetankgirl avatar

thetankgirl

New Zenner

Join Date:
Jul 2005
Posts:
33
Plugin Contributions:
0

Re: Question - adding radio buttons to checkout-shipping page

I'm also looking for the same thing!

24 Apr 2007, 8:54 AM
#11
bluefish avatar

bluefish

New Zenner

Join Date:
Apr 2007
Posts:
8
Plugin Contributions:
0

Re: Question - adding radio buttons to checkout-shipping page

Hiya,

You can put the radio buttons themselves on page
\includes\templates\template_default\templates\tpl_checkout_shipping_default.php
Replace 'template_default' with your template name ....
Or include them in which ever shipping module page you want - like
/includes/modules/shipping/flat.php - if you want them to relate specifically only with that module.

Then the shipping page posts back to itself for validation before going to the next page. The post validation code is held in the separate header file of this page
\includes\modules\pages\checkout_shipping\header_php.php

It's here that you'll need to put code to take the selected radio button value and save it to the database or where ever you need .. of course make sure you only post the value once the rest of the page has been successfully validated ..

Hope that helps point you in the right direction ....

1 May 2007, 8:37 PM
#12
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

bluefish,

Thanks for your reply, I would prefer to use the flat.php and just add radio buttons to it. What part of flat would I need to edit to get more than one radio button?

My thought was to edit flat.php to the below code but it didn't work-

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));

Any ideas how I would accomplish adding more radio buttons

2 May 2007, 2:50 PM
#13
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

Still looking for an answer for this one. Anyone?

Thanks,

3 May 2007, 10:30 AM
#14
bluefish avatar

bluefish

New Zenner

Join Date:
Apr 2007
Posts:
8
Plugin Contributions:
0

Re: Question - adding radio buttons to checkout-shipping page

Hiya slabadoo,

Been busy - but here's the first half of the solution for you .... I'm working on v1.3.7 btw

/includes/modules/shipping/flat.php holds the functions that relate to that shipping module
to add the rb information - make this change to flat.php - look for //+BLUEFISH
...
// class methods
function quote($method = '') {
global $order;

  $this->quotes = array('id' => $this->code,
                        'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                        'btype'  => array('RES' => 'Residential',  //+BLUEFISH
                        		      'BUS' => 'Business'),    //+BLUEFISH
                        'methods' => array(array('id' => $this->code,
                                                 'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                 'cost' => MODULE_SHIPPING_FLAT_COST)));

...

Now to make the rbs appear on the shipping screen you have to change file :
/includes/templates/<yourtemplate>/templates/tpl_checkout_shipping_default.php
this page takes all the shipping module information we just set up and displays it
modification required to display the new radio buttons

....

<?php echo zen_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'id="ship-'.$quotes[$i]['id'] . '-' . $quotes[$i]['methods'][$j]['id'].'"'); ?>

<label for="ship-<?php echo $quotes[$i]['id'] . '-' . $quotes[$i]['methods'][$j]['id']; ?>" class="checkboxLabel" ><?php echo $quotes[$i]['methods'][$j]['title']; ?></label>

<!--</div>--> <br class="clearBoth" /> <?php //+BLUEFISH output rbs if it has been set for current shipping method if (isset($quotes[$i]['btype'])) { // set default option to be selected if (! isset($_SESSION['shipping'][$quotes[$i]['id'] . '_' .'btype'])){ $_SESSION['shipping'][$quotes[$i]['id'] . '_' .'btype'] = $quotes[$i]['id'] . '_' . 'RES'; } echo "<b>What type of purchase is this?</b>"; // define this in your language file .... foreach($quotes[$i]['btype'] as $btypeKey => $btypeValue ) { $checked = (($quotes[$i]['id'] . '_' . $btypeKey == $_SESSION['shipping'][$quotes[$i]['id'] . '_' .'btype']) ? true : false); echo '<br>' . zen_draw_radio_field($quotes[$i]['id'] . '_' . $btypeKey, $checked, $checked) . ' ' . $btypeValue; } } // +BLUEFISH end output rbs $radio_buttons++; } } ?> ....

Now you need to pick up the value of the selected option and save this to your database - I don't have enough time to finish this now .. but you'll need to look at the value of
$POST['shipping'][$quotes[$i]['id'] . '_' .'btype']
which basically means for flat rate - if they select RES then
$POST['shipping']['flat_btype'] = 'RES'

you'll have to do this in file
/includes/languages/modules/pages/checkout_shipping/header_php.php
probably somewhere around here ....
...
// process the selected shipping method
if ( isset($_POST['action']) && ($_POST['action'] == 'process') ) {
if (zen_not_null($_POST['comments'])) {
$_SESSION['comments'] = zen_db_prepare_input($_POST['comments']);
...

And then when the order is saved and confirmed you'll have to post this information to the database.
You can either hack this into file
includes/modules/checkout_process.php
this is the code that commits the order to the database
...
// load the before_process function from the payment modules
$payment_modules->before_process();
$zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_BEFOREPROCESS');
// create the order record
$insert_id = $order->create($order_totals, 2);
$zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE');
$payment_modules->after_order_create($insert_id);
$zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE');
// store the product info to the order
$order->create_add_products($insert_id);
$_SESSION['order_number_created'] = $insert_id;
$zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS');
//send email notifications
$order->send_order_email($insert_id, 2);
$zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL');
...

Or you can use the Zen Cart event listener system to listen for an order being saved - event
'NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS' (see above)

if i get time i'll carry on with this unless someone else feels like finishing this off!

3 May 2007, 3:29 PM
#15
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

This is a great start, I am in the process of trying to make it work, One thing I have noticed is the radio buttons are able to be both selected, How do I achieve only one of them being selected? Meaning by default residential is selected, if I then select Business, I need the Residential rb to deselect?:smile:

Thanks,

14 May 2007, 10:33 AM
#16
thetankgirl avatar

thetankgirl

New Zenner

Join Date:
Jul 2005
Posts:
33
Plugin Contributions:
0

Re: Question - adding radio buttons to checkout-shipping page

has someone got this script working/finished it? I'm still learning PHP and I don't have enough knowledge yet to make this work :(

14 May 2007, 1:10 PM
#17
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

I've only benn able to ge the radio buttons on the page. I am still looking for a way to relate the radio buttons so only one can be chosen at a time. Perhaps Bluefish has a little more time to nail down the process. I think if I can get the buttons to be related then I could probably take it to the next level but someone will have to get me over that hump first.

Thanks,

18 May 2007, 9:56 AM
#18
bluefish avatar

bluefish

New Zenner

Join Date:
Apr 2007
Posts:
8
Plugin Contributions:
0

Re: Question - adding radio buttons to checkout-shipping page

Hiya,

Sorry about the bug in that last post of mine - not very well behaved radio buttons were they!

Anyways .. I had a bit of spare time so here's a correction to link the radio buttons up - and the next step which stores the user selection in the SESSION data.

In TPL_CHECKOUT_SHIPPING_DEFAULT.PHP the code addition should be :

....

<?php echo zen_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'id="ship-'.$quotes[$i]['id'] . '-' . $quotes[$i]['methods'][$j]['id'].'"'); ?>

<label for="ship-<?php echo $quotes[$i]['id'] . '-' . $quotes[$i]['methods'][$j]['id']; ?>" class="checkboxLabel" ><?php echo $quotes[$i]['methods'][$j]['title']; ?></label>

<!--</div>--> <br class="clearBoth" /> <?php //+BLUEFISH output rbs if it has been set for current shipping method ".$_SESSION['shipping']['BF_PURCHASE_TYPE']; //+bluefish if (isset($quotes[$i]['btype'])) { // set Residential as default option to be selected change RES to BUS to set to Business if (! isset($_SESSION['shipping']['BF_PURCHASE_TYPE'])){ $_SESSION['shipping']['BF_PURCHASE_TYPE'] = $quotes[$i]['id'] . '_' . 'RES'; } echo "<b>What type of purchase is this?</b>"; // define this in your language file .... foreach($quotes[$i]['btype'] as $btypeKey => $btypeValue ) { $checked = (($quotes[$i]['id'] . '_' . $btypeKey == $_SESSION['shipping']['BF_PURCHASE_TYPE']) ? true : false); echo '<br>' . zen_draw_radio_field('BF_PURCHASE_TYPE', $quotes[$i]['id'] . '_' . $btypeKey, $checked) . ' ' . $btypeValue; } } // +BLUEFISH end output rbs $radio_buttons++; } } ?> ....

Then put additional code in CHECKOUT_SHIPPING/HEADER_PHP.PHP to pick up the radiobutton they selected and save it to the SESSION variable $_SESSION[shipping]['BF_PURCHASE_TYPE]. This value will then be available to be saved to the database when they finally save the order .. sorry don't have time now to do that bit ....

....
if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
$_SESSION['shipping'] = array('id' => $_SESSION['shipping'],
'title' => (($free_shipping == true) ? $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
'cost' => $quote[0]['methods'][0]['cost']);

// STORE PURCHASE TYPE IF FLAT RATE SHIPPING SELECTED +BLUEFISH
//+BLUEFISH
if ( (isset($_POST['shipping'])) && ($_POST['shipping']=='flat_flat')) {
$_SESSION['shipping']['BF_PURCHASE_TYPE']=$_POST['BF_PURCHASE_TYPE'];
}
// // END OF STORING PURCHASE TYPE - BLUEFISH

                    zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));

....

Hope that helps ....

18 May 2007, 3:22 PM
#19
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Question - adding radio buttons to checkout-shipping page

bluefish, this has helped so much! As you can probably guess, I has it all working except for passing it to step 3 of the checkout process where it would say Residential instead of

Shipping Method: Flat Rate (Best Way)

And of course, this would include passing it to the DB which you have not had time to explain. Would love to get the last part of the code to make the above happen. Yes, I am begging!!!:blush:
thanks,

21 May 2007, 9:29 AM
#20
bluefish avatar

bluefish

New Zenner

Join Date:
Apr 2007
Posts:
8
Plugin Contributions:
0

Re: Question - adding radio buttons to checkout-shipping page

Hey there - had some more time - so here are the changes (in attached file) needed for you to display the purchase type on the checkout confirmation page - plus save it to the database.

I've tried to keep it nice and simple so you can display the purchase type data whereever you need to in the future too!

It's all quite quick and dirty but it should work - I've only tested it briefly .. so please test test test - and make backups of your database and all original files before making changes.

Enjoy!