productDetailViews event is fired very rarely, because hook_entity_view is invoked only once after each cache rebuild.
Is it expected behavior?
I assume productDetailViews is expected to be fired on every product details page load.

Comments

zeuty created an issue. See original summary.

zeuty’s picture

StatusFileSize
new4.19 KB

Patch that fixes the issue by moving productDetailsView event generation from hook_entity_view to Kernel Request Event.

zeuty’s picture

StatusFileSize
new4.88 KB
wengerk’s picture

Status: Active » Needs work
wengerk’s picture

Hey Zeuty, Thanks for helping us on this issue !!

Do you need any help to update the tests ?

zeuty’s picture

StatusFileSize
new4.67 KB
zeuty’s picture

Status: Needs work » Needs review

Please review the patch.
Functionality change:
Earlier productDetailViews was fired in commerce_google_tag_manager_commerce_product_view (hook_entity_view implementation), which is not the right one for the event, as it is not executed on every product details page load.
In patch productDetailViews execution is moved to KernelEvents::REQUEST event subscriber, so we can guarantee that it is fired during every product details page load.

zeuty’s picture

StatusFileSize
new4.84 KB

Added some comments to clarify why priority 28 is used.

wengerk’s picture

Many thanks for your help !

I think, we should add a tests that show why the previous code didn't now works.
I mean:

  1. Create a tests that will fail using the old code & upload this here to ensure it fails properly as expected
  2. Porting this new tests in your patch and show it does not fails

Once done, we would be sure we close an important issue & we cover any regression on this.
What do you think ?

zeuty’s picture

@Wengerk, agreed, I will work on this.

wengerk’s picture

StatusFileSize
new2.26 KB
new8.41 KB
new9.15 KB

Hey guys, happy to finally got times get working on this issue !!

So here is a patch reroll, containing improvements and tests coverage !

I also upload a "should-fail" patch to ensure the bug has been covered.
Let's test all of that via testbot !

wengerk’s picture

Status: Needs review » Reviewed & tested by the community
wengerk’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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