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
|
|
|
* 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\SyliusInvoicingPlugin\Menu; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusInvoicingPlugin\Repository\InvoiceRepositoryInterface; |
16
|
|
|
use BitBag\SyliusInvoicingPlugin\Resolver\CompanyDataResolverInterface; |
17
|
|
|
use Knp\Menu\ItemInterface; |
18
|
|
|
use Sylius\Bundle\AdminBundle\Event\OrderShowMenuBuilderEvent; |
19
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
20
|
|
|
|
21
|
|
|
final class DownloadInvoiceMenuBuilder |
22
|
|
|
{ |
23
|
|
|
/** @var InvoiceRepositoryInterface */ |
24
|
|
|
private $invoiceRepository; |
25
|
|
|
|
26
|
|
|
/** @var InvoiceRepositoryInterface */ |
27
|
|
|
private $companyDataResolver; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
InvoiceRepositoryInterface $invoiceRepository, |
31
|
|
|
CompanyDataResolverInterface $companyDataResolver |
32
|
|
|
) { |
33
|
|
|
$this->invoiceRepository = $invoiceRepository; |
34
|
|
|
$this->companyDataResolver = $companyDataResolver; |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function addItem(OrderShowMenuBuilderEvent $orderShowMenuBuilderEvent): void |
38
|
|
|
{ |
39
|
|
|
/** @var OrderInterface $order */ |
40
|
|
|
$order = $orderShowMenuBuilderEvent->getOrder(); |
41
|
|
|
|
42
|
|
|
if (null === $this->invoiceRepository->findByOrderId($order->getId())) { |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$menu = $orderShowMenuBuilderEvent->getMenu(); |
47
|
|
|
|
48
|
|
|
if (null === $this->companyDataResolver->resolveCompanyData()) { |
49
|
|
|
$this->addNoCompanyDataInfoMenuItem($menu); |
50
|
|
|
|
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->addDownloadInvoiceMenuItem($menu, $order); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function addNoCompanyDataInfoMenuItem(ItemInterface $menu): void |
58
|
|
|
{ |
59
|
|
|
$menu |
60
|
|
|
->addChild('download_invoice', [ |
61
|
|
|
'route' => 'bitbag_sylius_invoicing_plugin_admin_company_data_index', |
62
|
|
|
]) |
63
|
|
|
->setAttribute('type', 'link') |
64
|
|
|
->setLabel('bitbag_sylius_invoicing_plugin.ui.set_invoice_data') |
65
|
|
|
->setLabelAttribute('icon', 'warning') |
66
|
|
|
->setLabelAttribute('color', 'yellow') |
67
|
|
|
; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function addDownloadInvoiceMenuItem(ItemInterface $menu, OrderInterface $order): void |
71
|
|
|
{ |
72
|
|
|
$menu |
73
|
|
|
->addChild('download_invoice', [ |
74
|
|
|
'route' => 'bitbag_sylius_invoicing_plugin_download_order_invoice', |
75
|
|
|
'routeParameters' => ['orderTokenValue' => $order->getTokenValue()], |
76
|
|
|
]) |
77
|
|
|
->setAttribute('type', 'link') |
78
|
|
|
->setLabel('bitbag_sylius_invoicing_plugin.ui.download_invoice') |
79
|
|
|
->setLabelAttribute('icon', 'download') |
80
|
|
|
->setLabelAttribute('color', 'blue') |
81
|
|
|
; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.