我正在尝试为Drupal商业创建礼品包装模块。我已经创建了结帐窗格,其中有一个选择框供用户选择是否希望他们的订单礼品包装(以及一个字段用于选择配置表单上的giftwrap价格)。我也创建了一个giftwrap订单项类型。在窗格的base_checkout_form_submit()函数中,我想创建一个giftwrap订单项,并将其添加到订单旁边的产品中。这是我到目前为止有:将Drupal Commerce订单项添加到来自模块的订单
/**
* Implements base_checkout_form_submit()
*/
function commerce_giftwrap_pane_checkout_form_submit($form, &$form_state, $checkout_pane, $order) {
$default_currency_code = commerce_default_currency();
if ($balance = commerce_payment_order_balance($order)) {
$default_currency_code = $balance['currency_code'];
}
// Create the new line item.
$line_item = commerce_line_item_new('giftwrap', $order->order_id);
$line_item->line_item_label = 'Gift Wrapping';
$line_item->quantity = 1;
$line_item->commerce_unit_price['amount'] = variable_get('commerce_giftwrap_price', '2.00');
$line_item->commerce_unit_price['currency_code'] = $default_currency_code;
commerce_line_item_save($line_item);
}
我没有if语句包裹它,但我希望得到它第一个工作日。此代码正在数据库中创建订单项,但它并未将订单项添加到结帐评价页上的购物车内容视图。我已将购物车视图更改为包含产品系列商品和新创建的giftwrap订单项。
任何帮助,将不胜感激。
我最近加入了代码示例为此在这里: http://stackoverflow.com/questions/13491983/drupal-commerce-line-items-alter-the-price/17821893#17821893 – mpoplin