I used the custom price field in order entity with this name : field_commerce_order_off
for get custom discount from admin in " admin/commerce/orders/add ".
I try to use this hook :
<?php
// Implements hook_commerce_order_presave().
function commerce_deposit_account_commerce_order_presave($order) {
if($order->field_commerce_order_off){
$discount = $order->field_commerce_order_off['und'][0]['amount'];
$line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
// Add the discount as a price component
$line_item->commerce_unit_price->data = commerce_price_component_add(
$order->commerce_order_total['und'][0]['amount'],
'discount',
array(
'amount' => $discount * -1,
'currency_code' => 'IRR',
'data' => array()
),
0 // NOT included already in the price
);
}
}
?>
But it doesn't work!
I don't want to add discount to line_item
, I want to add discount to order.