Seriously, why is it so hard to add an item to the cart with a specific price.
I've tried like 6 different approaches, but nothing seems to have any effect.
Hi,
I also tried to use this hook, but it doesn't effect the line item price, what amount should I change?
<?php function myticket_commerce_product_calculate_sell_price_line_item_alter($line_item) { global $user;
// Reference the current shopping cart order in the line item if it isn't set. if (empty($line_item->order_id)) { $line_item->order_id = commerce_cart_order_id($user->uid); } $line_item->commerce_unit_price['und'][0]['amount'] = 10000; $line_item->commerce_unit_price['und'][0]['data']['components'][0]['price']['amount'] = 10000; dpm($line_item);
} ?>
The output of dpm shows the changed amounts, but the item added to the cart still has the original price.
Using the following hooks.
hook_commerce_product_calculate_sell_price_line_item_alter($line_item)
hook_commerce_cart_line_item_refresh($line_item, $order_wrapper)
Comments
i found this
i found this
$product = $product = commerce_product_load(7);
$product->commerce_price['und'][0]['amount'] = 39900;
commerce_product_save( $product );
everything is fine. the price for the product is changed
the line items price was updated
also in checkpout and review
but if only want to change the line item price
$line_item = commerce_line_item_load(array(4), array());
$line_item->commerce_unit_price['und'][0]['amount'] = 1234;
commerce_line_item_save($line_item);
this did not effect the review line items
what is my mistake?
Why is this so difficult?
Seriously, why is it so hard to add an item to the cart with a specific price.
I've tried like 6 different approaches, but nothing seems to have any effect.
Most API Docs in *.api.php
Take a look at:
~/sites/all/modules/contrib/commerce/modules/product_pricing/commerce_product_pricing.api.php
You'll see the hook which you can implement in your module:
hook_commerce_product_calculate_sell_price_line_item_alter($line_item)
Hi,
Hi,
I also tried to use this hook, but it doesn't effect the line item price, what amount should I change?
<?php
function myticket_commerce_product_calculate_sell_price_line_item_alter($line_item) {
global $user;
// Reference the current shopping cart order in the line item if it isn't set.
if (empty($line_item->order_id)) {
$line_item->order_id = commerce_cart_order_id($user->uid);
}
$line_item->commerce_unit_price['und'][0]['amount'] = 10000;
$line_item->commerce_unit_price['und'][0]['data']['components'][0]['price']['amount'] = 10000;
dpm($line_item);
}
?>
The output of dpm shows the changed amounts, but the item added to the cart still has the original price.
Which value should we change to take effect?
Thank you,
Fossie
Update line item id price after item purchased.
Hi,
In my case, I want to update the line item price to 0 while showing reports. is it possible to update line item prices?
Please help me.
Thanks
I have a solution
Using the following hooks.
hook_commerce_product_calculate_sell_price_line_item_alter($line_item)
hook_commerce_cart_line_item_refresh($line_item, $order_wrapper)
Check my answer here:
http://stackoverflow.com/a/21395149/1212791