Tried different solutions, now I'm looking for this...
SITUATION
I need to create a custom order via rules (trigger is creation of new node) with a calculated price that references the node. I have a custom field in order settings for this.
My rule looks like:
- Create entity order (with status=checkout/payment)
- Set data value of order's field referencing my node
- Save entity order
This works.
Now I need to add line-items/products to fill the order with a calculated price (based on some fields in the node).
I've tried adding:
- Create entity line-item
- Add item to list (add line-item to order just created)
- Save order again
But "EntityMalformedException: Missing bundle property on entity of type commerce_order." comes out.
QUESTION
How do I add products/line-item to the order setting the price and then redirect user to payment?
Ideally I would like to add a list of products (about three or four) already set in the admin's panel, but customizing their price (and of course the total!)
Comments
Maybe also with a single PHP snippet, but how?
I've tried also a single php snippet, like in http://www.commerceguys.com/resources/articles/245 with following code:
... but I get Fatal error: Cannot use object of type EntityDrupalWrapper as array ... at line $order_wrapper->commerce_line_items[] = $line_item; and I need to set one more field (see code above)
Line-item adding: solved. Node reference settings: not yet.
Suddenly the error is arising no more! (maybe caching problem?)
Anyway: in configuration -> order settings -> manage fields I've created a custom field "node reference" for orders... how do I set it in the above snippet? It's reached as $order_wrapper->field_noderef...