I have installed commerce and commerce_coupon, and commerce_coupon allows creating a submodule to provide a new type of coupon.
commerce_coupon provides 2 types of entity: coupon_type and coupon. The first provides the types of coupon that can be created, and the second provides the actual coupons that can be used, so it's possible to have more than one coupon of a particular type.
When I install my custom coupon type module, I get an error: "invalid text representation" which is caused because an insert is being made into the {metatag} table, into the entity_id field, and it's trying to insert a string instead of an integer. While coupons themselves have numeric ids, coupon_type only has a string for an id, which is where the error is coming from.
The part I'm unsure about is why metatag is trying to save data about coupon_type entities. It comes back to metatag_entity_update(), which will only try to call metatag_metatags_save() if the entity's metatag property is not empty. For some reason that I can't figure out, the coupon_type entity is having an empty array assigned to the metatag property.
I can work around this problem by changing if (isset($entity->metatags)) to if (!empty($entity->metatags)) and everything works fine. My real interest, however, is understanding why there is a metatag property on the entity to begin with. I can't seem to track this down in the code.
It's also worth noting that the commerce_coupon module installs two coupon_type entities by default, and does not suffer from this problem. However, all I've done is simply copy one of the modules, rename it, and add a couple of rules defaults to it, so functionally, it should be identical to the defaults provided by commerce_coupon.
I also uncovered #1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID which might be related. If it's related, I'm afraid I'm not sure how.
Comments
Comment #1
damienmckennaMetatag does not support entities that have string-based IDs, only numerical IDs. Also, it was changed a while ago so that only entities that are specifically enabled will show up with the Metatag options, so I don't see how the fields are even loading.
Please test with the latest -dev version, I'm quite certain you should not have this problem anymore.