Problem/Motivation

The current architecture and implementation with final plugin classes and duplicated and different implementations to build the order items makes it really hard to customize them, which is a common use case for things like category, see also #3392918: Add category to the item object for ecommerce tracking.

Steps to reproduce

Proposed resolution

Unify the creation of the order item in a method on the trait, trigger an event

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork google_tag-3410273

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review

Introduced a method on the trait used it on all events where it makes sense, only exception is commerce_view_item_list, which calls it item but it's a product variation.

Also added an event and a test that verifies it works.

MR needs work on docs and trait doesn't use DI, that's a bit awkward as every plugin class would need to do the whole DI dance, probably even with BC?

newaytech’s picture

Fantastic @Berdir - thanks for the contrib...

berdir’s picture

Fixed a missing use. Not sure why it's still a Build Successful and not a pass, https://dispatcher.drupalci.org/job/drupal_contrib/724221/console seems OK to me.

berdir’s picture

I pushed a few updates. I didn't realize that $item is sometimes an order item and sometimes it's actually a product variation. The naming really doesn't help there.

So there are now two methods on the trait and two events. Still would like some first feedback before finishing this up with comments and so on.

japerry’s picture

On first glance this looks great! Waiting to see if I can get the new test suite to pass, I committed some changes a week ago that fixed tests for Drupal 10.

rszrama’s picture

Issue tags: +Deprecate Commerce GTM
Related issues: +#3358305: Add alter event processing to collector

Tagging and cross-referencing #3358305: Add alter event processing to collector as one or the other (or both?) of these approaches will be needed. A more general solution for altering event data seems to make sense, though ... for example, determining what coupon code should be present on a purchase event when multiple coupon codes have been applied to an order.

cyberwolf made their first commit to this issue’s fork.

loze made their first commit to this issue’s fork.

primsi made their first commit to this issue’s fork.

primsi’s picture

Issue tags: -

Updating mr to address php 8.4 deprecations

FILE: ...trib/google_tag/src/Plugin/GoogleTag/Event/Commerce/CommerceEventTrait.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
--------------------------------------------------------------------------------
  81 | WARNING | Implicitly marking a parameter as nullable is deprecated since
     |         | PHP 8.4. Update the type to be explicitly nullable instead.
     |         | Found implicitly nullable parameter: $affiliation.
 109 | WARNING | Implicitly marking a parameter as nullable is deprecated since
     |         | PHP 8.4. Update the type to be explicitly nullable instead.
     |         | Found implicitly nullable parameter: $affiliation.
--------------------------------------------------------------------------------