0

我在具有此名称的订单实体中使用了自定义价格字段: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,我想给订单添加折扣。

4

1 回答 1

0

您可以使用https://www.drupal.org/project/commerce_fees为订单添加负费用。

于 2014-11-27T15:20:19.110 回答