From 6f8edf44cddb73d9724b069def6b46c3ebda4c64 Mon Sep 17 00:00:00 2001 From: Ben Bromley <74667456+Ben-Bromley@users.noreply.github.com> Date: Mon, 3 Oct 2022 12:44:02 +0100 Subject: [PATCH] fix accessing undefined array index (with fallback) --- Block/Richsnippet.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Block/Richsnippet.php b/Block/Richsnippet.php index 283f714..ff317be 100755 --- a/Block/Richsnippet.php +++ b/Block/Richsnippet.php @@ -47,8 +47,14 @@ public function autoRichSnippet() if ($current_product && $product_enabled) { $sku = $this->dataHelper->getProductSkus($current_product); + + $productAvailability = $this->availability(); + if (array_key_exists('is_in_stock', $current_product->getData('quantity_and_stock_status'))) { + $productAvailability = $this->availability($current_product->getData('quantity_and_stock_status')['is_in_stock']); + } + $product = [ - 'availability' => $this->availability($current_product->getData('quantity_and_stock_status')['is_in_stock']), + 'availability' => $productAvailability, 'price' => $current_product->getFinalPrice(), 'url' => $current_product->getProductUrl(), 'description' => $current_product->getMetaDescription(),