我在订单实体中使用了自定义价格字段,其名称为field_commerce_order_off
,用于从“admin / commerce / orders / add”中获取管理员的自定义折扣。
我尝试使用这个钩子:
<?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
);
}
}
?>
但它不起作用!
我不想为line_item
添加折扣,我想为订单添加折扣。