1
Answers
Vote up!
0
Vote down!

commerce_product_save($product) problem with commerce_price

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(); 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'];
    $product_wrapper->commerce_price->currency_code = commerce_default_currency();
    $product_wrapper->save();

    $product_id = $product->product_id;
Asked by: stevieegee
on January 29, 2015

1 Answer

Vote up!
1
Vote down!

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.

Answer by: stevieegee
Posted: Jan 30, 2015