Exception thrown when tracking commerce events

Created on 10 July 2023, over 1 year ago
Updated 28 January 2024, 10 months ago

Problem/Motivation

When this module's v2 is enabled and the user clicks the "Add to cart" button on any page for any product, the following exception is getting thrown:
TypeError: Drupal\simple_facebook_pixel\EventSubscriber\PixelSubscriber::addToCartEvent(): Argument #1 ($event) must be of type Symfony\Contracts\EventDispatcher\Event, Drupal\commerce_cart\Event\CartEntityAddEvent given in Drupal\simple_facebook_pixel\EventSubscriber\PixelSubscriber->addToCartEvent() (line 127 of modules/contrib/simple_facebook_pixel/src/EventSubscriber/PixelSubscriber.php).

Steps to reproduce

Enable the module. Go to a product and click the "Add to cart" button.

Proposed resolution

Replace the original class used for the commerce events with \Drupal\Component\EventDispatcher\Event since according to the documentation in that class file's comment:

/**
* Provides a forward-compatibility layer for the Symfony 5 event class.
*
* Symfony 5 relies on the Symfony\Contracts\EventDispatcher\Event class.
* In order to prepare for updates, code that wishes to extend Symfony's Event
* class should extend this intermediary class, which will handle switching
* from Symfony\Component to Symfony\Contracts without a further change.
*/

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇬🇷Greece vensires

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024