From ff22d4cf28aafaaa28d347f57dbff6d556cb6a31 Mon Sep 17 00:00:00 2001 From: Sebastian <41212477+S-Tian86@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:32:52 -0300 Subject: [PATCH] bugfix: Validate if quantity has changed It is necessary validate if quantity has change before to try to get the old and new values. --- .../InventoryLevelNotificationEventListener.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php b/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php index 7dbc59d..98e61e9 100644 --- a/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php +++ b/src/Synolia/Bundle/StockAlertBundle/EventListener/InventoryLevelNotificationEventListener.php @@ -63,8 +63,12 @@ public function postUpdate(): void protected function inventoryHasNewStock(PreUpdateEventArgs $args): bool { - $oldQuantity = floatval($args->getOldValue('quantity')); - $newQuantity = floatval($args->getNewValue('quantity')); + if (!$args->hasChangedField('quantity')) { + return false; + } + + $oldQuantity = (float) $args->getOldValue('quantity'); + $newQuantity = (float) $args->getNewValue('quantity'); return $oldQuantity <= 0 && $newQuantity > 0; }