The following error happens:
Warning: htmlspecialchars() expects parameter 1 to be string, array given in includes/bootstrap.inc on line 1567
on AJAX when clicking wheel settings icon on Manage Display (on Product display and 'Product Type'/Add to Cart Form).
Affected code in commerce_cart.module:
$summary[] = t('Add to Cart line item type: @type', array('@type' => commerce_line_item_type_get_name($settings['line_item_type'])));
It seems that the commerce_line_item_type_get_name() is returning array instead of the string causing issues in check_plain().
Input:
[2]=>
array(4) {
["file"]=>
string(113) "modules/cart/commerce_cart.module"
["line"]=>
int(2541)
["function"]=>
string(1) "t"
["args"]=>
array(2) {
[0]=>
&string(33) "Add to Cart line item type: @type"
[1]=>
&array(1) {
["@type"]=>
array(5) {
["commerce_coupon"]=>
string(6) "Coupon"
["training_bundle"]=>
string(15) "Training bundle"
["bundle"]=>
string(11) "Bundle Item"
["product"]=>
string(7) "Product"
["commerce_webform"]=>
string(16) "Commerce webform"
}
}
}
}
It seems 0 value is passed into commerce_line_item_type_get_name() causing to return array instead of string.
$settings = array(5) {
["show_quantity"]=>
int(0)
["default_quantity"]=>
int(1)
["combine"]=>
int(0)
["show_single_product_attributes"]=>
int(0)
["line_item_type"]=>
int(0)
}
Comments
Comment #1
kenorb commentedComment #2
kenorb commented.
Comment #3
kenorb commentedComment #4
kenorb commentedHere is $display value before generating the $settings via:
Whole $instance variable:
So the source of the problem is ["line_item_type"]=> int(0) somewhere in field settings. But I'm not sure which settings can be wrong.
My product display field (field_commerce_extension_pack ) is Product reference type displayed as Check boxes.
But the same happening for field_product_type which is Product reference displayed as Select list.
And even for General image (field_general_image) which is Image field.
Comment #5
kenorb commentedProposed patch:
Comment #6
ordermind commentedPatch works for me.
Comment #7
ordermind commentedAttaching patch.
Comment #8
ordermind commentedSorry, the above patch file doesn't seem to be working. Here's one that does.
Comment #10
rszrama commentedTagging for http://contribkanban.com/#/board/commerce/7.x-1.x.
We prefer !empty() checks for array values to catch the case of unset keys.
Comment #11
joelpittet!empty added.
Comment #12
joelpittetSince we are working on the cart.
Comment #13
rszrama commentedOne thought I had here, too, is instead of just not showing the label for the field formatter's line item type, we could default to 'product' as done in commerce_cart_field_formatter_view():
So instead of checking !empty($settings['line_item_type']) and bailing in the patch, we could check for it and use 'product' if it isn't set. What do you think?
Sorry, I wish I hadn't made this so hacky to begin with. ; )
Comment #14
joelpittetAgreed, +1 for consistency
Comment #15
rszrama commentedStellar. I wish the underlying API was better, but this is probably as good as it can be in the meantime. : )
Comment #17
joelpittetEasier to refactor if they are same same;)