2014-12-26 7 views
1

"구성> 품목 유형"의 UI를 통해 생성 된 "사용자 정의 노트"라는 사용자 정의 품목 유형을 사용하는 제품을 설정했습니다. 체크 아웃시 노출되는 "Custom Notes"의 필드 중 하나는 "field_notes"텍스트 영역입니다. 의도 한대로 작동합니다 ... 제품 디스플레이에서 사용자 정의 텍스트를 추가하고 ORDER를 클릭하면 노트가 체크 아웃을 수행합니다.어떻게 프로그래밍 방식으로 Commerce Product 사용자 지정 품목 유형의 필드 값을 설정할 수 있습니까?

그러나 프로그래밍 방식으로 이러한 주문을 만들어야합니다. 나는 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); 

내가 뭘 잘못하고 있니? 감사!

답변

1

commerce_product_line_item_new에 올바른 광고 항목 유형을 전달하지 않았기 때문일 수 있습니다. 예를 들어, 이렇게하면 어떻게 할 수 있습니까?

$line_item = commerce_product_line_item_new(
    $product, 
    $quantity = 1, 
    $order_id = 0, 
    $data = array(), 
    $line_item_type = 'my_custom_line_item_type' 
); 
+0

그게 전부입니다! 정말 고마워! – sakeferret