when juggling with #1159162: reference a coupon with a commercial product i found a code flaw
the idea is that when a commerce_coupon entity is saved, and has no coupon code, some is autogenerated.
this is a key to coupon generation with rules.
some code review suggests that this can't work, because
* what is done in commerce_coupon_save()
* must be done in a hook_entity_presave()
because entity_save() does not care about save callback if entity class has a save callback as crud entity has.
so commerce_coupon_save is never called on a $coupon->save()
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 0001-fixed-1369138-by-axel.rutz-generation-of-coupon-code.patch | 2.87 KB | geek-merlin |
| #1 | 0001-fixed-1369138-by-axel.rutz-generation-of-coupon-code.patch | 1.98 KB | geek-merlin |
Comments
Comment #1
geek-merlinso the right thing to do is use hook_entity_presave
attached patch does this and fixes #1159162: reference a coupon with a commercial product for me
Comment #2
geek-merlinps: in fact the patch is a 3-liner, it just looks big because a dozen lines had to be indented
Comment #3
geek-merlinerps, now it's complete.
Comment #4
fagoI'd suggest implementing that in your entity class' save() method, then just call parent::save().
Comment #5
fagoIf using the hook, it should be hook_commerce_coupoin_presave(). Still, the superb solution is as outline in #4 .
Comment #6
geek-merlindid it therightway(tm) and committed.