Saving a variant with new stock from plugin Has anyone had any luck trying to save a variant via a plugin? 

I'm trying to integrate with a 3rd party inventory system and want to grab the current stock information and update my variants. Currently I have

$criteria = craft()-&gt;elements-&gt;getCriteria('Commerce_Variant');
$criteria-&gt;sku = $sku;
$variant = $criteria-&gt;first();


Which works just fine to grab the variant i need, but...

$variant-&gt;stock = 99;
craft()-&gt;commerce_variants-&gt;saveVariant($variant);


This gives me no error, but does not update the variant in the database. What is the method I should be using to achieve this?
I haven't done this, but as a rule I try an mimic what Commerce actually does itself.  In this area I would be inclined to follow the code Commerce uses in it's own completed order handling, found in public function orderCompleteHandler in commerce/services/Commerce_VariantsService.php around line 290:

        $purchasable = $lineItem-&gt;getPurchasable();

        // Only reduce variant stock if the variant exists in db
        if (!$purchasable)
        {
            continue;
        }

        $clearCacheOfElementIds = [];
        if ($purchasable instanceof Commerce_VariantModel &amp;&amp; !$purchasable-&gt;unlimitedStock)
        {

            // Update the qty in the db
            craft()-&gt;db-&gt;createCommand()-&gt;update('commerce_variants',
                ['stock' =&gt; new \CDbExpression('stock - :qty', [':qty' =&gt; $lineItem-&gt;qty])],
                'id = :variantId',
                [':variantId' =&gt; $purchasable-&gt;id]);

            // Update the stock
            $purchasable-&gt;stock = craft()-&gt;db-&gt;createCommand()
                -&gt;select('stock')
                -&gt;from('commerce_variants')
                -&gt;where('id = :variantId', [':variantId' =&gt; $purchasable-&gt;id])
                -&gt;queryScalar();

            // Clear the cache since the stock changed
            $clearCacheOfElementIds[] = $purchasable-&gt;id;
            $clearCacheOfElementIds[] = $purchasable-&gt;product-&gt;id;
        }

        $clearCacheOfElementIds = array_unique($clearCacheOfElementIds);
        craft()-&gt;templateCache-&gt;deleteCachesByElementId($clearCacheOfElementIds);