When creating a booking via the admin, the "create a new profile" functionality can be used to create a new customer. After saving the profile, the auto complete properly returns the new customer for the booking creation.

However, when viewing the order, the customer and Billing Information is not retained. This can be seen on the commerce order view:
/admin/commerce/orders as well as on the order itself.

Comments

ben.hamelin’s picture

Working on this today, hoping for some feedback regarding next steps.
During the "Create new profile" process, the "owned by" user association field is hidden.
This creates a new `commerce_customer_profile` record with uid = 0.
At this time a new `rooms_customers` record is created as well, referencing the profile id
The booking process resumes, the new "profile" is selected, and the booking is created.

At this point we have a new `commerce_order` record, with uid = [ADMIN_UID]
I believe this is the point where we need to step in. With no valid link to the customer profile, the order billing info is left empty.
Manually updating the `field_data_commerce_customer_billing` profile_id reference fixes the issue.

I believe if we get this value to the order creation process we should be ok.

ben.hamelin’s picture

Based on this post: http://www.drupalcommerce.org/discussions/2615/programatically-create-or...

Can we add the following to rooms_booking.admin.inc line #1132

$profile_object = array ( 
        'und' => array ( array ( 'profile_id' => $profile_id , ) , ) , ); 
    
$order->commerce_customer_billing = $profile_object;

This would require adding 6th argument to rooms_booking_create_order(), namely the $profile_id

ashzade’s picture

We are also very interested in a solution for this problem. We tried work arounds but it looks like this functionality is a requirement.

ben.hamelin’s picture

Status: Active » Needs review
StatusFileSize
new1.74 KB

patch attached as described in #2. Creating new booking, and editing existing booking worked fine.

ben.hamelin’s picture

Sorry, that last patch was backwards. Also updated to reflect comment #

ashzade’s picture

Ben, you've done it! It works :) This should really be pushed up to the next release as it's a vital feature.

ronald_istos’s picture

Ben - will look into this hopefully today! Thanks for the work.

ben.hamelin’s picture

ashgotti, you are welcome. Glad to have a potential solution in place and that it helped you out!
Ronald, my pleasure, glad to help!
Just finished updating the DB to add the relationships as needed.
Here's the PHP I used, potentially helpful for @ashgotti and others, also I could see this in an _update function for a future release?

 $orders_result = db_query("SELECT orders.order_id,orders.revision_id, profiles.profile_id
 FROM `main_commerce_order` `orders`
INNER JOIN `main_rooms_bookings` `bookings` ON bookings.order_id = orders.order_id
INNER JOIN `main_rooms_customers` `customers` ON bookings.customer_id = customers.id
INNER JOIN `main_commerce_customer_profile` `profiles` ON customers.commerce_customer_id = profiles.profile_id
WHERE 
orders.order_id not in (select entity_id from  main_field_data_commerce_customer_billing)
AND orders.status NOT IN ('cart' , 'canceled' , 'checkout_checkout')
ORDER BY `orders`.`order_id`  ASC");


	 if ($orders_result) {
    while ($row = $orders_result->fetchAssoc()) {
	
	$cur_order_id = $row['order_id'];
	$cur_rev_id = $row['revision_id'];
	$cur_cust_id = $row['profile_id'];
	
	
	$insert_sql = "INSERT INTO `main_field_data_commerce_customer_billing` (
					`entity_type` ,
					`bundle` ,
					`deleted` ,
					`entity_id` ,
					`revision_id` ,
					`language` ,
					`delta` ,
					`commerce_customer_billing_profile_id`
					)
					VALUES (
					'commerce_order', 'commerce_order', '0', '{$cur_order_id}', '{$cur_rev_id}', 'und', '0', '{$cur_cust_id}'
					)";
		
		db_query($insert_sql);
		
		//drupal_set_message('Updated order id '.$cur_order_id);
		
	}
  }
leducdubleuet’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I applied the patch in #5 manually and it is solving this issue!
Thx a lot to ben.hamelin!

ronald_istos’s picture

Status: Reviewed & tested by the community » Fixed

committed - thanks Ben and all!

ronald_istos’s picture

Status: Fixed » Closed (fixed)
wahavi’s picture

Sorry to open this old issue, but the issue exists in Rooms 1.15, Drupal 7.69.
To reproduce the issue:
- click on bookable day in calendar (/admin/rooms/units/bulk_unit_management)
- click on link: Create @booking_type
- choose existing customer (or create new)
- save booking
- navigate to bookings views: /admin/rooms/bookings
- search for the booking now created (i.e. set booking_id order to descending)
Find that the recently created order/booking has order_id = 0, and customer profile url with wrong id (although the commerce customer HAS an id which is different from this)
Please take a look at it if you have time.
Thanks for you help!