Skip to content

Fix: grouped events#30

Open
ahuininga-orisha wants to merge 21 commits into
developfrom
fix/grouped-events
Open

Fix: grouped events#30
ahuininga-orisha wants to merge 21 commits into
developfrom
fix/grouped-events

Conversation

@ahuininga-orisha

Copy link
Copy Markdown
Collaborator

fix/grouped-events — Grouped export product key resolution for events

Summary

  • Bug: When grouped export is enabled, Tweakwise requires product keys in simpleId-parentId format. All events (add to cart, add to wishlist, product view, purchase) were sending plain product IDs, causing incorrect tracking for configurable products.
  • Bumped tweakwise/magento2-tweakwise-export to ^7.8.3 to support the updated getTweakwiseId signature with an optional $groupCode parameter.

Core logic

  • Added resolveGroupedExportProductKey() to Helper/Data.php — handles configurable, simple-with-parent, and standalone simple products, returning the correct simpleId-parentId key when grouped export is on.
  • Extended getTweakwiseId() with an optional $groupCode parameter passed through to the export helper.

Add to Cart

  • Switched observer from checkout_cart_add_product_completecheckout_cart_product_add_after to get access to the quote_item for resolving simple/parent IDs.
  • AddToCart event now receives the Quote\Item and resolves the grouped key via qty_options.
  • Added tweakwise_event_handled request param to widget-triggered add-to-cart requests (Luma & Hyvä) to prevent the observer from double-firing.

Add to Wishlist

  • AddToWishlist now calls resolveGroupedExportProductKey() using the product's type ID.
  • Same tweakwise_event_handled guard added to the wishlist observer.

Product View

  • Product view event now uses resolveGroupedExportProductKey() instead of the plain product ID.

Purchase / Order

  • ViewModel/Event.php now maps order items to simpleId-parentId format when grouped export is enabled, pairing child and parent product IDs from order items.

DI / Plugin fixes

  • Converted virtualType plugin declarations for Cart and Wishlist customer data sections to concrete classes (AddEventDataToCartSection, AddEventDataToWishlistSection) to fix a DI resolution issue.
  • Fixed XML indentation in di.xml.

How to test

Prerequisites

  • Tweakwise JS module enabled and configured.
  • Grouped export enabled: Stores > Configuration > Tweakwise > Export > Grouped export.
  • At least one configurable product in the catalog.

1. Add to Cart — configurable product

  1. Open a configurable product page and select an option.
  2. Add to cart.
  3. On the next page load, check the browser console or network tab for the Tweakwise event payload.
  4. Verify productKey is in simpleId-parentId format (e.g. 10000500001-10000400001), not a plain ID.

2. Add to Wishlist — configurable product

  1. On a configurable product page, click "Add to Wishlist".
  2. Verify the addtowishlist event payload has a productKey in simpleId-parentId format.

3. Product View event

  1. Open a configurable product page.
  2. Verify the productView event fires with a productKey in simpleId-parentId format.

4. Purchase event

  1. Complete an order containing a configurable product.
  2. On the success page, verify the purchase event payload lists product keys in simpleId-parentId format.

5. No double-firing (Tweakwise widget add-to-cart)

  1. Use the Tweakwise category/search page to add a product via the widget.
  2. Confirm the addtocart event fires exactly once. The tweakwise js should trigger the event from the category/search lister pages. Not the observer.

6. Grouped export OFF

  1. Disable grouped export in the config.
  2. Repeat steps 1–4 and verify all product keys are plain IDs with no -parentId suffix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant