I am using this code to insert the commerce stock but it fails some how:
$cp = commerce_product_new($product_type); $cp->is_new = TRUE; $cp->revision_id = NULL; $cp->uid = 1; $cp->status = 1; $cp->created = $cp->changed = time(); $cp->sku = $product_sku; $cp->title = $product_title; $cp->language = LANGUAGE_NONE; $cp->commerce_price = array(LANGUAGE_NONE => array( 0 => array( 'amount' => $product_price, 'currency_code' => 'GBP', ))); $cp->commerce_stock[LANGUAGE_NONE]['value'] = 10; commerce_product_save($cp);
I checked on the documentation using:
$cp->commerce_stock[LANGUAGE_NONE]['value'] = 10;
should do the trick, but strangely its not updating. Am I missing anything? All the rest is working except the stock.