Ajax Basket Framework

From VYRE

Jump to: navigation, search

Contents

Summary:

Unify 4.3.1 introduces a new Ajax Basket Framework Javascript API for performing basket actions and the ability to render the users Basket using AJAX calls to the server.

In order to use the the framework we first need to include the Javascript file in the HTML page.

Including the basket_jax script into the page

<script type="text/javascript" src="/javascript/pub_module/basket_jax.js"></script>

Next we instansiate an object to perform basket actions

Creating the Basket Object

var orderBasket = new Basket({
basket:"order"
});

Above is an example of a Basket object which will handle actions to do with the "order" basket. You can specifiy "bulkEdit" instead if you wish to perform actions to the bulkEdit basket. The next properties are the array of itemIds mapped with an array of quantities for the itemids specified.

Performing Actions with the Basket Object, these can be applied to both order and bulkEdit baskets.

Adding to the basket

/**
* Adds the specified items to the basket
* along with the corresponding quantities
*/
orderBasket.add();

/**
* Adds the items that
* are passed as arguments to the basket
*/
orderBasket.add([45,23]);
/**
* Adds the items and quantities that
* are passed as arguments to the basket
*/
orderBasket.add([45,23],[2,2]);

Removing from the basket

/**
* Removes the specified items to the basket
* along with the corresponding quantities
*/
orderBasket.remove();

/**
* Removes the items that
* are passed as arguments from the basket
*/
orderBasket.remove([45,23]);

Modifying the basket

/**
* Modifies the specified items in the basket
* along with the corresponding quantities
*/
orderBasket.modify();
 
/**
* Modifies the items and quantities that
* are passed as arguments in the basket
*/
orderBasket.modify([45,23],[2,2]);

Clearing the basket

orderBasket.clear();

Rendering the basket using the BasketRenderer Class

  /**
    * Declare basketRenderer object to render the basket list.
    */
     var basketRenderer = new BasketRenderer({
        basket:"bulkEdit",  
        xslId:33,
        storeId:1,
        pageId:$page_id, 
        portletId:$portlet_id, /* since 4.4.0.1 */
        contextPath:"",
        loadContent : true,         /* deprecated in 4.6 */
        loadLinkedItems : true,     /* deprecated in 4.6 */
        loadLinkedContent : true,   /* deprecated in 4.6 */
        loadLinkedUsers : true      /* deprecated in 4.6 */
        /*globalXmlCfgId : 1234,  -- alternatively specify this for fine granular XML results -- since Unify 4.6.2 */
 
      });
 
    /**
    * Overwrite BasketRenders resultHandler method to specify what to do with the response
    */
     basketRenderer.resultHandler = function( xml ){
           document.getElementById("basketList").innerHTML = xml;
    }
 
    /**
    * Sends the request for the basket and uses the resultHander method as a callBack
    */
    basketRenderer.render();

N.B. When upgrading or using Unify 4.6 Any AJAX configurations that require a 'pageId' parameter to be set, but do not have them, will now result in a 'NullPointerException'. (This functionality was introduced in Unify 4.6. If you are using a previous version this feature will not be available.).

The ajax listener accepts the following actions ( taken from the original spec)

Actions:

Add to basket:

  • &action=basketAdd (adds the items specified to the basket)
  • &basket (mandatory)
    • &basket=order (use order basket for performing actions and rendering basket list)
    • &basket=bulkEdit (use bulk edit basket for performing actions and rendering basket list)
  • &itemIds (mandatory)_
    • &itemIds=233 (an example of a single item)
    • &itemIds=244,266,455 (example of multiple ids - comma delimited)
  • &quantity (optional)
    • &quantity=1 (quantity for single item)
    • &quantity=1,5,3 (quantity for three items - comma delmited)
    • if no quantity is specified, a defaulted quantiy of 1 will be incremented to the specified itemIds
    • if action = "basketAdd" then the items will be incremented by these quantities
    • the set of quantities will be directly mapped in order of the set of itemIds specified.
      An error will be thrown if these 2 sets are not directly mapped

e.g. /servlet/ajax?action=basketAdd&basket=order&itemIds=12,22&quantity=3,2

Modify basket:

  • &action=basketModify (modifies the items specified in the basket)
  • &basket (mandatory)
  • &itemIds (mandatory)
  • &quantity (mandatory)
    • if action = "basketModify" then the items will be replaced by these quantities
    • the set of quantities will be directly mapped in order of the set of itemIds specified.
      An error will be thrown if these 2 sets are not directly mapped_

e.g. /servlet/ajax?action=basketModify&basket=basketEdit&itemIds=233&quantity=2

Remove from basket:

  • &action=basketRemove (removes items specified in the basket totally(resets count))
  • &basket (mandatory)
  • &itemIds (mandatory)

e.g. /servlet/ajax?action=basketRemove&basket=order&itemIds=32

Clear basket:

  • &action=basketClear (clears basket)
  • &basket (mandatory)

e.g. /servlet/ajax?action=basketClear&basket=basketEdit

Render basket:

  • &action=basketRender (renders basket list with a specified transformation)
  • &basket (mandatory)
  • &contextPath=$contextPath (sends contextPath )
  • &pageId=$pageId (sends pageId )
  • &xslId (mandatory, since Unify 4.8 the parameter is deprecated and legacy id is used)
    • &xslId=233 (id of the XSL that will be used to transform the basket list for the response)
  • &xslPath (since Unify 4.8 only)
    • &xslPath=someXsl (full path of the XSL that will be used to transform the basket list for the response)


  • &storeId (optional)
    • &storeId=1 (id of the store to filter basket list reponse by)
    • If not specified, default to Show All
  • &loadContent=[false/true] (optional default=false)
  • &loadLinkedItems=[false/true] (optional default=false)
  • &loadLinkedContent=[false/true] (optional default=false)
  • &loadLinkedUsers=[false/true] (optional default=false)

e.g. /servlet/ajax?action=basketRender&basket=order&xslId=444&storeId=1&loadLinkedContent=true&loadLinkedItems=true&loadLinkedUsers=true&loadLinkedContent=true

See also

Personal tools