Hi Lee,
I am thinking that the Adults vs children is too complicated in a simple B & B scenario where occupancy is occupancy, regardless of the age, in this case, only the adults drop down is needed and it would be a far simpler user experience to have suppressed the Child drop down and rename the Adult to persons. Is there some simple way to do this?

Thanks
Franco

CommentFileSizeAuthor
#7 uc_hotel_rhouse.tar_.gz2.39 KBspydmobile
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan’s picture

You need an implementation of hook form alter in a custom module to change the adults title.
I think there is a setting that will hide the children field, if not - form alter will do that too, for an example see #768260: Check out date in search box although this is a different use case - the concept is similar.

spydmobile’s picture

right. There is a feature already for suppressing children but it ONLY suppresses the children drop down in the BLOCK not in the actual search form page. I had good success with the other module we discussed, thanks for your direction on that.

Here is what I am trying to do:

suppress children (hide it and force 0) in the search page.
limit the number of adults to a maximum of 2.

It sounds like a good approach, to simply load the form object, and modify the elements using form alter. So I will add these functions to my new module that I already made.

I will review the code mentioned above and build a couple of form alters from it.

Thank you Lee.....
Franco

larowlan’s picture

No probs, happy to review your code if you paste it here.
You can get rid of the children element by going

$form['search']['children']['#type'] = 'value';
$form['search']['children']['#value'] = 0;

in your form alter, this just makes it a value field instead of a select and hardcodes the value to 0.
You might want to use the devel module for help.
Inside your form alter code, once you have determined that it is the correct form ($form_id = 'hotel_booking_search_form') you can use dsm($form) to examine the form.
You can limit the number of adults with

$form['search']['adults']['#options'] = drupal_map_assoc(range(1,2));
spydmobile’s picture

thanks for this, I have solved all those issues with a custom module, i chose a different approach than yours, not sure if one is better than the other but here is what I did
suppress children in the search page (I dont use the block)
change adults to persons
Make the number of persons dropdown configurable



// get the max persosn from config
$config['max_persons']=variable_get('rhouse_custom_settings_max_persons', 'need_config');
// hide the children drop down
$form['search']['children']['#type']='hidden';
// change adults to persons
$form['search']['adults']['#title']='persons';
// change button to say "Find a room"
$form['search']['submit']['#value']='Find a Room';

// build an array of persons
for ($i = 1; $i <= $config['max_persons']; $i++) {
    $option_array[$i]=$i;
}

// replace the adult dropdown options with our array
$form['search']['adults']['#options']=$option_array;

I would be happy to upload my module when its done and after I run it through coder and clean it up....

larowlan’s picture

Looks fine, you might want to use the php range and drupal_map_assoc functions for cleaner code instead of the for loop, achieves the same thing in one line.

spydmobile’s picture

Super, I will, getting Close :)
Thank You

spydmobile’s picture

FileSize
2.39 KB

well I was able to accomplish 95% of my goals using a custom module. For any others out there who wish to make changes to the cart panes etc, this should be helpful.

I have introduced a bug with this module though and have spent many hours trying to fix it but was unable to. at best I was able to make it fail nicely without disturbing the user. using the original idea you presented to me in email over the holidays, I have implemented the Room A+ room B = discount concept, however doing so causes the trigger room to not be able to be removed from the cart until its the only one left. So because of this, if you add both to the cart, it applies the discount to the target but that target cannot be removed from the cart until the trigger room is moved first, wish I could figure it out, but hey, 9 out of 10 aint bad.

To summarize this module does the following:

1) Implements a two room combo discount
2) Allows choosing the room NIDs for trigger and target in admin page
3) Allows you to config the Discount name
4) allows you to set the discount amount
5) Suppreses the Children dropdown in the search page (not in the search block)
6) Allows config of max number of adults for dropdown
7) Changes Adults to Persons in search and cart page

If anyone finds this module helpful, thank Lee, the author of uc_hotel, because he practically taught me everything in it.

larowlan’s picture

Hi Franco
The key to getting the removal to work is reversing the changes you made to the $item->data.
Ubercart stores the data in the db (uc_cart_products table) (serialised).
The code that removes the line item in Ubercart (unfortunately) does not work on the cart item id, instead it works on cart_id, node id and data (as it stands ie after changes).
So if your module changes $item->data in hook_cart_item, you need to remove the changes on $op = 'remove' so that the data matches the initial state, otherwise the query won't find the item you're trying to delete.
Hope that helps
Lee