I have created a customized product with lots of attributes to set for it. I also altered hook_add_to_cart_form_submit() where I collect all selected attributes and calculate a new price based on the selected and configured attributes. So in my
function MYMODULE_add_to_cart_form_submit($form, &$form_state) {}
I create a big array and:
if (empty($form_state['line_item']->line_item_id)) {
if ($attributes)
$form_state['line_item']->data['context']['attributes'] = $attributes;
$line_item = commerce_product_line_item_new($product, $form_state['values']['quantity'], 0, $form_state['line_item']->data, $form_state['line_item']->type);
// ...
}
I'm not sure if I am doing it right, I just want to store that array in the line-item table. While adding product to cart randomly I get:
"PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_line_item-177-0-0-und' for key 'PRIMARY': INSERT INTO {field_data_commerce_unit_price} ..."
error. Should I use some special format for this $attribute array? Everything is stored as BLOB in commerce_line_item.data field.