protected function PixelSubscriber::addItem in Simple Facebook Pixel 8
Adds an event.
Parameters
\Drupal\commerce\PurchasableEntityInterface $product_variation: The product variation.
float $quantity: The quantity added.
string $event_name: The Facebook Pixel event name.
3 calls to PixelSubscriber::addItem()
- PixelSubscriber::addToCartEvent in src/
EventSubscriber/ PixelSubscriber.php - Adds AddToCart event.
- PixelSubscriber::addToWishlist in src/
EventSubscriber/ PixelSubscriber.php - Adds AddToWishlist event. Using Commerce Wishlist module.
- PixelSubscriber::addToWishlistFlag in src/
EventSubscriber/ PixelSubscriber.php - Adds AddToWishlist event. Using Flag module.
File
- src/
EventSubscriber/ PixelSubscriber.php, line 173
Class
- PixelSubscriber
- Class PixelSubscriber.
Namespace
Drupal\simple_facebook_pixel\EventSubscriberCode
protected function addItem($product_variation, $quantity, $event_name) {
$contents[] = [
'id' => $product_variation
->getSku(),
'quantity' => $quantity,
];
$context = new Context($this->currentUser, $this->currentStore
->getStore());
$resolved_price = $this->chainPriceResolver
->resolve($product_variation, 1, $context);
$data = [
'content_name' => $product_variation
->getProduct()
->getTitle(),
'content_type' => 'product',
'content_ids' => [
$product_variation
->getSku(),
],
'value' => $resolved_price
->getNumber(),
'currency' => $resolved_price
->getCurrencyCode(),
'contents' => $contents,
];
$this->pixelBuilder
->addEvent($event_name, $data, TRUE);
}