|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
|
|
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
|
|
8
|
|
|
use ControleOnline\Entity\Order; |
|
9
|
|
|
use ControleOnline\Entity\People; |
|
|
|
|
|
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
|
|
11
|
|
|
use ControleOnline\Service\HydratorService; |
|
|
|
|
|
|
12
|
|
|
use ControleOnline\Service\StatusService; |
|
|
|
|
|
|
13
|
|
|
use Exception; |
|
14
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface |
|
|
|
|
|
|
15
|
|
|
as Security; |
|
16
|
|
|
|
|
17
|
|
|
class DiscoveryCart |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
private HydratorService $hydratorService, |
|
24
|
|
|
private EntityManagerInterface $manager, |
|
25
|
|
|
private StatusService $statusService, |
|
26
|
|
|
private Security $security |
|
27
|
|
|
) {} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function __invoke(Request $request): JsonResponse |
|
31
|
|
|
{ |
|
32
|
|
|
try { |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var \ControleOnline\Entity\People |
|
36
|
|
|
*/ |
|
37
|
|
|
$userPeople = $this->security->getToken()?->getUser()?->getPeople(); |
|
38
|
|
|
|
|
39
|
|
|
$providerId = $request->get('provider'); |
|
40
|
|
|
if (!$providerId) { |
|
41
|
|
|
return new JsonResponse(['error' => 'Provider é obrigatório'], Response::HTTP_BAD_REQUEST); |
|
42
|
|
|
} |
|
43
|
|
|
$provider = $this->manager->getRepository(People::class)->find($providerId); |
|
44
|
|
|
if (!$provider) { |
|
45
|
|
|
return new JsonResponse(['error' => 'Provider inválido'], Response::HTTP_BAD_REQUEST); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$order = null; |
|
49
|
|
|
if ($userPeople) { |
|
50
|
|
|
$status = $this->statusService->discoveryStatus('open', 'open', 'order'); |
|
51
|
|
|
|
|
52
|
|
|
$order = $this->manager->getRepository(Order::class)->findOneBy([ |
|
53
|
|
|
'client' => $userPeople, |
|
54
|
|
|
'provider' => $provider, |
|
55
|
|
|
'status' => $status |
|
56
|
|
|
]); |
|
57
|
|
|
|
|
58
|
|
|
if (!$order) { |
|
59
|
|
|
$order = new Order(); |
|
60
|
|
|
$order->setStatus($status); |
|
61
|
|
|
$order->setClient($userPeople); |
|
62
|
|
|
$order->setOrderType('order'); |
|
63
|
|
|
$order->setApp('SHOP'); |
|
64
|
|
|
$order->setProvider($provider); |
|
65
|
|
|
//$order->setPayer(); |
|
66
|
|
|
$this->manager->persist($order); |
|
67
|
|
|
|
|
68
|
|
|
$this->manager->flush(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return new JsonResponse($this->hydratorService->item(Order::class, $order->getId(), 'order_details:read'), Response::HTTP_OK); |
|
73
|
|
|
} catch (Exception $e) { |
|
74
|
|
|
return new JsonResponse($this->hydratorService->error($e)); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths