如何在drupal commerce中为订单总数添加自定义折扣

时间:2014-09-09 15:01:43

标签: drupal drupal-7 drupal-commerce

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

1 个答案:

答案 0 :(得分:0)

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

相关问题