Skip to content

Commit

Permalink
Redirect to created invoice when accepting a quote (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Feb 21, 2019
1 parent b3bca29 commit 7eb85e2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/QuoteBundle/Action/Transition.php
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7eb85e2

Please sign in to comment.