Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Adam Lipinski 5 posts 26 karma points
    Dec 30, 2011 @ 14:40
    Adam Lipinski
    0

    uCommerce Razor examples - working with the Basket

    Hi,

    Are there any examples available on how to use uCommerce exclusively with Razor. I have developed menu, Category and Product pages with Razor and I am now stuck trying to work with products adding to a cart/basket. I installed the sample site, however it is all built using XSLT.

    Any help would be appreciated.

    Kind Regards,

    Adam 

  • Adam Lipinski 5 posts 26 karma points
    Jan 02, 2012 @ 02:59
    Adam Lipinski
    0

    I've decided to use Rest Extension methods (/Base) to enable adding products to the Basket and these will be called asychronously wherever an add to cart option is provided. The following method is being used to add a product to the Basket. The problem that I am having is that the basket remains empty after a call to this method.

    [RestExtensionMethod()]
            public static string Add(int ProductId) 
            {
                var catalog = ProductCatalog.All().Where(pc => pc.Name == "misiu").SingleOrDefault();
                var product = Product.All().Where(p => p.ProductId ==  ProductId).SingleOrDefault();  
          SiteContext.Current.CatalogContext.CurrentCatalogName = "misiu";
                SiteContext.Current.OrderContext.GetBasket().PurchaseOrder.AddProduct(catalog, product, 1);

    Does the Basket need to be explictly initialised? Any help would be greatly appreciated as I can't find any documentation as a reference other than the API reference docs.

    Regards,
    Adam

     

  • Adam Lipinski 5 posts 26 karma points
    Jan 02, 2012 @ 10:07
    Adam Lipinski
    1

    For reference, the Basket needs to be explictly saved for the contents to persist. This is achieved by calling the following:

    SiteContext.Current.OrderContext.GetBasket().Save();

    The Basket is saved on a per user/browser basis by way of a cookie identifying the user. The call to GetBasket() creates a PurchaseOrder but the call to Save() actually persists any products added to the Basket to the OrderLines table, which is associated with a PurchaseOrder by OrderId.

    Regards,

    Adam

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 03, 2012 @ 09:24
    Søren Spelling Lund
    0

    The article 3 Steps To Managing Multiple Line Items As One describes various techniques for working with the basket.

Please Sign in or register to post replies

Write your reply to:

Draft