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.
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.
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.
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
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.
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
For reference, the Basket needs to be explictly saved for the contents to persist. This is achieved by calling the following:
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
The article 3 Steps To Managing Multiple Line Items As One describes various techniques for working with the basket.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.