From 221b79b0366ff3e0f37959f4002ab7f69193e8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Wed, 6 Dec 2023 14:44:15 +0100 Subject: [PATCH] Fix null pointer exception possibility --- src/Form/Extension/AddToCartTypeExtension.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Form/Extension/AddToCartTypeExtension.php b/src/Form/Extension/AddToCartTypeExtension.php index b494d964..7bebfcee 100644 --- a/src/Form/Extension/AddToCartTypeExtension.php +++ b/src/Form/Extension/AddToCartTypeExtension.php @@ -53,8 +53,13 @@ public function reworkFormForGiftCard(FormEvent $event): void return; } + $variant = $data->getCartItem()->getVariant(); + if (null === $variant) { + return; + } + /** @var ProductInterface|null $product */ - $product = $data->getCartItem()->getProduct(); + $product = $variant->getProduct(); if (null === $product) { return; }