gjshah7254
2/4/2016 - 9:47 PM

Restore shopping cart kentico or convert order hash

Restore shopping cart kentico or convert order hash

/* 
    ===============================================================================================
     Convert Order hash and Retrieve ShoppingCartInfo object (out-of-box Kentico Checkout process)
    ===============================================================================================
    
    When using the default Kentico checkout process, an order hash is appended as a query string
    parameter (e.g. '?o=XXYYZZ') on the specified final step URL of the Page Wizard Manager. The
    following demonstrates how to convert an order hash into its relevant order ID and subsequently
    reconstruct the related shopping cart object.
*/

using CMS.Helpers;
using CMS.Ecommerce;

protected void Page_Load(object sender, EventArgs e)
{
    var orderId = GetOrderId(); // see below...
    var cart = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId); // returns ShoppingCartInfo object
    
    // do the biz...
}

protected int GetOrderId()
{
    // a full URL with a complete order hash will look something like: http://mydomain.com/my-final-step-url/?o=30499793
    string orderHash = QueryHelper.GetString("o", string.Empty);
    int orderId = ValidationHelper.GetInteger(WindowHelper.GetItem(orderHash), 0);
    return orderId;
}