From df0662ae5f97cc263dea89dcb599adde560309f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Tue, 10 Sep 2024 10:07:51 +0200 Subject: [PATCH] Check if we can reset before doing it --- src/EventListener/Doctrine/ProductListener.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/EventListener/Doctrine/ProductListener.php b/src/EventListener/Doctrine/ProductListener.php index 5eacfda..5284cdb 100644 --- a/src/EventListener/Doctrine/ProductListener.php +++ b/src/EventListener/Doctrine/ProductListener.php @@ -55,7 +55,13 @@ private function handle(LifecycleEventArgs $eventArgs): void Assert::isInstanceOf($variant, ProductVariantInterface::class); $uploadProductVariantRequest = $variant->getPeakUploadProductVariantRequest() ?? $this->uploadProductVariantRequestFactory->createNew(); - $this->uploadProductVariantRequestWorkflow->apply($uploadProductVariantRequest, UploadProductVariantRequestWorkflow::TRANSITION_RESET); + + if ($this->uploadProductVariantRequestWorkflow->can($uploadProductVariantRequest, UploadProductVariantRequestWorkflow::TRANSITION_RESET)) { + $this->uploadProductVariantRequestWorkflow->apply( + $uploadProductVariantRequest, + UploadProductVariantRequestWorkflow::TRANSITION_RESET, + ); + } $variant->setPeakUploadProductVariantRequest($uploadProductVariantRequest); }