-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOssCustomModel.php
More file actions
165 lines (148 loc) · 5.22 KB
/
OssCustomModel.php
File metadata and controls
165 lines (148 loc) · 5.22 KB
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
159
160
161
162
163
164
165
<?php
namespace OssCustomModel;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\DeactivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Doctrine\ORM\Tools\SchemaTool;
/**
* Shopware-Plugin OssCustomModel.
*/
class OssCustomModel extends Plugin
{
/**
* Adds the widget and create the database schema.
*
* @param Plugin\Context\InstallContext $installContext
*/
public function install(Plugin\Context\InstallContext $installContext)
{
parent::install($installContext);
try{
$this->createSchema();
$this->updateSchema();
}catch(\Exception $e){
/** @var \Shopware\Components\Logger */
Shopware()->Pluginlogger()->addError($e->getMessage());
}
}
/**
* @param ActivateContext $context
*/
public function activate(ActivateContext $context)
{
$context->scheduleClearCache( array( InstallContext::CACHE_LIST_ALL ) );
}
/**
* @param DeactivateContext $context
*/
public function deactivate(DeactivateContext $context)
{
$context->scheduleClearCache( array( InstallContext::CACHE_LIST_ALL ) );
}
/**
* Remove widget and remove database schema.
*
* @param Plugin\Context\UninstallContext $uninstallContext
*/
public function uninstall(Plugin\Context\UninstallContext $uninstallContext)
{
parent::uninstall($uninstallContext);
try{
$this->removeSchema();
$this->dropSchema();
}catch(\Exception $e){
/** @var \Shopware\Components\Logger */
Shopware()->Pluginlogger()->addError($e->getMessage());
}
}
/**
* @param ContainerBuilder $container
*/
public function build(ContainerBuilder $container)
{
$container->setParameter('oss_custom_model.plugin_dir', $this->getPath());
parent::build($container);
}
/**
* create schema
*/
private function createSchema()
{
$tool = new SchemaTool($this->container->get('models'));
$classes = [
$this->container->get('models')->getClassMetadata(\OssCustomModel\Models\CustomModel\CustomModel::class)
];
$tool->createSchema($classes);
}
/**
* remove schema
*/
private function removeSchema()
{
// TODO: uncomment
return ;
$tool = new SchemaTool($this->container->get('models'));
$classes = [
$this->container->get('models')->getClassMetadata(\OssCustomModel\Models\CustomModel\CustomModel::class)
];
$tool->dropSchema($classes);
}
/**
* add attributes for `Shop Pages`
*/
private function updateSchema()
{
$service = $this->container->get('shopware_attribute.crud_service');
$service->update('s_cms_static_attributes', 'custombanner', 'single_selection', [
'label' => Shopware()->Snippets()->getNamespace("backend/common/main")->get(
'custombannerField', 'Banner', true
),
'helpText' => Shopware()->Snippets()->getNamespace("backend/common/main")->get(
'custombannerDescrption', 'Landing Page Banner', true
),
'entity' => 'Shopware\Models\Media\Media',
'displayInBackend' => true,
'position' => 1
]);
$service->update('s_cms_static_attributes', 'position', 'combobox', [
'label' => Shopware()->Snippets()->getNamespace("backend/common/main")->get(
'positionField', 'Banner Position', true
),
'displayInBackend' => true,
'arrayStore' => [
['key' => 'top', 'value' => 'On Top'],
['key' => 'bottom', 'value' => 'On THe Bottom']
],
'position' => 2
]);
$service->update('s_cms_static_attributes', 'customize', 'multi_selection', [
'label' => Shopware()->Snippets()->getNamespace("backend/common/main")->get(
'customizeField', 'Custom Models', true
),
'helpText' => Shopware()->Snippets()->getNamespace("backend/common/main")->get(
'customizeDescrption', 'Related Custom Models.', true
),
'entity' => 'OssCustomModel\Models\CustomModel\CustomModel',
'displayInBackend' => true,
'position' => 3
]);
// Regeneration attributes proxy for including this attributes
Shopware()->Models()->generateAttributeModels( array('s_cms_static_attributes') );
}
/**
* remove schema
*/
private function dropSchema()
{
// TODO: uncomment
return ;
$service = $this->container->get('shopware_attribute.crud_service');
$service->delete('s_cms_static_attributes', 'custombanner');
$service->delete('s_cms_static_attributes', 'position');
$service->delete('s_cms_static_attributes', 'customize');
// Regeneration attributes proxy for excluding this attributes
Shopware()->Models()->generateAttributeModels( array('s_cms_static_attributes') );
}
}