【问题标题】:How to add custom discount to order total in drupal commerce如何在drupal commerce中为订单总额添加自定义折扣
【发布时间】:2014-09-09 15:01:43
【问题描述】:

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

【问题讨论】:

    标签: drupal drupal-7 drupal-commerce


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 2021-11-23
      • 1970-01-01
      • 2021-06-09
      • 2023-03-30
      相关资源
      最近更新 更多