fetching customer profile via rules, when checkout is completed


I need to fetch the customer profile after an order checkout is completed via rules.
The user, who has created the order, can have many different customer profiles and i need to fetch exactly that profile, what belongs to the fetched order.

How can I get that?

thanks, Marc

Posted: Oct 19, 2011


dasmoermel on October 26, 2011

I needed the customer profile/billing attached to the bought Products to offer these informations in a view for the ShopAdmin. In that customer profile are 2 fields, a name-field and a telephonenumber-field.

I defined a new field for my product-type "tour", it's an Entity Reference Field->http://drupal.org/project/entityreference.

When an order is checked out, I fetch the event via rules.

Event: "Checkout completed"
Condition: "Order:type = commerce_order" -> this is the solution to "see" the customer profile from an order.
- set the order state to completed
- loop all lineitems:
run the rule component "get Product from LineItem" Param: LineItem, Customer-Profile/Billing
decreasing stock

Rule "get Product from LineItem"
Parameter: LineItem, Customer-Profile
Provided: none
condition: "LineItem:type = article" -> to "see" the referenced Product
- run the rule component "add customer profile to product" Param: Product, Customer-Profile/Billing

Rule "add customer profile to product"
Parameter: Product, Customer-Profile
Provided: none
condition: "Product:Type = Tour" -> to "see" field-commerce-prod-bookings (entity reference field)
- add item to a list: product:field-commerce-prod-bookings item: customer-profile
- save product

There might be a simpler way, but it works great for me.