Price list | Previo API

Price list

Description

Price list of accommodation with the same functionality and html structure as the price lists used on the websites of hotels created by our company.

Properties:

  • Simple file cache
  • Supported languages ​​cs, en, de and sk
  • Switching seasons using JavaScript
  • Prices per room / per person

Download source code

History of changes

Date Change
17.7.2009 Added Slovak
20.7.2009 More accurate CSS class names
20.7.2009 Fixed invalid formatting character in English translation

Usage

Upload the Previo_PriceList base class from its actual location and set the login name, password, cache directory, and wsdl file addresses in the constructor.

require_once 'Previo/PriceList.php';
$priceList = new Previo_PriceList(array(
    'login'    => 'login_name',
    'password' => 'password',
    'cachedir' => 'path_to_directory',
    'booking' => array(
        'wsdl' => 'https://api.previo.cz/v1/wsdl/booking.wsdl'),
    'hotel' => array(
        'wsdl' => 'https://api.previo.cz/v1/wsdl/hotel.wsdl'),
    'system' => array(
        'wsdl' => 'https://api.previo.cz/v1/wsdl/system.wsdl')));

Set hotel id, date, language and currency.

$priceList
    ->setHotId(1)
    ->setTerm(array('from' => '2009-01-01', 'to' => '2009-12-31'))
    ->setLang('cs')
    ->setCurrency('CZK');

Now all you have to do is call the render()method, which returns the HTML code of the price list.

echo $priceList->render();

Each subsequent call to the render() method with the same combination of hotel id, date, language, and currency returns the code stored in the file in the cachedir directory. There is no connection to the Previo server at all.

Finally, season switching is activated, just call the JavaScript function previoLoadPriceList(). This needs to be done when the entire document is ready. Use e.g.

<body onload="previoLoadPriceList()"></body>

or one of the JavaScript libraries (jQuery, Prototype).

Possible improvements

Regular maintenance

The first call to the render()method requires a connection to the Previo server. It is not good for this task to lie on the shoulders of any of the visitors to your site. Therefore, create a cron task and generate price lists at regular intervals, so visitors will only see the cached results.

// file cronCenik.php
 
// first you need to delete the chachedir directory ...
 
$priceList = new Previo_PriceList(...);
$priceList->setTerm(array(...));
// for all hotels connected with Previo
foreach ($hotIds as $hotId) {
    $priceList->setHotId($hotId);
    // your site is in Czech and English
    foreach (array('cs', 'en') as $lang) {
        $priceList->setLang($lang);
        foreach (array('CZK', 'EUR') as $currency) {
            $priceList->setCurrency($currency);
            // render empty, the result is saved in cachedir
            $priceList->render();
        }
    }
}

Cache

The cache method used is primitive. If you use a custom method (memcache, Zend_Cache), use it.

Translations

The Previo_PriceList class contains the _translate() translation method and strings stored in a static array. If you use another system (gettext, constants), replace these structures with your own solution.

Changing the structure of HTML code

All HTML code is located in the template.php file. Add elements or CSS class names as you wish.