1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by the developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusShippingExportPlugin\Controller; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusShippingExportPlugin\Event\ExportShipmentEvent; |
16
|
|
|
use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface; |
17
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\ResourceController; |
18
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
final class ShippingExportController extends ResourceController |
23
|
|
|
{ |
24
|
|
|
/** @var ShippingExportRepositoryInterface */ |
25
|
|
|
protected $repository; |
26
|
|
|
|
27
|
|
|
public function exportAllNewShipmentsAction(Request $request): RedirectResponse |
28
|
|
|
{ |
29
|
|
|
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
30
|
|
|
|
31
|
|
|
$shippingExports = $this->repository->findAllWithNewState(); |
32
|
|
|
|
33
|
|
|
if (0 === count($shippingExports)) { |
34
|
|
|
$this->addFlash('error', 'bitbag.ui.no_new_shipments_to_export'); |
35
|
|
|
|
36
|
|
|
return $this->redirectToReferer($request); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
foreach ($shippingExports as $shippingExport) { |
40
|
|
|
$this->eventDispatcher->dispatch( |
41
|
|
|
ExportShipmentEvent::SHORT_NAME, |
42
|
|
|
$configuration, |
43
|
|
|
$shippingExport |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->redirectToReferer($request); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function exportSingleShipmentAction(Request $request): RedirectResponse |
51
|
|
|
{ |
52
|
|
|
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
53
|
|
|
|
54
|
|
|
$shippingExport = $this->repository->find($request->get('id')); |
55
|
|
|
Assert::notNull($shippingExport); |
56
|
|
|
|
57
|
|
|
$this->eventDispatcher->dispatch( |
58
|
|
|
ExportShipmentEvent::SHORT_NAME, |
59
|
|
|
$configuration, |
60
|
|
|
$shippingExport |
|
|
|
|
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
return $this->redirectToReferer($request); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function redirectToReferer(Request $request): RedirectResponse |
67
|
|
|
{ |
68
|
|
|
$referer = $request->headers->get('referer'); |
69
|
|
|
if (null !== $referer) { |
|
|
|
|
70
|
|
|
return new RedirectResponse($referer); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->redirectToRoute($request->attributes->get('_route')); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|