1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller; |
4
|
|
|
|
5
|
|
|
use App\Library\Rates\Model\Product; |
|
|
|
|
6
|
|
|
use ControleOnline\Entity\Device; |
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
8
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
10
|
|
|
use ControleOnline\Entity\Order; |
11
|
|
|
use ControleOnline\Service\HydratorService; |
|
|
|
|
12
|
|
|
use ControleOnline\Service\OrderProductService; |
13
|
|
|
use Exception; |
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
|
15
|
|
|
|
16
|
|
|
class AddProductsOrderAction |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
public function __construct( |
21
|
|
|
private EntityManagerInterface $entityManager, |
22
|
|
|
private HydratorService $hydratorService, |
23
|
|
|
private OrderProductService $orderProductService |
24
|
|
|
|
25
|
|
|
) {} |
26
|
|
|
|
27
|
|
|
public function __invoke(Request $request, int $id): JsonResponse |
28
|
|
|
{ |
29
|
|
|
try { |
30
|
|
|
$order = $this->entityManager->getRepository(Order::class)->find($id); |
31
|
|
|
if (!$order) |
32
|
|
|
return new JsonResponse(['error' => 'Order not found'], 404); |
33
|
|
|
|
34
|
|
|
$data = json_decode($request->getContent(), true); |
35
|
|
|
|
36
|
|
|
foreach ($data as $p) { |
37
|
|
|
$product = $this->entityManager->getRepository(Product::class)->find($p['product']); |
38
|
|
|
$quantity = $p['quantity']; |
39
|
|
|
$price = $product->getPrice(); |
40
|
|
|
$this->orderProductService->addOrderProduct($order, $product, $quantity, $price); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$this->entityManager->refresh($order); |
44
|
|
|
|
45
|
|
|
return new JsonResponse($this->hydratorService->item(Order::class, $order->getId(), "order_details:read"), Response::HTTP_OK); |
46
|
|
|
} catch (Exception $e) { |
47
|
|
|
return new JsonResponse($this->hydratorService->error($e)); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
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