-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomerPdfEvent.php
62 lines (54 loc) · 1.53 KB
/
CustomerPdfEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Author: Dung Le Quoc
* Email: [email protected]
* Date: 11/5/2018
* Time: 2:30 PM
*/
namespace Plugin\CustomerPdf;
use Eccube\Application;
use Eccube\Event\TemplateEvent;
/**
* Class OrderPdf Event.
*/
class CustomerPdfEvent
{
protected $app;
/**
* CustomerPdfEvent constructor.
* @param $app
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Event for new hook point.
*
* @param TemplateEvent $event
*/
public function onMypageHistoryRender(TemplateEvent $event)
{
$source = $event->getSource();
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
$insertPart = $twig->getLoader()->getSource('CustomerPdf/Resource/template/default/Mypage/mypage_pdf_button.twig');
$newSource = str_replace('{% endblock %}', $insertPart.'{% endblock %}', $source);
$event->setSource($newSource);
}
/**
* @param TemplateEvent $event
*/
public function onShoppingIndexRender(TemplateEvent $event)
{
if (!$this->app->isGranted('ROLE_USER')) {
return;
}
$source = $event->getSource();
/** @var \Twig_Environment $twig */
$twig = $this->app['twig'];
$insertPart = $twig->getLoader()->getSource('CustomerPdf/Resource/template/default/Shopping/shopping_pdf_button.twig');
$newSource = str_replace('{% endblock %}', $insertPart.'{% endblock %}', $source);
$event->setSource($newSource);
}
}