1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* You can find more information about us on https://bitbag.io and write us |
7
|
|
|
* an email on [email protected]. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace BitBag\SyliusMolliePlugin\Resolver\Order; |
13
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Entity\OrderInterface; |
15
|
|
|
use Sylius\Component\Order\Context\CartContextInterface; |
16
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
17
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
18
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
19
|
|
|
|
20
|
|
|
final class PaymentCheckoutOrderResolver implements PaymentCheckoutOrderResolverInterface |
21
|
|
|
{ |
22
|
|
|
/** @var RequestStack */ |
23
|
|
|
private $requestStack; |
24
|
|
|
|
25
|
|
|
/** @var CartContextInterface */ |
26
|
|
|
private $cartContext; |
27
|
|
|
|
28
|
|
|
/** @var RepositoryInterface */ |
29
|
|
|
private $orderRepository; |
30
|
|
|
|
31
|
|
|
public function __construct( |
32
|
|
|
RequestStack $requestStack, |
33
|
|
|
CartContextInterface $cartContext, |
34
|
|
|
RepositoryInterface $orderRepository |
35
|
|
|
) { |
36
|
|
|
$this->requestStack = $requestStack; |
37
|
|
|
$this->cartContext = $cartContext; |
38
|
|
|
$this->orderRepository = $orderRepository; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function resolve(): OrderInterface |
42
|
|
|
{ |
43
|
|
|
$tokenValue = $this->requestStack->getCurrentRequest()->get('tokenValue'); |
44
|
|
|
|
45
|
|
|
$order = $this->orderRepository->findOneBy(['tokenValue' => $tokenValue]); |
46
|
|
|
|
47
|
|
|
if (!$order instanceof OrderInterface) { |
48
|
|
|
$order = $this->cartContext->getCart(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($order instanceof OrderInterface) { |
52
|
|
|
return $order; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
throw new NotFoundHttpException('Order was not found'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|