Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid issues with missing variations. #13

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/EventTrackerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,24 @@ private function buildProductFromOrderItem(OrderItemInterface $orderItem) {
/**
* Build the Enhanced Ecommerce product from a given commerce product variation.
*
* @param \Drupal\commerce_product\Entity\ProductVariationInterface $productVariation
* @param \Drupal\commerce_product\Entity\ProductVariationInterface|null $productVariation
* A commerce product variation.
* @return \Drupal\commerce_google_tag_manager\Product
* The Enhanced Ecommerce product.
*/
private function buildProductFromProductVariation(ProductVariationInterface $productVariation) {
private function buildProductFromProductVariation($productVariation) {
$product = new Product();
$product
->setName($productVariation->getProduct()->getTitle())
->setId($productVariation->getProduct()->id())
->setVariant($productVariation->getTitle())
->setPrice($this->formatPrice((float) $productVariation->getPrice()->getNumber()));

$event = new AlterProductEvent($product, $productVariation);
$this->eventDispatcher->dispatch(EnhancedEcommerceEvents::ALTER_PRODUCT, $event);

if ($productVariation) {
$product
->setName($productVariation->getProduct()->getTitle())
->setId($productVariation->getProduct()->id())
->setVariant($productVariation->getTitle())
->setPrice($this->formatPrice((float) $productVariation->getPrice()->getNumber()));

$event = new AlterProductEvent($product, $productVariation);
$this->eventDispatcher->dispatch(EnhancedEcommerceEvents::ALTER_PRODUCT, $event);
}

return $product;
}
Expand Down