-
Notifications
You must be signed in to change notification settings - Fork 976
/
CategoryDefinition.php
178 lines (144 loc) · 9.64 KB
/
CategoryDefinition.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php declare(strict_types=1);
namespace Shopware\Core\Content\Category;
use Shopware\Core\Content\Category\Aggregate\CategoryTag\CategoryTagDefinition;
use Shopware\Core\Content\Category\Aggregate\CategoryTranslation\CategoryTranslationDefinition;
use Shopware\Core\Content\Cms\CmsPageDefinition;
use Shopware\Core\Content\Media\MediaDefinition;
use Shopware\Core\Content\Product\Aggregate\ProductCategory\ProductCategoryDefinition;
use Shopware\Core\Content\Product\Aggregate\ProductCategoryTree\ProductCategoryTreeDefinition;
use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Content\ProductStream\ProductStreamDefinition;
use Shopware\Core\Content\Seo\MainCategory\MainCategoryDefinition;
use Shopware\Core\Content\Seo\SeoUrl\SeoUrlDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\AutoIncrementField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ChildCountField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ChildrenAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReverseInherited;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Runtime;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SearchRanking;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\WriteProtected;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ParentAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ParentFkField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ReferenceVersionField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslatedField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TranslationsAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TreeLevelField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\TreePathField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\VersionField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\System\CustomEntity\CustomEntityDefinition;
use Shopware\Core\System\SalesChannel\SalesChannelDefinition;
use Shopware\Core\System\Tag\TagDefinition;
#[Package('inventory')]
class CategoryDefinition extends EntityDefinition
{
final public const ENTITY_NAME = 'category';
final public const TYPE_PAGE = 'page';
final public const TYPE_LINK = 'link';
final public const TYPE_FOLDER = 'folder';
final public const LINK_TYPE_EXTERNAL = 'external';
final public const LINK_TYPE_CATEGORY = 'category';
final public const LINK_TYPE_PRODUCT = 'product';
final public const LINK_TYPE_LANDING_PAGE = 'landing_page';
final public const PRODUCT_ASSIGNMENT_TYPE_PRODUCT = 'product';
final public const PRODUCT_ASSIGNMENT_TYPE_PRODUCT_STREAM = 'product_stream';
final public const CONFIG_KEY_DEFAULT_CMS_PAGE_CATEGORY = 'core.cms.default_category_cms_page';
public function getEntityName(): string
{
return self::ENTITY_NAME;
}
public function getCollectionClass(): string
{
return CategoryCollection::class;
}
public function getEntityClass(): string
{
return CategoryEntity::class;
}
public function getDefaults(): array
{
return [
'displayNestedProducts' => true,
'type' => self::TYPE_PAGE,
'productAssignmentType' => self::PRODUCT_ASSIGNMENT_TYPE_PRODUCT,
];
}
public function since(): ?string
{
return '6.0.0.0';
}
public function getHydratorClass(): string
{
return CategoryHydrator::class;
}
protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('id', 'id'))->addFlags(new ApiAware(), new PrimaryKey(), new Required()),
(new VersionField())->addFlags(new ApiAware()),
(new ParentFkField(self::class))->addFlags(new ApiAware()),
(new ReferenceVersionField(self::class, 'parent_version_id'))->addFlags(new ApiAware(), new Required()),
(new FkField('after_category_id', 'afterCategoryId', self::class))->addFlags(new ApiAware()),
(new ReferenceVersionField(self::class, 'after_category_version_id'))->addFlags(new ApiAware(), new Required()),
(new FkField('media_id', 'mediaId', MediaDefinition::class))->addFlags(new ApiAware()),
(new BoolField('display_nested_products', 'displayNestedProducts'))->addFlags(new ApiAware(), new Required()),
new AutoIncrementField(),
(new TranslatedField('breadcrumb'))->addFlags(new ApiAware(), new WriteProtected()),
(new TreeLevelField('level', 'level'))->addFlags(new ApiAware()),
(new TreePathField('path', 'path'))->addFlags(new ApiAware()),
(new ChildCountField())->addFlags(new ApiAware()),
(new StringField('type', 'type'))->addFlags(new ApiAware(), new Required()),
(new StringField('product_assignment_type', 'productAssignmentType'))->addFlags(new ApiAware(), new Required()),
(new BoolField('visible', 'visible'))->addFlags(new ApiAware()),
(new BoolField('active', 'active'))->addFlags(new ApiAware()),
(new BoolField('cmsPageIdSwitched', 'cmsPageIdSwitched'))->addFlags(new Runtime(), new ApiAware()),
(new IntField('visibleChildCount', 'visibleChildCount'))->addFlags(new Runtime(), new ApiAware()),
(new TranslatedField('name'))->addFlags(new ApiAware(), new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
(new TranslatedField('customFields'))->addFlags(new ApiAware()),
new TranslatedField('slotConfig'),
(new TranslatedField('linkType'))->addFlags(new ApiAware()),
(new TranslatedField('internalLink'))->addFlags(new ApiAware()),
(new TranslatedField('externalLink'))->addFlags(new ApiAware()),
(new TranslatedField('linkNewTab'))->addFlags(new ApiAware()),
(new TranslatedField('description'))->addFlags(new ApiAware()),
(new TranslatedField('metaTitle'))->addFlags(new ApiAware()),
(new TranslatedField('metaDescription'))->addFlags(new ApiAware()),
(new TranslatedField('keywords'))->addFlags(new ApiAware()),
(new ParentAssociationField(self::class, 'id'))->addFlags(new ApiAware()),
(new ChildrenAssociationField(self::class))->addFlags(new ApiAware()),
(new ManyToOneAssociationField('media', 'media_id', MediaDefinition::class, 'id', false))->addFlags(new ApiAware()),
(new TranslationsAssociationField(CategoryTranslationDefinition::class, 'category_id'))->addFlags(new ApiAware(), new Required()),
(new ManyToManyAssociationField('products', ProductDefinition::class, ProductCategoryDefinition::class, 'category_id', 'product_id'))->addFlags(new CascadeDelete(), new ReverseInherited('categories')),
(new ManyToManyAssociationField('nestedProducts', ProductDefinition::class, ProductCategoryTreeDefinition::class, 'category_id', 'product_id'))->addFlags(new CascadeDelete(), new WriteProtected()),
(new ManyToManyAssociationField('tags', TagDefinition::class, CategoryTagDefinition::class, 'category_id', 'tag_id'))->addFlags(new ApiAware()),
(new FkField('cms_page_id', 'cmsPageId', CmsPageDefinition::class))->addFlags(new ApiAware()),
(new ReferenceVersionField(CmsPageDefinition::class))->addFlags(new Required(), new ApiAware()),
(new ManyToOneAssociationField('cmsPage', 'cms_page_id', CmsPageDefinition::class, 'id', false))->addFlags(new ApiAware()),
new FkField('product_stream_id', 'productStreamId', ProductStreamDefinition::class),
new ManyToOneAssociationField('productStream', 'product_stream_id', ProductStreamDefinition::class, 'id', false),
// custom entity specific fields
(new FkField('custom_entity_type_id', 'customEntityTypeId', CustomEntityDefinition::class, 'id'))->addFlags(new ApiAware()),
// Reverse Associations not available in store-api
new OneToManyAssociationField('navigationSalesChannels', SalesChannelDefinition::class, 'navigation_category_id'),
new OneToManyAssociationField('footerSalesChannels', SalesChannelDefinition::class, 'footer_category_id'),
new OneToManyAssociationField('serviceSalesChannels', SalesChannelDefinition::class, 'service_category_id'),
(new OneToManyAssociationField('mainCategories', MainCategoryDefinition::class, 'category_id'))->addFlags(new CascadeDelete()),
(new OneToManyAssociationField('seoUrls', SeoUrlDefinition::class, 'foreign_key'))->addFlags(new ApiAware()),
(new IntField('visible_child_count', 'visibleChildCount'))->addFlags(new Runtime(), new ApiAware()),
]);
}
}