Craft Commerce update variant field in plugin I'm trying to get, update, and save products &amp;/or variants in my plugin controller, and am stuck on accessing/changing/saving updated fields.

// get product ID from post
$variant_id = craft()-&gt;request-&gt;getPost('variant_id');

// create criteria
$criteria = craft()-&gt;elements-&gt;getCriteria('Commerce_Variant');
$criteria-&gt;id = $variant_id;

// query
$variant = $criteria-&gt;first();


The above works just fine and gets the variant. But now I need to update a few fields and save it. Any idea how to do this?

$variant-&gt;getContent()-&gt;myCustomField = 'new value';


How would I then save $variant?
This is the general mechanism for updating custom fields on elements - use setContentFromPost and then call the element's save function.

    $variant-&gt;setContentFromPost(array(
        'fieldHandle' =&gt; $newValue,
    ));
    craft()-&gt;commerce_variants-&gt;saveVariant($variant);


You should catch exceptions around that really, to handle any errors that may arise (as the model gets validated during save etc.)