A default product variation is expected in commerce_google_tag_manager_commerce_product_view and fails if none is available, but it is valid that a product has no (active) product variation.

Comments

archnode created an issue. See original summary.

archnode’s picture

Status: Active » Needs review
StatusFileSize
new1.12 KB

Attached patch adds a check for default variation.

wengerk’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Hey archnode !

Thanks for your contribution, could you write a test for the use case ?
Then upload a version with test-only just to demonstrate the tests works as intend to.

Thanks again for you help on the project.

finex’s picture

Hi, the bug is still reproducible, the patch provided is not enough because a product variation is required by EventTrackerService::buildProductFromProductVariation.

This is the error:

[Thu Feb 14 00:22:59.912638 2019] [proxy_fcgi:error] [pid 26869:tid 140559034906368] [client 79.16.181.224:44206] AH01071: Got error 'PHP message: TypeError: Argument 1 passed to Drupal\\commerce_google_tag_manager\\EventTrackerService::buildProductFromProductVariation() must implement interface Drupal\\commerce_product\\Entity\\ProductVariationInterface, null given, called in /var/www/example/web/modules/contrib/commerce_google_tag_manager/src/EventTrackerService.php on line 338 in /var/www/example/web/modules/contrib/commerce_google_tag_manager/src/EventTrackerService.php on line 294 #0 /var/www/example/web/modules/contrib/commerce_google_tag_manager/src/EventTrackerService.php(338): Drupal\\commerce_google_tag_manager\\EventTrackerService->buildProductFromProductVariation(NULL)\n#1 [internal function]: Drupal\\commerce_google_tag_manager\\EventTrackerService->Drupal\\commerce_google_tag_manager\\{closure}(NULL)\n#2 /var/www/example/web/modules/contrib/commerce_google_tag_manager/src/EventTrackerService.php(340): array_map(Object(Closure), Array)\n#3 /var/www/example/web/modules/contrib/co...\n', referer: https://stag.example.com/product/18/variations
chrissnyder’s picture

Patch #2 worked for me.

sittard’s picture

Patch #2 worked for me as well.

Could we get this rolled out. Thanks.

schtifu’s picture

Status: Needs work » Needs review

Thanks for the feedback guys. I opened a pull request which adds the patch from archnode and an additional test case. Should be merged soon: https://www.drupal.org/project/commerce_google_tag_manager/issues/3020256

Cheers

wengerk’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Nice work !

You all rock 💪

We will merge today

wengerk’s picture

schtifu’s picture

Status: Reviewed & tested by the community » Fixed

Fixed with the alpha-2 release coming in a few minutes.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.