1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Customer; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Customer\Aggregate\CustomerAddress\CustomerAddressDefinition; |
6
|
|
|
use Shopware\Core\Checkout\Customer\Aggregate\CustomerGroup\CustomerGroupDefinition; |
7
|
|
|
use Shopware\Core\Checkout\Customer\Aggregate\CustomerRecovery\CustomerRecoveryDefinition; |
8
|
|
|
use Shopware\Core\Checkout\Customer\Aggregate\CustomerTag\CustomerTagDefinition; |
9
|
|
|
use Shopware\Core\Checkout\Order\Aggregate\OrderCustomer\OrderCustomerDefinition; |
10
|
|
|
use Shopware\Core\Checkout\Payment\PaymentMethodDefinition; |
11
|
|
|
use Shopware\Core\Checkout\Promotion\Aggregate\PromotionPersonaCustomer\PromotionPersonaCustomerDefinition; |
12
|
|
|
use Shopware\Core\Checkout\Promotion\PromotionDefinition; |
13
|
|
|
use Shopware\Core\Content\Product\Aggregate\ProductReview\ProductReviewDefinition; |
14
|
|
|
use Shopware\Core\Framework\Api\Context\AdminApiSource; |
15
|
|
|
use Shopware\Core\Framework\Api\Context\SalesChannelApiSource; |
16
|
|
|
use Shopware\Core\Framework\Context; |
17
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition; |
18
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\BoolField; |
19
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\CustomFields; |
20
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\DateField; |
21
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\DateTimeField; |
22
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField; |
23
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\CascadeDelete; |
24
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey; |
25
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ReadProtected; |
26
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Required; |
27
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SearchRanking; |
28
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\SetNullOnDelete; |
29
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\WriteProtected; |
30
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField; |
31
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\IntField; |
32
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField; |
33
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyIdField; |
34
|
68 |
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToOneAssociationField; |
35
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToManyAssociationField; |
36
|
68 |
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\OneToOneAssociationField; |
37
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\PasswordField; |
38
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\RemoteAddressField; |
39
|
65 |
|
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField; |
40
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection; |
41
|
65 |
|
use Shopware\Core\Framework\Feature; |
42
|
|
|
use Shopware\Core\System\Language\LanguageDefinition; |
43
|
|
|
use Shopware\Core\System\NumberRange\DataAbstractionLayer\NumberRangeField; |
44
|
66 |
|
use Shopware\Core\System\SalesChannel\SalesChannelDefinition; |
45
|
|
|
use Shopware\Core\System\Salutation\SalutationDefinition; |
46
|
66 |
|
use Shopware\Core\System\Tag\TagDefinition; |
47
|
|
|
|
48
|
|
|
class CustomerDefinition extends EntityDefinition |
49
|
1 |
|
{ |
50
|
|
|
public const ENTITY_NAME = 'customer'; |
51
|
1 |
|
|
52
|
1 |
|
public function getEntityName(): string |
53
|
|
|
{ |
54
|
1 |
|
return self::ENTITY_NAME; |
55
|
|
|
} |
56
|
1 |
|
|
57
|
|
|
public function getCollectionClass(): string |
58
|
1 |
|
{ |
59
|
|
|
return CustomerCollection::class; |
60
|
1 |
|
} |
61
|
|
|
|
62
|
1 |
|
public function getEntityClass(): string |
63
|
1 |
|
{ |
64
|
|
|
return CustomerEntity::class; |
65
|
1 |
|
} |
66
|
|
|
|
67
|
1 |
|
public function hasManyToManyIdFields(): bool |
68
|
1 |
|
{ |
69
|
1 |
|
return true; |
70
|
1 |
|
} |
71
|
|
|
|
72
|
1 |
|
protected function defineFields(): FieldCollection |
73
|
1 |
|
{ |
74
|
1 |
|
$fields = new FieldCollection([ |
75
|
1 |
|
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()), |
76
|
1 |
|
|
77
|
1 |
|
(new FkField('customer_group_id', 'groupId', CustomerGroupDefinition::class))->addFlags(new Required()), |
78
|
1 |
|
|
79
|
1 |
|
(new FkField('default_payment_method_id', 'defaultPaymentMethodId', PaymentMethodDefinition::class))->addFlags(new Required()), |
80
|
1 |
|
|
81
|
1 |
|
(new FkField('sales_channel_id', 'salesChannelId', SalesChannelDefinition::class))->addFlags(new Required()), |
82
|
1 |
|
|
83
|
1 |
|
(new FkField('language_id', 'languageId', LanguageDefinition::class))->addFlags(new Required()), |
84
|
1 |
|
|
85
|
1 |
|
new FkField('last_payment_method_id', 'lastPaymentMethodId', PaymentMethodDefinition::class), |
86
|
1 |
|
|
87
|
1 |
|
(new FkField('default_billing_address_id', 'defaultBillingAddressId', CustomerAddressDefinition::class))->addFlags(new Required()), |
88
|
1 |
|
(new FkField('default_shipping_address_id', 'defaultShippingAddressId', CustomerAddressDefinition::class))->addFlags(new Required()), |
89
|
1 |
|
|
90
|
1 |
|
(new IntField('auto_increment', 'autoIncrement'))->addFlags(new WriteProtected()), |
91
|
1 |
|
|
92
|
1 |
|
(new NumberRangeField('customer_number', 'customerNumber', 255))->addFlags(new Required(), new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)), |
93
|
1 |
|
(new FkField('salutation_id', 'salutationId', SalutationDefinition::class))->addFlags(new Required()), |
94
|
1 |
|
(new StringField('first_name', 'firstName'))->addFlags(new Required(), new SearchRanking(SearchRanking::MIDDLE_SEARCH_RANKING)), |
95
|
1 |
|
(new StringField('last_name', 'lastName'))->addFlags(new Required(), new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)), |
96
|
1 |
|
(new StringField('company', 'company'))->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)), |
97
|
1 |
|
|
98
|
1 |
|
(new PasswordField('password', 'password'))->addFlags(new ReadProtected(SalesChannelApiSource::class, AdminApiSource::class)), |
99
|
1 |
|
(new StringField('email', 'email'))->addFlags(new Required(), new SearchRanking(SearchRanking::MIDDLE_SEARCH_RANKING)), |
100
|
1 |
|
new StringField('title', 'title'), |
101
|
|
|
new StringField('affiliate_code', 'affiliateCode'), |
102
|
|
|
new StringField('campaign_code', 'campaignCode'), |
103
|
|
|
new BoolField('active', 'active'), |
104
|
|
|
new BoolField('doubleOptInRegistration', 'doubleOptInRegistration'), |
105
|
|
|
new DateTimeField('doubleOptInEmailSentDate', 'doubleOptInEmailSentDate'), |
106
|
|
|
new DateTimeField('doubleOptInConfirmDate', 'doubleOptInConfirmDate'), |
107
|
|
|
new StringField('hash', 'hash'), |
108
|
|
|
new BoolField('guest', 'guest'), |
109
|
|
|
new DateTimeField('first_login', 'firstLogin'), |
110
|
|
|
new DateTimeField('last_login', 'lastLogin'), |
111
|
|
|
new BoolField('newsletter', 'newsletter'), |
112
|
|
|
new DateField('birthday', 'birthday'), |
113
|
|
|
(new DateTimeField('last_order_date', 'lastOrderDate'))->addFlags(new WriteProtected(Context::SYSTEM_SCOPE)), |
114
|
|
|
(new IntField('order_count', 'orderCount'))->addFlags(new WriteProtected(Context::SYSTEM_SCOPE)), |
115
|
|
|
new CustomFields(), |
116
|
|
|
(new StringField('legacy_password', 'legacyPassword'))->addFlags(new ReadProtected(SalesChannelApiSource::class, AdminApiSource::class)), |
117
|
|
|
(new StringField('legacy_encoder', 'legacyEncoder'))->addFlags(new ReadProtected(SalesChannelApiSource::class, AdminApiSource::class)), |
118
|
|
|
new ManyToOneAssociationField('group', 'customer_group_id', CustomerGroupDefinition::class, 'id', false), |
119
|
|
|
(new ManyToOneAssociationField('defaultPaymentMethod', 'default_payment_method_id', PaymentMethodDefinition::class, 'id', false))->addFlags(new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING)), |
120
|
|
|
new ManyToOneAssociationField('salesChannel', 'sales_channel_id', SalesChannelDefinition::class, 'id', false), |
121
|
|
|
new ManyToOneAssociationField('language', 'language_id', LanguageDefinition::class, 'id', false), |
122
|
|
|
new ManyToOneAssociationField('lastPaymentMethod', 'last_payment_method_id', PaymentMethodDefinition::class, 'id', false), |
123
|
|
|
(new ManyToOneAssociationField('defaultBillingAddress', 'default_billing_address_id', CustomerAddressDefinition::class, 'id', false))->addFlags(new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING)), |
124
|
|
|
(new ManyToOneAssociationField('defaultShippingAddress', 'default_shipping_address_id', CustomerAddressDefinition::class, 'id', false))->addFlags(new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING)), |
125
|
|
|
new ManyToOneAssociationField('salutation', 'salutation_id', SalutationDefinition::class, 'id', false), |
126
|
|
|
(new OneToManyAssociationField('addresses', CustomerAddressDefinition::class, 'customer_id', 'id'))->addFlags(new CascadeDelete()), |
127
|
|
|
(new OneToManyAssociationField('orderCustomers', OrderCustomerDefinition::class, 'customer_id', 'id'))->addFlags(new SetNullOnDelete()), |
128
|
|
|
(new ManyToManyAssociationField('tags', TagDefinition::class, CustomerTagDefinition::class, 'customer_id', 'tag_id'))->addFlags(new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING)), |
129
|
|
|
new ManyToManyAssociationField('promotions', PromotionDefinition::class, PromotionPersonaCustomerDefinition::class, 'customer_id', 'promotion_id'), |
130
|
|
|
new OneToManyAssociationField('productReviews', ProductReviewDefinition::class, 'customer_id'), |
131
|
|
|
new OneToOneAssociationField('recoveryCustomer', 'id', 'customer_id', CustomerRecoveryDefinition::class, false), |
132
|
|
|
new RemoteAddressField('remote_address', 'remoteAddress'), |
133
|
|
|
new ManyToManyIdField('tag_ids', 'tagIds', 'tags'), |
134
|
|
|
new FkField('requested_customer_group_id', 'requestedGroupId', CustomerGroupDefinition::class), |
135
|
|
|
new ManyToOneAssociationField('requestedGroup', 'requested_customer_group_id', CustomerGroupDefinition::class, 'id', false), |
136
|
|
|
]); |
137
|
|
|
|
138
|
|
|
if (Feature::isActive('FEATURE_NEXT_10555')) { |
139
|
|
|
$fields->add( |
140
|
|
|
new FkField('bound_sales_channel_id', 'boundSalesChannelId', SalesChannelDefinition::class) |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$fields->add( |
144
|
|
|
new ManyToOneAssociationField('boundSalesChannel', 'bound_sales_channel_id', SalesChannelDefinition::class, 'id', false) |
145
|
|
|
); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return $fields; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|