Copied to clipboard

Flag this post as spam?

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


  • juanga16 4 posts 44 karma points
    Jul 29, 2020 @ 18:31
    juanga16
    0

    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 414 posts 1655 karma points
    Aug 01, 2020 @ 03:13
    David Armitage
    0

    Hi Junanga,

    Did you follow the documentation here? https://docs.ucommerce.net/ucommerce/v9.2/getting-started/transaction-foundation/basket.html

    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.

    Regards

    David

  • David Armitage 414 posts 1655 karma points
    Aug 01, 2020 @ 03:14
    David Armitage
    0

    Also does that Sku and the variant exist?

  • juanga16 4 posts 44 karma points
    Aug 03, 2020 @ 12:47
    juanga16
    100

    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

  • 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.

Please Sign in or register to post replies