Discussions

commerce_product_save($product); problem

I am creating a product using the below code. Everything is fine, bar not saving the price information. When I load the product using commerce_product_load($product_id); I get all the correct product information without the price information. Any ideas what I am doing wrong?

    $existing_product = commerce_product_load_by_sku($sku);

    $product = !empty($existing_product) ? $existing_product : commerce_product_new('date_reserve_product');

// add price and currency information
    $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
    $product_wrapper->sku = $sku;
    $product_wrapper->title = $value['promotion_label'];
    $product_wrapper->language = LANGUAGE_NONE;
    $product_wrapper->commerce_price->amount = $value['promotion_cost'] * 100;
    $product_wrapper->commerce_price->currency_code = commerce_default_currency();
    $product_wrapper->save();

    $product_id = $product->product_id;
Posted: Jan 29, 2015

Comments

stevieegee on January 30, 2015

Worked it out! I had called a new product type named 'date_reserve_product ' but I had not define it with hook_commerce_product_type_info(); Silly me.