I'm trying to get, update, and save products &/or variants in my plugin controller, and am stuck on accessing/changing/saving updated fields.
// get product ID from post $variant_id = craft()->request->getPost('variant_id'); // create criteria $criteria = craft()->elements->getCriteria('Commerce_Variant'); $criteria->id = $variant_id; // query $variant = $criteria->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->getContent()->myCustomField = 'new value';
How would I then save