【发布时间】:2014-12-26 12:55:49
【问题描述】:
我设置了一个产品,它使用称为“自定义备注”的自定义订单项类型(通过 UI 中的配置 > 订单项类型创建)。结帐时显示的“自定义注释”中的字段之一是“field_notes”文本区域字段。它按预期工作...在产品显示中,我可以添加一些自定义文本,单击“订购”,然后将注释带到结帐。
但是,我需要以编程方式创建这些订单。我已经到了使用 hook_menu 提交订单的地步,而且效果很好。唯一的问题是我似乎无法为“field_notes”设置值。
// Load whatever product represents the item the customer will be
// paying for and create a line item for it.
$line_item = commerce_product_line_item_new($product, $quantity, $order->order_id);
// Save the line item to get its ID.
commerce_line_item_save($line_item);
//***this is the part that's not working. trying to set the field_notes field***
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
$line_item_wrapper->field_notes->set("Does this work??");
// Save the line item to get its ID.
commerce_line_item_save($line_item);
// Add the line item to the order using fago's rockin' wrapper.
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
// Save the order again to update its line item reference field.
commerce_order_save($order);
我做错了什么?谢谢!
【问题讨论】:
标签: drupal-7 custom-fields drupal-commerce