Tags/topics: 
1
Answers
Vote up!
0
Vote down!

Cannot Set Product Price Progamatically

Hi I have created a module that adds products through CSV.
All the attributes get populated apart from the price.
I am not sure where i am going wrong.

$product_node = new stdClass();

if (!empty($product['price']))
{
$product_node->commerce_price['und'][0]['amount'] = ($product['price'] * 100);
}
else
{
$product_node->commerce_price['und'][0]['amount'] = 0;
}

commerce_product_new($product_node);
commerce_product_save($product_node);

Please help

Asked by: Surf Thakur
on July 14, 2014

1 Answer

Vote up!
0
Vote down!

I found the answer

if (!empty($product['price']))
{
$product_node->commerce_price['und'][0]['amount'] = $product['price'] * 100;
$product_node->commerce_price['und'][0]['currency_code'] = commerce_default_currency();
}
else
{
$product_node->commerce_price['und'][0]['amount'] = 0;
$product_node->commerce_price['und'][0]['currency_code'] = commerce_default_currency();
}
commerce_product_new($product_node);
commerce_product_save($product_node);
thanks any ways

Answer by: Surf Thakur
Posted: Jul 15, 2014