Copied to clipboard

Flag this post as spam?

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

  • juanga16 3 posts 23 karma points
    5 days ago

    No basket exists for the current user

    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

    System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. Parameter name: No basket exists for the current user.

    Thanks in advance

  • David Armitage 314 posts 1239 karma points
    2 days ago
    David Armitage

    Hi Junanga,

    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.



  • David Armitage 314 posts 1239 karma points
    2 days ago
    David Armitage

    Also does that Sku and the variant exist?

  • juanga16 3 posts 23 karma points
    2 hours ago

    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

Please Sign in or register to post replies

Write your reply to: