From 7eb85e2f597db74dbd4c0c44170f9b772c2abe92 Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Thu, 21 Feb 2019 19:41:18 +0200 Subject: [PATCH] Redirect to created invoice when accepting a quote (#229) --- src/QuoteBundle/Action/Transition.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/QuoteBundle/Action/Transition.php b/src/QuoteBundle/Action/Transition.php index 8653b057e..43eb11182 100644 --- a/src/QuoteBundle/Action/Transition.php +++ b/src/QuoteBundle/Action/Transition.php @@ -16,9 +16,11 @@ use SolidInvoice\CoreBundle\Response\FlashResponse; use SolidInvoice\QuoteBundle\Entity\Quote; use SolidInvoice\QuoteBundle\Exception\InvalidTransitionException; +use SolidInvoice\QuoteBundle\Model\Graph; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Workflow\Marking; use Symfony\Component\Workflow\StateMachine; final class Transition @@ -45,10 +47,15 @@ public function __invoke(Request $request, string $action, Quote $quote) throw new InvalidTransitionException($action); } - $this->stateMachine->apply($quote, $action); + /** @var Marking $marking */ + $marking = $this->stateMachine->apply($quote, $action); $route = $this->router->generate('_quotes_view', ['id' => $quote->getId()]); + if ($marking->has(Graph::STATUS_ACCEPTED)) { + $route = $this->router->generate('_invoices_view', ['id' => $quote->getInvoice()->getId()]); + } + return new class($action, $route) extends RedirectResponse implements FlashResponse { /** * @var string