Here is my code
function addToCart($product_id, $quantite){
global $user;
$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new($product, $quantite);
$line_item->data['context']['product_ids'] = array($product_id);
$line_item->commerce_unit_price->amount = '900';
commerce_cart_product_add($user->uid, $line_item);
}
The above code add the product to the cart with the correct quantity but the price isn't changed ... Any idea ?
Update (resolved thanks to scott's answer)
//Panier
function addToCartCallback()
{
addToCart($_POST['product_id'], $_POST['quantite']);
}
function addToCart($product_id, $quantite){
global $user;
$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new($product, $quantite);
$line_item->data['context']['product_ids'] = array($product_id);
commerce_cart_product_add($user->uid, $line_item);
$order = commerce_cart_order_load($user->uid);
commerce_cart_order_refresh($order);
}
function groupes_views_commerce_cart_line_item_refresh($line_item, $order_wrapper) {
global $user;
$idProduit = $line_item->commerce_product['und'][0]['product_id'];
$prix = getPrixClient(getIdClient($user->uid), $idProduit) * 100;
$line_item->commerce_unit_price[LANGUAGE_NONE]['0']['amount'] = $prix;
$line_item->commerce_unit_price[LANGUAGE_NONE]['0']['data']['components']['0']['price']['amount'] = $prix;
}