Drupal 7 如何以编程方式设置商业产品自定义行项目类型中字段的值?

Drupal 7 如何以编程方式设置商业产品自定义行项目类型中字段的值?,drupal-7,custom-fields,drupal-commerce,Drupal 7,Custom Fields,Drupal Commerce,我已经设置了一个产品,它使用一个名为“custom Notes”的自定义行项目类型(通过配置>行项目类型的UI创建)。结帐时公开的“自定义注释”中的一个字段是“field_Notes”textarea字段。它按预期工作。。。在产品展示中,我可以添加一些自定义文本,单击“订单”,并将注释带到结帐 但是,我需要以编程方式创建这些订单。我已经到了使用hook_菜单提交订单的地步,效果非常好。唯一的问题是我似乎无法设置“field_notes”的值 我做错了什么?谢谢 我认为这可能是因为您没有将正确的商

我已经设置了一个产品,它使用一个名为“custom Notes”的自定义行项目类型(通过配置>行项目类型的UI创建)。结帐时公开的“自定义注释”中的一个字段是“field_Notes”textarea字段。它按预期工作。。。在产品展示中,我可以添加一些自定义文本,单击“订单”,并将注释带到结帐

但是,我需要以编程方式创建这些订单。我已经到了使用hook_菜单提交订单的地步,效果非常好。唯一的问题是我似乎无法设置“field_notes”的值


我做错了什么?谢谢

我认为这可能是因为您没有将正确的商品类型传递给
commerce\u product\u line\u item\u new
。例如,我会这样做:

$line\u item=commerce\u product\u line\u item\u new(
$product,
$quantity=1,
$order\u id=0,
$data=array(),
$line\u item\u type='my\u custom\u line\u item\u type'
);

就是这样!非常感谢!
// 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);