Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Puck Holshuijsen 184 posts 727 karma points
    Aug 30, 2017 @ 09:13
    Puck Holshuijsen
    0

    Question about different prices based on dates

    Hi,

    I am looking into uBooking, so I can use it for a customer. I got a question though.

    What I basically need is having different prices between different dates. For example:

    • Between january 1st and march 31st - 1200 euros
    • Between march 31st and june 7th - 1500 euros

    I need to use it for a booking system for a vacation home, which handles different prices based on the date and based on amount of people. I wasn't able to find out if this is already possible, or maybe you have an idea how I can achieve this?

    Thanks!

    Puck

  • Cimplex 113 posts 576 karma points
    Aug 30, 2017 @ 09:46
    Cimplex
    0

    Hi Puck, Great question!

    This is not a feature that is built in inside the core but it's doable if you create your own custom controller when new bookings are submitted. You can also add some properties to your DocumentType that holds the prices.

    Here's a tutorial how a custom controller looks like: https://www.ubooking.org/support/documentation/tutorials/custom-controller/

    Between line 38 and 39, right after the booking is generated your able to adjust the price. Something like this:

            public ActionResult HandleForm(BookingViewModel model, FormCollection collection)
            {
                // Add a custom field with the current id within the form, in this example the input name is currentNode
                // You might want to add some null check here :)
                var hostel = Umbraco.TypedContent<Hostel>(int.Parse(collection["currentNode"]));
    
                var totalCost = hostel.TotalCost; // Add your calculations here
    
                // ------
    
                var booking = bookingHandler.GenerateBooking();
                booking.TotalCost = totalCost;
                booking = bookingService.Create(booking);
    
                // ------
            }
    

    Booking model: https://www.ubooking.org/support/documentation/reference/management/models/booking/

    Please let me know if you have any other questions.

    // Herman

  • Puck Holshuijsen 184 posts 727 karma points
    Aug 30, 2017 @ 09:50
    Puck Holshuijsen
    1

    Hi Herman,

    Thanks for the quick reply, I will look into this!

    Puck

  • Puck Holshuijsen 184 posts 727 karma points
    Aug 30, 2017 @ 13:09
    Puck Holshuijsen
    0

    Hi Herman,

    I am almost there, but I got one issue.

    I created an extra form field, which is a dropdownlist with number of persons (1 - 16). Inside the customcontroller, i am able to get the inputfields from the BookingViewModel, but i haven't got any usable data.

    enter image description here

    I was exptecting that the value would hold the selected value, instead I get a Guid (which I assume is the Guid of the selected value). Is there a way of getting the correct data with the use of uBooking? Or should I create extra fields inside my Document Type, and create my own mailing system to email that field?

    Thanks! Puck

  • Cimplex 113 posts 576 karma points
    Sep 11, 2017 @ 06:22
    Cimplex
    0

    Hi Puck,

    Sorry I forgot that you answered. Did you solve it?

    // Herman

  • Puck Holshuijsen 184 posts 727 karma points
    Sep 11, 2017 @ 06:40
    Puck Holshuijsen
    0

    Hi Herman,

    I couldn't solve my last post, about the form fields. The calculating stuff is working already :)

    Can you tell me how to get the selected values from the form fields, inside the Customcontroller?

    Thanks. Puck

  • Cimplex 113 posts 576 karma points
    Sep 12, 2017 @ 09:29
    Cimplex
    0

    Hi Puck, Here's a snippet for you:

    public class MyCustomBookingController : SurfaceController
        {
            [HttpPost]
            public ActionResult HandleForm(BookingViewModel model)
            {
                var settings = UBookingContext.Current.Services.SettingService.GetByIdentifierCollection(new List<int>
                {
                    SettingConstant.NewBookingSuccessLabel,
                    SettingConstant.NewBookingSuccessMessage,
                    SettingConstant.NewBookingErrorLabel,
                    SettingConstant.NewBookingErrorMessage
                }).ToList();
    
                if (!ModelState.IsValid)
                {
                    TempData["ubStatus"] = "Error";
                    TempData["ubLabel"] = UmbracoHelper.GetDictionaryItem(SettingHelper.GetSettingValueWithFallback(settings,
                        SettingConstant.NewBookingErrorLabel));
                    TempData["ubMessage"] = UmbracoHelper.GetDictionaryItem(SettingHelper.GetSettingValueWithFallback(settings,
                        SettingConstant.NewBookingErrorMessage));
    
                    return CurrentUmbracoPage();
                }
    
                var bookingHandler = new BookingHandler(model);
                var bookingService = UBookingContext.Current.Services.BookingService;
    
                var booking = bookingHandler.GenerateBooking();
    
                booking = bookingService.Create(booking);
                bookingHandler.CreateBookingData(booking);
    
                // On our documenttype we have created two properties Low season price and High season price.
                // Low season is between jun - aug and the other months are low season
                // We have also created a uBooking field that holds the amount of people that are joining the event with a dropdown menu
                // Our price calculation formula: seasonPrice * totalDays * numberOfPeople
                var page = CurrentPage;
                var totalDays = (booking.LeavingDate - booking.ArrivalDate).TotalDays + 1;
                booking = bookingService.GetById(booking.Id);
                var numberOfPeople = int.Parse(booking.QuestionAnswers.First(x => x.Question == "Number of people").Answer);
    
                if (DateTime.Now.Month >= 6 && DateTime.Now.Month <= 8)
                {
                    booking.TotalCost = page.GetPropertyValue<double>("priceHighSeason") * totalDays * numberOfPeople;
                }
                else
                {
                    booking.TotalCost = page.GetPropertyValue<double>("priceLowSeason") * totalDays * numberOfPeople;
                }
    
                bookingService.Update(booking);
    
                bookingHandler.SendMails(booking);
    
                TempData["ubStatus"] = "Success";
                TempData["ubLabel"] =
                    UmbracoHelper.GetDictionaryItem(SettingHelper.GetSettingValueWithFallback(settings,
                        SettingConstant.NewBookingSuccessLabel));
                TempData["ubMessage"] = UmbracoHelper.GetDictionaryItem(SettingHelper.GetSettingValueWithFallback(settings,
                    SettingConstant.NewBookingSuccessMessage));
    
                return RedirectToCurrentUmbracoPage();
            }
        }
    

    It's not the best soloution but hey, it works! You might note that we are refetching the booking and thats because no QuestionAndAnswers are assigned to the model when its generated and created.

    To get the dropdownvalue inside you emails go to uBooking > Emails and add the field to the body text.

    Hope this solves your problem.

    // Herman

Please Sign in or register to post replies

Write your reply to:

Draft