From 025cf42a0d7d090ec61a25a8e4176551d8f352b6 Mon Sep 17 00:00:00 2001 From: boo-code Date: Sat, 27 Jun 2026 06:25:58 +0200 Subject: [PATCH] Prevent fatal error when product template variable is a Product object HookDisplayFooterProduct::run() passes the 'product' Smarty variable straight to ProductWrapper::prepareItemFromProduct(), which accesses it with array keys. The variable is normally a ProductLazyArray (array-accessible), but some themes or modules assign a raw Product object, causing a fatal error "Cannot use object of type Product as array" on the product page. Guard against a non-array-accessible product and skip tracking in that case instead of breaking the whole product page. --- classes/Hook/HookDisplayFooterProduct.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/classes/Hook/HookDisplayFooterProduct.php b/classes/Hook/HookDisplayFooterProduct.php index dd97891..ea43824 100644 --- a/classes/Hook/HookDisplayFooterProduct.php +++ b/classes/Hook/HookDisplayFooterProduct.php @@ -54,6 +54,14 @@ public function run() return; } + // The 'product' template variable is expected to be a ProductLazyArray (array-accessible). + // Some themes or modules assign a raw Product object instead, which prepareItemFromProduct() + // cannot consume (it accesses array keys) and would raise a fatal error on the product page. + // Skip tracking in that case rather than breaking the page. + if (!is_array($product) && !$product instanceof \ArrayAccess) { + return; + } + // Initialize tag handler $gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);