I’m busy developing an app which uses the OFN API to affect product counts. Nothing seems to be working, though.
I’ve tried PUTing product[count_on_hand] to a product endpoint, variant[count_on_hand] to a variant endpoint. Neither makes any difference to the count_on_hand value, but a successful result is returned (ie, no error).
Basically, I’ve tried this:
PUT /api/products/1?product[count_on_hand]=100
And this:
PUT /api/products/1/variants/1?variant[count_on_hand]=100
That looks like you’re starting from the right place. The one to look for is the PUT on the variant, not the product, since the product’s count_on_hand value is a cached version of that stored on the variant(s).
There’s an additional layer of complexity here because of VariantOverrides, which allow a hub to have their own stock level of a variant, independent of the stock level at the producer or at other hubs. There’s a little documentation of variant overrides at this page: Variant Overrides - Hub can override stock level and price on a variant . (@Kirsten, do you know of any more thorough documentation?)
I doubt that’s causing your immediate problem though. If I were to investigate this problem myself, I’d start by putting a binding.pry in the spree API, in Spree::Api::VariantsController#update and investigate whether authorisation was granted, if the save succeeded and so on.
Thanks for the pointers, I’ll start digging. Was the API also changed to support that feature? Are there any specs or tests in the codebase that would help me to learn how to use that?