-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwagTestPlugin.php
158 lines (120 loc) · 4.17 KB
/
SwagTestPlugin.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
namespace SwagTestPlugin;
use PDO;
use Shopware\Bundle\StoreFrontBundle\Struct\ShopContext;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UninstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
use sOrder;
use Symfony\Component\HttpKernel\HttpCache\Store;
use Zend_Db_Statement_Pdo;
class SwagTestPlugin extends Plugin
{
public function install(InstallContext $context)
{
$this->createAttributes('feld1');
}
/**
* @param UpdateContext $context
*/
public function update(UpdateContext $context)
{
parent::update($context);
$this->createAttributes('feld2');
}
public static function getSubscribedEvents()
{
return [
];
}
public function onFilterExportResult(\Enlight_Event_EventArgs $args)
{
$articles = $args->getReturn();
/** This is the id of the feed being exported */
$feedId = $args->get('feedId');
/** @var \sExport $sExport */
$sExport = $args->get('subject');
/**
* Here is the instance of the export class which can be used to add new variables to smarty
*/
$sExport->sSmarty->assign('newVariable', ['custom' => 'This is a custom variable available in the export template']);
/**
* in $sArticles are all the articles as array which we can modify here
*/
foreach($articles as &$article) {
$article['specialArgument'] = random_int(1, 100);
}
return $articles;
}
public function testDispatch(\Enlight_Event_EventArgs $args)
{
}
public function onBlogPostDispatch(\Enlight_Controller_ActionEventArgs $args)
{
/** @var \Shopware_Controllers_Frontend_Blog $subject */
$subject = $args->getSubject();
if ($subject->Request()->getActionName() !== 'detail') {
return;
}
$blogArticle = $subject->Request()->getParam('blogArticle');
$view = $subject->View();
$view->addTemplateDir($this->getPath() . '/Resources/views');
if ($blogArticle == '3') {
$view->loadTemplate($this->getPath() . '/Resources/views/frontend/blog/my_detail.tpl');
}
}
public function onTest()
{
die('neu');
}
public function prozessDetails(\Enlight_Event_EventArgs $args)
{
Shopware()->Container()->get('shopware.api.order');
$orderId = $args->get('orderId');
$models = $this->container->get('models');
$api = Shopware()->Container()->get('shopware.api.order');
$api->setManager($models);
}
public function orderUpdate(\Enlight_Event_EventArgs $args)
{
$modelManager = $args->get('entityManager');
/** @var \Shopware\Models\Order\Order $model */
$model = $args->get('entity');
$this->container->get('template')->addTemplateDir(
$this->getPath()
);
}
public function event(\Enlight_Event_EventArgs $args)
{
/** @var Zend_Db_Statement_Pdo $result */
$result = $args->getReturn();
return $result;
}
public function onPostDispatch(\Enlight_Controller_ActionEventArgs $args)
{
$view = $args->getSubject()->View();
$session = $this->container->get('session');
$basket = Shopware()->Modules()->Basket();
if($session->get('sNotesQuantity')) {
$view->assign('sNotesQuantity', $session->get('sNotesQuantity'));
} else {
$view->assign('sNotesQuantity', $basket->sCountNotes());
}
}
public function onBeforeSaveOrder(\Enlight_Hook_HookArgs $args)
{
/** @var \sOrder $subject */
$subject = $args->getSubject();
$subject->orderAttributes['meinattribut'] = '15. September';
}
private function createAttributes($field)
{
$crud = Shopware()->Container()->get('shopware_attribute.crud_service');
$crud->update('s_articles_attributes', $field, 'string', [
'translatable' => true,
'displayInBackend' => true,
'label' => $field
], null, true);
}
}