Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Customizing price display in ACBC

Hello,
I am building an ACBC exercize dealing with accomodations, using summed price. I would like to display, in addition to the total price, a price per person, which depends of the number of persons staying together.
My question is not about the number of persons, which is not an ACBC attribute, but with the function containing the calculated price. What is the function name i should call in order to divide it by the number of persons ?
I guess the function name depends of the question (BYO, screener, choice).
Thank you in advance
asked Jan 16 by anonymous

1 Answer

0 votes
Sorry for the delay.  The BYO ended up being a bit complicated, but I believe I've completed your request.  This is the code I put in the footer of my BYO, Screeners, and Choices:

<script>
$(document).ready(function(){
    var params = {
        priceRow: 4,
        persons: [% Persons %],
        label: 'Price per person',
        currencySymbol: '$',
        currencySymbolBefore: true
    };
    
    // BYO
    if ($('.acbc_byo').length) {
        $('.acbc_byo .total_label_cell').html($('.acbc_byo .total_label_cell').html() + '<br/>' + params.label);
        $('.acbc_byo .total_price tbody').append($('.acbc_byo .total_price tbody tr').clone());
        var perPerson = $('.acbc_byo .total_price tbody > tr:last-child input');
        $(perPerson).attr('id', '').attr('name', '');
    }
    
    // Screener / Choice Task
    if ($('.acbc_screener, .acbc_choicetask').length) {
        // Add per-person row
        var priceRow = $('#[% QuestionName() %]_div .inner_table > tbody > tr:nth-child(' + params.priceRow + ')');
        $(priceRow).after($(priceRow).clone());
    
        // Per-person label
        var perPersonRow = $('#[% QuestionName() %]_div .inner_table > tbody > tr:nth-child(' + (params.priceRow + 1) + ')');
        $(perPersonRow).find('.label_text_cell .label_text').text(params.label);
    
        // Per-person values
        $(perPersonRow).find('.level_text_cell .level_text').each(function(){
            var price = $(this).text().replace(params.currencySymbol, '');
            price = Number(price) / params.persons;
            price = Math.round(price);
            if (params.currencySymbolBefore) {
                price = params.currencySymbol + price;
            }
            else {
                price += params.currencySymbol;
            }
            $(this).text(price);
        });
    }
})

function SSI_CustomGraphicalRadiobox(graphicalObj, inputObj) {
    var params = {
        persons: [% Persons %]
    };

    var list = $('input[name=hid_list_[% QuestionName() %]]').val().split(',').map(Number);
    
    var total = 0;
    list.forEach(function(attr){
        var level = SSI_GetValue('[% QuestionName() %]_' + attr);
        if (level) {
            var priceText = $('#[% QuestionName() %]_' + attr + '_' + level).closest('tr').find('.acbc_byo_price_text').text();
            if (priceText) {
                var price = Number(priceText.match(/([0-9]+)/)[0]);
                if (/^\(-/.test(priceText)) {
                    price *= -1;
                }
                total += price;
            }
        }
    });
    
    $('.acbc_byo .total_price tbody > tr:last-child input').val(Math.round(total / params.persons));
}
</script>


The params in lines 4-8 and line 47 must be updated:

* "priceRow" must be set to which attribute is the summed price.
* "persons" needs to reflect the number of persons; I have assumed that the value is in a question named "Persons."
* "label" is the label for the per-person values.
* "currencySymbol" should be the currency symbol used in the ACBC settings.
* "currencySymbolBefore" should be true or false depending on where the currency symbol is set to appear.
answered Jan 18 by Zachary Platinum Sawtooth Software, Inc. (63,675 points)
...