With the meta tag module enabled I can now not save products, instead it just returns to the product page without saving it. The problem is caused by the use of array union (+) in commerce_product_product_form when setting the submit handler for the submit button. If a previous module has already set a submit handler then this function attempts to add the product form submit handler using '#submit' => $submit + array('commerce_product_product_form_submit') but since both arrays use the default key 0 the union ignores the second array value. This should use array_merge rather than array union.

CommentFileSizeAuthor
#1 1532026-1.patch710 bytesjoshmiller

Comments

joshmiller’s picture

Status: Active » Needs review
StatusFileSize
new710 bytes

Attached is a patch that does what the description above recommends. No idea if it works or really solves the problem :)

Josh

rszrama’s picture

Hmm, interesting. This issue came up before in the Meta tags queue, and the solution never seemed as simple as this.

#1286122: Incompatibility with Commerce

Is there nothing more to be done, like in our entity info hooks or anything?

dippers’s picture

This is definetly a bug, array union should not be used on unassociated arrays as the keys are going to clash and in this case the left hand (current value) takes precedence and the right hand is ignored. I can see no reason that the two submit handlers cannot coexist, it's just at the moment the commerce_product_product_form_submit handler is never added to the form.

You might be right that metatags is overzealous in appearing on every entity form but it seems to work quite happily alongside commerce product with this fix in place.

dippers’s picture

I should add that metatags is currently 'patched' to add its submit handlers in hook_form_alter rather than hook_field_attach_form to get around a problem in core so this issue may reoccurr if/when metatags reverts to hook_field_attach_form.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

I cannot reproduce the initial bug of not being able to save commerce products (with latest metatag, entity api, etc.) but the reasoning and the patch from #1 sounds sane :)

rszrama’s picture

Title: Product not saved with meta tag module enabled » Do not use the array union operator on non-associative arrays
Status: Reviewed & tested by the community » Fixed

A quick grep -rn "+ array(" * turns up this problem on the forms for customer profiles and orders as well. The rest all appear to be unions of associative arrays (price data arrays, permissions arrays, and form arrays). I went ahead and patched 'em all. There may be some leftover that joined non-associative arrays through two variables, but I'm not sure how to best grep for those. This should be good for now.

Commit: http://drupalcode.org/project/commerce.git/commitdiff/93ecb9e

mr.baileys’s picture

Status: Fixed » Closed (fixed)

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