Chapter 18. Product Stock Reservation

Table of Contents

API Calls
Storefront Application
Order Integration Manager
Reservations for Bookable Products
Batch Removal of Expired Stock Records

KonaKart allows you to reserve stock for a predefined amount of time. Once the reservation expiry time has been reached, the reserved stock becomes available again for other customers. This feature is useful when you have products that cannot be oversold so you need to ensure that they remain in stock during the checkout process.

API Calls

The API used to reserve stock is

public BasketIf[] reserveStock(String sessionId, BasketIf[] basketItems, StockReservationOptionsIf options) throws KKException;

In the standard storefront application, it is called in CheckoutAction.java before displaying the one page checkout page. When the reservation is successful, the returned array of Basket items is populated both with general stock information and with reserved stock information. The relevant attributes are:

  • reservationId : The reservation identifier. When no reservation is present (maybe the reservation was not successful), the default value is -1.

  • qtyResrvdForResId : The quantity reserved for this reservation id.

  • quantityReserved : The total quantity reserved. This is useful information because if the reservation was not successful but quantityReserved > 0, you may inform your customers that the product is currently reserved by other customers but may become available shortly if they do not complete the purchase.

  • quantityInStock : The total quantity in stock.

  • quantityAvailable : The total quantity in stock – the total quantity reserved.

  • reservationExpiryDate : When the reservation expires.

  • reservationStartDate : When the reservation started.

The StockReservationOptions allows you to:

  • Define the number of seconds the reservation is active for. The default is set to -1 which means that the value defined in the global configuration variable is used. This global variable can be found in the Admin App under Configuration >> Stock and Orders. A batch job should be scheduled to run at regular intervals to remove expired reservations. Such a job is part of the download package. It’s called removeExpiredStockReservationsBatch and can be found within /custom/batch/src/com/konakartadmin/bl/AdminProductBatchMgr.java after installing KonaKart.

  • Define whether you want to allow a partial reservation for a product if the number of items available is less than the number required. The default behaviour is to not allow partial reservations.

  • Define a maximum number of reservations per customer for any one product. This is a defensive measure to prevent a customer from abandoning multiple checkouts or a (single checkout with a high quantity number) and so reserving products and preventing other customers from buying them.

AddToBasketOptions has an attribute called getStockReservationInfo . When set to true the basket items returned have the following attributes populated:

  • reservationId : The reservation identifier. When no reservation is present, the default value is -1.

  • qtyResrvdForResId : The quantity reserved for this reservation id.

  • reservationExpiryDate : When the reservation expires.

  • reservationStartDate : When the reservation started.

It applies to the updateBasketWithStockInfoWithOptions() and to the getBasketItemsPerCustomerWithOptions() API calls.

There are three API calls to remove stock reservation records from the database. These are:

  • removeStockReservationsForBasketItems()

  • removeStockReservationsForOrderProducts()

  • removeStockReservationsForIds()

Under java_api_examples/src/com/konakart/apiexamples there is a Java classs called ReserveStock.java which demonstrates how the API calls can be used in order to reserve stock.