gridonic / commerce_google_tag_manager

Provides Commerce integration for Enhanced Ecommerce via Google Tag Manager
https://www.drupal.org/project/commerce_google_tag_manager
GNU General Public License v2.0
3 stars 3 forks source link

Avoid issues with missing variations. #13

Open grahl opened 6 years ago

grahl commented 6 years ago

Hello

I have a case where some product data can become inconsistent due to long running import jobs from the ERP. This can lead to a missing product variation. This function causes a fatal error in that case and the following change catches it.

WengerK commented 6 years ago

Instead of altering buildProductFromProductVariation, can we prevent to call this method when no product variation exists ? Before ?

Which was the parent calling buildProductFromProductVariation ? Was is the stacktrace ?

wanze commented 6 years ago

@grahl

Do you know when the exception occurs? I guess it happened when viewing a commerce_product entity without a default variation? In this case, the check should go here:

https://github.com/gridonic/commerce_google_tag_manager/blob/8.x-1.x/commerce_google_tag_manager.module#L39

I would also add the check for a missing reference a higher level - not entering the method buildProductFromProductVariation at all.

grahl commented 6 years ago

Hi @wanze

I noticed this on a product detail page with an invalid variation, not quite sure if the the field there was the "add to cart" formatter or the entity renderer.

I only did a cursory check where Both methods calling buildProductFromProductVariation() was being called and since both instances didn't look like a great place to check it I went further down. Though I understand your criticism.

Time permitting I'll try to recreate this and send the stacktrace.