Copied to clipboard

Flag this post as spam?

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


  • Morten Christensen 61 posts 215 karma points
    Nov 12, 2012 @ 14:13
    Morten Christensen
    0

    Update stock from codebehind

    Hi,

    Is it possible to update stock from c#? I tried some different stuff, and I get an error when I do it the-umbraco-way.

    It's related to this post http://our.umbraco.org/projects/website-utilities/tea-commerce/tea-commerce-support/34364-Optimistic-stock-system

    /Morten 

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 13, 2012 @ 08:13
    Rune Grønkjær
    0

    Hi Morten,

    You will need to use the NodeStock class which have a bunch of static methods. It's placed in the TeaCommerce.Data namespace.

    /Rune

  • Morten Christensen 61 posts 215 karma points
    Nov 13, 2012 @ 13:18
    Morten Christensen
    0

    Hi Rune,

    Thanks! I works perfect.

    Should I use ChangeStock or SetStock? ChangeStock doesn't seems to update the node. SetStock can do it, but does it run an umbraco UpdateDocumentCache?

    The thing is that we will have around 200-300 people ordering in the same minute. So I think umbraco will die if the cache is updated 200 times in one minute.

    /Morten

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 13, 2012 @ 13:35
    Rune Grønkjær
    0

    Hi Morten,

    Well. The stock management of Tea Commerce uses a separate custom table in the database. This is partly because of performance which would be very slow if the value was on the node. The other part is that we would have to publish the node, which could potentially publish something the user have previously saved.

    Your doc type should use the custom Tea Commerce stock datatype, which will fetch the stock from the custom table. Then it should be displayed properly.

    Also you should use the GetStock method to retrieve the value for a specific node.

    As to your 2-300 people ordering on the same time, that won't be a problem. It's a simple update to the database each time.

    ChangeStock vs SetStock
    ChangeStock will add or withdraw stock from the current stock of the node/product. SetStock will brutally overwrite the stock.
    Also ChangeStock uses SetStock after calculating the new stock.

    /Rune

     

  • Morten Christensen 61 posts 215 karma points
    Nov 13, 2012 @ 13:49
    Morten Christensen
    0

    Hi Rune,

    Yes, I know about the stock is in the database, and I use the stock datatype on my node.

    When I tried ChangeStock, I took the current stock (with GetStock) and took one from that. I can see know thats wrong, and that why I didn't work as I expected.

    But every things work perfectly now! Thanks :)

    /Morten

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 13, 2012 @ 13:51
    Rune Grønkjær
    0

    No problem. I'm glad to help. :)

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft