More in this section
Forums / Ecommerce / Adding to shopping cart thru the API results in Out Of Stock

Adding to shopping cart thru the API results in Out Of Stock

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 2 answered
  1. Tim
    Tim  avatar
    34 posts
    16 Oct 2012
    13 Jun 2013
    Link to this post
    I'm probably missing something obvious... when I add a product to the shopping cart thru the API, it comes in with an error message of "Out Of Stock".  

    Code snippet is below.  I don't know what to do with the "OptionsDetails " parameter in the addToCart ... that may be part of the problem.

    I've tried with several different SKU's, even ones that I "shopped into the cart" without problem.

    So, what am I supposed to do with the OPtionsDetails parameter, and why does it come in with the OutOfStock error?

    Any insight much appreciated!

    Product LessThanMinItem = GetProductBySku("F127479");
    OptionsDetails od = new OptionsDetails();
    ordersManager.AddToCart(cartOrder, LessThanMinItem, od, 1); // add the item to the cart
    --ENd Snip
  2. Svetla
    Svetla avatar
    36 posts
    07 Sep 2015
    13 Jun 2013
    Link to this post
    Hi Tim,

    This is probably because you are adding the Master Version of the product instead of the Live Version. Since version 6.0 we have introduced content lifecycle to Ecommerce and passing the Master Version typically results in giving you this inventory message. Here is the code that you need to use the only difference is calling LifeCycle.GetLive, and in my example id is the current id that results in your error message right now.

    CartOrder currentCartOrder = this.TryGetShoppingCartForUser(orderManager);
    Product productMaster = CatalogManager.GetProduct(new Guid(id));
    Product product = CatalogManager.Lifecycle.GetLive(productMaster) as Product;
    OptionsDetails optionDetails = new OptionsDetails();
    OrdersManager.AddToCart(currentCartOrder, product, optionDetails, 1);

    Have in mind that the TryGetShoppingCartForUser is an extension method that we already have, but to use it you would need to implement IOrdersControl in your class. I would recommend this as a way of getting the current CartOrder as opposed to writing your own method, as it makes better use of our code.

    Hope this helps!
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 2 answered