forked from shopware5/SwagAdditionalAttributes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bootstrap.php
125 lines (112 loc) · 3.29 KB
/
Bootstrap.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
<?php
/*
* (c) shopware AG <info@shopware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
class Shopware_Plugins_Backend_SwagAdditionalAttributes_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
/**
* Install SwagAdditionalAttributes
* Adds db-attributes swagattr21 - swagattr40
*
* @return bool
*/
public function install()
{
$this->subscribeEvent(
'Enlight_Controller_Action_PostDispatch_Backend_Article',
'onLoadArticle'
);
$this->subscribeEvent(
'Shopware_Modules_Articles_sGetArticlesByCategory_FilterSql',
'onFilterSql'
);
$this->subscribeEvent(
'Shopware_Modules_Articles_GetArticleById_FilterSQL',
'onFilterSql'
);
$this->subscribeEvent(
'Shopware_Modules_Articles_sGetProductByOrdernumber_FilterSql',
'onFilterSql'
);
$this->subscribeEvent(
'Shopware_Modules_Articles_GetPromotionById_FilterSql',
'onFilterSql'
);
for ($i = 21; $i <= 40; $i++) {
Shopware()->Models()->addAttribute(
's_articles_attributes',
'swag',
'attr'.$i,
'TEXT',
true
);
}
Shopware()->Models()->generateAttributeModels(array('s_articles_attributes'));
return true;
}
public function onLoadArticle(Enlight_Event_EventArgs $args)
{
$request = $args->getSubject()->Request();
$view = $args->getSubject()->View();
if ($request->getActionName() != "load") {
return;
}
$view->addTemplateDir($this->Path().'Views/');
$view->extendsTemplate('backend/swag_additional_attributes/article/model/attribute.js');
}
public function onFilterSql(Enlight_Event_EventArgs $args)
{
$sql = $args->getReturn();
$newSql = 'attr20,';
for ($i = 21; $i <= 40; $i++) {
$newSql .= 'swag_attr'.$i.',';
}
$sql = str_replace('attr20,', $newSql, $sql);
return $sql;
}
/**
* Returns the version of the plugin as a string
*
* @return string
*/
public function getVersion()
{
$info = json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR .'plugin.json'), true);
if ($info) {
return $info['currentVersion'];
} else {
throw new Exception('The plugin has an invalid version file.');
}
}
/**
* Returns the well-formatted name of the plugin
* as a sting
*
* @return string
*/
public function getLabel()
{
return 'Weitere Artikel-Attribute';
}
/**
* Returns the meta information about the plugin
* as an array.
* Keep in mind that the plugin description located
* in the info.txt.
*
* @return array
*/
public function getInfo()
{
return array(
'version' => $this->getVersion(),
'label' => $this->getLabel(),
'link' => 'http://www.shopware.de/',
'description' => file_get_contents($this->Path() . 'info.txt')
);
}
}