Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I just created an MVC Empty site, then installed Umbraco package , then configured Umbraco and then installed Ucommerce package.
In my controller method I want to run this:
transactionLibrary.AddToBasket(quantity: 2, sku: "100-000-001", variantSku: "001");
var amount = transactionLibrary.GetBasket().OrderTotal;
But in the last line I'm getting the error: No basket exists for the current user
Message=Value cannot be null.
Parameter name: No basket exists for the current user.
Thanks in advance
Did you follow the documentation here?
var currentProduct = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<Ucommerce.Api.ICatalogContext>().CurrentProduct;
var transactionLibrary = Ucommerce.Infrastructure.ObjectFactory.Instance.Resolve<Ucommerce.Api.ITransactionLibrary>();
transactionLibrary.AddToBasket(quantity: 1, currentProduct.Sku);
If you are still having the problem do you think you could upload a little more of your code so we can help debug it.
Also does that Sku and the variant exist?
Hi David, I believe I finally could solve the issue.
I just built an empty Web project, then I added Umbraco package and then Ucommerce package. Because I'm learning the API and I want to build from the scratch.
To avoid the aforementioned error I set my current catalog in the context:
// Setting Catalog
var catalogId = new Guid("704F3A60-0C46-4071-BC73-7A6D4943A895");
var catalog = CatalogLibrary.GetCatalog(catalogId);
CatalogContext.CurrentCatalog = catalog;
By setting up the current catalog then I can create the basket, add products and get the total with not problems.
So in my future implementation the first thing I have to do is to set the current catalog in the contetxt.
Thanks and regards
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted