Hi,
i finally flipped out from Ubercart and got my hands in Drupal Commerce to gain the Drupal's core systems integration and it's pretty good !
The customer profile system seems to be really cool but i'm stuck with this non-negligeable error and i can't go further without having it resolved :

- I start to create a customer profile, and fill in all the required fields that are in this profile. So far all is up and running well.
- Then i want to modify this customer profile, and if i change any value of the fields or even the "owner profile" field (which is declared as a default field of the customer_profile entity), it throws me this error :

PDOException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) AND (field_data_commerce_customer_billing0.entity_type = 'commerce_order') ) ' at line 2: SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM {field_data_commerce_customer_billing} field_data_commerce_customer_billing0 INNER JOIN {commerce_order} commerce_order ON commerce_order.order_id = field_data_commerce_customer_billing0.entity_id WHERE (field_data_commerce_customer_billing0.commerce_customer_billing_profile_id = :db_condition_placeholder_0) AND (field_data_commerce_customer_billing0.deleted = :db_condition_placeholder_1) AND (commerce_order.status NOT IN ()) AND (field_data_commerce_customer_billing0.entity_type = :db_condition_placeholder_2) ) subquery; Array ( [:db_condition_placeholder_0] => 3 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => commerce_order ) dans field_sql_storage_field_storage_query() (line 568 in (...)/modules/field/modules/field_sql_storage/field_sql_storage.module).

Note that when i remove all custom fields of the customer profile (so there is only the default fields left, i.e. the owner of the profile and the status), i can save successfully the changes i make in these fields.

Note also that if i don't change anything in the customer profile, i can save the modifications without error (i guess the entity module finds out nothing has been changed and choose not to interact with the database at all).

I started digging but my knowledge in the entity api isn't really deep. So far i found that the problem pass (pretty logically) through the function commerce_customer_profile_save in the commerce_customer.module, line 374 :

function commerce_customer_profile_save($profile) {
  return entity_get_controller('commerce_customer_profile')->save($profile);
}

I tried to comment out the line and there was no error anymore, but obviously changes were not updated.
I also tried to replace it by a simple return entity_save($profile); and it had surprisingly the same behaviour as if there was nothing, i. e. no error but no update either.

I don't know how to debug the $profile object that is passed in parameter as the function can't ouput any drupal_set_message, nor dprint_r functions.
The devel module didn't help me much either, as the bad request is not visible in the devel query log.

Any idea ?

Comments

rszrama’s picture

Status: Active » Fixed

Ahh, ok. Took me a while to reproduce this because I always have Cart / Checkout enabled. What tipped me off is that the syntax error in that query is related to the fact that we're doing a NOT IN () check on an order status, but there's nothing in the IN (). : P

I recently added code to prevent the errant deletion or overwriting of a customer profile that has been referenced by a non-cart order. Unfortunately I didn't check to make sure there was such a thing as a shopping cart status before adding that as a condition to my query.

Commit: http://drupalcode.org/project/commerce.git/commitdiff/d154b38

ben kuper’s picture

I must say, i'm impressed by your analyse !
Yeah, i didn't activated them (and i should have mentionned it, personal note for the next time !) because i need the customer just to receive bills and to pay, not to choose their product (the admin creates the bills and the customer just receive a mail telling that they must pay).

Thank you, will try this and post some news !

ben kuper’s picture

Works like a charm. Thanks man !

rszrama’s picture

Great, thanks for testing it out. : )

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.