before: hook not triggering for product.variant events — intentional?
#652
Unanswered
sebastian-meckovski
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
We're building a Swell App that auto-calculates product prices from dimension attributes (
width/height) using abefore:product.updatedhook. It works great for products — the price merges into the saved record before it's written, so the UI reflects it immediately with no extra round-trip.We're now extending this to variants. We noticed that
product.variant.updatedandproduct.variant.createdfire correctly as async events, butbefore:product.variant.updated/before:product.variant.createddon't seem to trigger at all.Our question: Is this intentional, or a gap in the current implementation?
Variants appear to be their own collection (
products:variants) with the same field structure as products (they haveprice,purchase_options,$currency, etc.), so we'd expectbefore:hooks to work the same way. We can't find anything in the docs that explains the difference.Why
before:matters here specifically:Not a massive issue but...
Immediate UI consistency — With
before:, the calculated price is part of the same write. Any dependent fields in the admin UI (or the storefront) reflect the new value instantly. With asyncafter:, there's a window where the variant is saved with a stale/null price until the second write completes.Efficiency — Without
before:, we have to do a follow-upreq.swell.putto write the price back, which is (maybe?) an extra API call per variant save.Is there a workaround we're missing, or is
before:support for variant events on the roadmap?Thanks
Here's the function:
as soon as I prepend
before:to the events array items, it stops workingAll reactions