Customer   F
last analyzed

Complexity

Total Complexity 106

Size/Duplication

Total Lines 1441
Duplicated Lines 0 %

Coupling/Cohesion

Components 9
Dependencies 6

Importance

Changes 0
Metric Value
wmc 106
lcom 9
cbo 6
dl 0
loc 1441
rs 0.8
c 0
b 0
f 0

92 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getId() 0 4 1
A getChanged() 0 4 1
A setPassword() 0 8 1
A getPassword() 0 4 1
A setRawPassword() 0 6 1
A setEmail() 0 6 1
A getEmail() 0 4 1
A setActive() 0 6 1
A getActive() 0 4 1
A setAccountMode() 0 6 1
A getAccountMode() 0 4 1
A setConfirmationKey() 0 6 1
A getConfirmationKey() 0 4 1
A setFirstLogin() 0 9 2
A getFirstLogin() 0 4 1
A setLastLogin() 0 9 2
A getLastLogin() 0 4 1
A setSessionId() 0 6 1
A getSessionId() 0 4 1
A setNewsletter() 0 6 1
A getNewsletter() 0 4 1
A setValidation() 0 6 1
A getValidation() 0 4 1
A setAffiliate() 0 6 1
A getAffiliate() 0 4 1
A setPaymentPreset() 0 6 1
A getPaymentPreset() 0 4 1
A setReferer() 0 6 1
A getReferer() 0 4 1
A setInternalComment() 0 6 1
A getInternalComment() 0 4 1
A setFailedLogins() 0 6 1
A getFailedLogins() 0 4 1
A setLockedUntil() 0 9 2
A getLockedUntil() 0 4 1
A onSave() 0 16 5
A onUpdate() 0 17 5
A getAttribute() 0 4 1
A setAttribute() 0 4 1
A getShop() 0 4 1
A setShop() 0 6 1
A getOrders() 0 4 1
A setOrders() 0 6 1
A getGroup() 0 7 1
A setGroup() 0 4 1
A getPaymentId() 0 4 1
A setPaymentId() 0 4 1
A getPriceGroup() 0 4 1
A setPriceGroup() 0 4 1
A setLanguageSubShop() 0 7 2
A getLanguageSubShop() 0 4 1
A setLanguageId() 0 4 1
A getLanguageId() 0 4 1
A setPaymentInstances() 0 4 1
A getPaymentInstances() 0 4 1
A setPaymentData() 0 4 1
A getPaymentData() 0 4 1
A addPaymentData() 0 6 1
A getGroupKey() 0 4 1
A getDefaultBillingAddress() 0 4 1
A setDefaultBillingAddress() 0 4 1
A getDefaultShippingAddress() 0 4 1
A setDefaultShippingAddress() 0 4 1
A getSalutation() 0 4 1
A setSalutation() 0 4 1
A getTitle() 0 4 1
A setTitle() 0 4 1
A getFirstname() 0 4 1
A setFirstname() 0 4 1
A getLastname() 0 4 1
A setLastname() 0 4 1
A getBirthday() 0 4 1
A setBirthday() 0 8 3
A getEncoderName() 0 4 1
A setEncoderName() 0 4 1
A getNumber() 0 4 1
A setNumber() 0 4 1
A getCustomerType() 0 4 1
A setCustomerType() 0 4 1
A getAdditional() 0 4 1
A setAdditional() 0 4 1
A getDoubleOptinRegister() 0 4 1
A setDoubleOptinRegister() 0 4 1
A getDoubleOptinEmailSentDate() 0 4 1
A setDoubleOptinEmailSentDate() 0 4 1
A getDoubleOptinConfirmDate() 0 4 1
A setDoubleOptinConfirmDate() 0 4 1
A getPasswordChangeDate() 0 4 1
A updateChangedTimestamp() 0 4 1
A getRegisterOptInId() 0 4 1
A setRegisterOptInId() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like Customer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Customer, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Shopware 5
4
 * Copyright (c) shopware AG
5
 *
6
 * According to our dual licensing model, this program can be used either
7
 * under the terms of the GNU Affero General Public License, version 3,
8
 * or under a proprietary license.
9
 *
10
 * The texts of the GNU Affero General Public License with an additional
11
 * permission and of our proprietary license can be found at and
12
 * in the LICENSE file you have received along with this program.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * "Shopware" is a registered trademark of shopware AG.
20
 * The licensing of the program under the AGPLv3 does not imply a
21
 * trademark license. Therefore any rights, title and interest in
22
 * our trademarks remain entirely with us.
23
 */
24
25
namespace Shopware\Models\Customer;
26
27
use Doctrine\Common\Collections\ArrayCollection;
28
use Doctrine\ORM\Mapping as ORM;
29
use Shopware\Components\Model\LazyFetchModelEntity;
30
use Shopware\Components\Model\ModelEntity;
31
use Shopware\Components\Security\AttributeCleanerTrait;
32
use Shopware\Models\Attribute\Customer as CustomerAttribute;
33
use Shopware\Models\Shop\Shop;
34
use Symfony\Component\Validator\Constraints as Assert;
35
36
/**
37
 * Shopware customer model represents a single customer.
38
 *
39
 * The Shopware customer model represents a row of the s_user table.
40
 * The customer model data set from the Shopware\Models\Customer\Repository.
41
 * One customer has the follows associations:
42
 * <code>
43
 *   - Address  =>  Shopware\Models\Customer\Address    [1:1] [s_user_addresses]
44
 *   - Group    =>  Shopware\Models\Customer\Group      [n:1] [s_core_customergroups]
45
 *   - Shop     =>  Shopware\Models\Shop\Shop           [n:1] [s_core_shops]
46
 *   - Orders   =>  Shopware\Models\Order\Order         [1:n] [s_order]
47
 * </code>
48
 * The s_user table has the follows indices:
49
 * <code>
50
 *   - PRIMARY KEY (`id`)
51
 *   - KEY `email` (`email`)
52
 *   - KEY `sessionID` (`sessionID`)
53
 *   - KEY `firstlogin` (`firstlogin`)
54
 *   - KEY `lastlogin` (`lastlogin`)
55
 *   - KEY `pricegroupID` (`pricegroupID`)
56
 * </code>
57
 *
58
 * @ORM\Entity(repositoryClass="Repository")
59
 * @ORM\Table(name="s_user")
60
 * @ORM\HasLifecycleCallbacks()
61
 */
62
class Customer extends LazyFetchModelEntity
63
{
64
    /*
65
     * HTML Cleansing trait (Used to cleanup different properties in setters)
66
     * @see \Shopware\Components\Security\AttributeCleanerTrait
67
     */
68
    use AttributeCleanerTrait;
69
70
    const ACCOUNT_MODE_CUSTOMER = 0;
71
    const ACCOUNT_MODE_FAST_LOGIN = 1;
72
73
    const CUSTOMER_TYPE_PRIVATE = 'private';
74
    const CUSTOMER_TYPE_BUSINESS = 'business';
75
76
    /**
77
     * Contains the unique customer number
78
     *
79
     * @var string|null
80
     *
81
     * @ORM\Column(name="customernumber", type="string", length=30, nullable=true)
82
     */
83
    protected $number = '';
84
85
    /**
86
     * OWNING SIDE
87
     * The group property is the owning side of the association between customer and customer group.
88
     * The association is joined over the group id field and the groupkey field of the customer.
89
     *
90
     * @var Group
91
     *
92
     * @ORM\ManyToOne(targetEntity="Shopware\Models\Customer\Group", inversedBy="customers", cascade={"persist"})
93
     * @ORM\JoinColumn(name="customergroup", referencedColumnName="groupkey")
94
     */
95
    protected $group;
96
97
    /**
98
     * INVERSE SIDE
99
     * The orders property is the inverse side of the association between customer and orders.
100
     * The association is joined over the customer id field and the userID field of the order.
101
     *
102
     * @var ArrayCollection<\Shopware\Models\Order\Order>
103
     *
104
     * @ORM\OneToMany(targetEntity="Shopware\Models\Order\Order", mappedBy="customer")
105
     */
106
    protected $orders;
107
108
    /**
109
     * OWNING SIDE
110
     *
111
     * @var Shop
112
     *
113
     * @ORM\ManyToOne(targetEntity="Shopware\Models\Shop\Shop")
114
     * @ORM\JoinColumn(name="subshopID", referencedColumnName="id")
115
     */
116
    protected $shop;
117
118
    /**
119
     * INVERSE SIDE
120
     *
121
     * @var CustomerAttribute|null
122
     *
123
     * @Assert\Valid()
124
     * @ORM\OneToOne(targetEntity="Shopware\Models\Attribute\Customer", mappedBy="customer", orphanRemoval=true, cascade={"persist"})
125
     */
126
    protected $attribute;
127
128
    /**
129
     * OWNING SIDE
130
     * The price group property represents the owning side for the association between customer and customer price group.
131
     * The association is joined over the pricegroup id field and the pricegroupID field of the customer.
132
     *
133
     * @var PriceGroup|null
134
     *
135
     * @ORM\ManyToOne(targetEntity="\Shopware\Models\Customer\PriceGroup", inversedBy="customers")
136
     * @ORM\JoinColumn(name="pricegroupID", referencedColumnName="id")
137
     */
138
    protected $priceGroup;
139
140
    /**
141
     * INVERSE SIDE
142
     *
143
     * @var ArrayCollection<\Shopware\Models\Article\Notification>
144
     *
145
     * @ORM\OneToMany(targetEntity="Shopware\Models\Article\Notification", mappedBy="customer")
146
     */
147
    protected $notifications;
148
149
    /**
150
     * @var ArrayCollection<\Shopware\Models\Payment\PaymentInstance>
151
     *
152
     * @ORM\OneToMany(targetEntity="Shopware\Models\Payment\PaymentInstance", mappedBy="customer")
153
     */
154
    protected $paymentInstances;
155
156
    /**
157
     * @var ArrayCollection<\Shopware\Models\Customer\PaymentData>
158
     *
159
     * @ORM\OneToMany(targetEntity="Shopware\Models\Customer\PaymentData", mappedBy="customer", orphanRemoval=true, cascade={"persist"})
160
     */
161
    protected $paymentData;
162
163
    /**
164
     * OWNING SIDE
165
     *
166
     * @var \Shopware\Models\Customer\Address
167
     *
168
     * @ORM\ManyToOne(targetEntity="\Shopware\Models\Customer\Address", inversedBy="customer")
169
     * @ORM\JoinColumn(name="default_billing_address_id", referencedColumnName="id")
170
     */
171
    protected $defaultBillingAddress;
172
173
    /**
174
     * OWNING SIDE
175
     *
176
     * @var \Shopware\Models\Customer\Address
177
     *
178
     * @ORM\ManyToOne(targetEntity="\Shopware\Models\Customer\Address", inversedBy="customer")
179
     * @ORM\JoinColumn(name="default_shipping_address_id", referencedColumnName="id")
180
     */
181
    protected $defaultShippingAddress;
182
183
    /**
184
     * @var array
185
     */
186
    protected $additional;
187
188
    /**
189
     * The id property is an identifier property which means
190
     * doctrine associations can be defined over this field
191
     *
192
     * @var int
193
     *
194
     * @ORM\Column(name="id", type="integer", nullable=false)
195
     * @ORM\Id()
196
     * @ORM\GeneratedValue(strategy="IDENTITY")
197
     */
198
    private $id;
199
200
    /**
201
     * Time of the last modification of the customer
202
     *
203
     * @var \DateTimeInterface
204
     *
205
     * @ORM\Column(name="changed", type="datetime", nullable=false)
206
     */
207
    private $changed;
208
209
    /**
210
     * Contains the id of the customer default payment method.
211
     * Used for the payment association.
212
     *
213
     * @var int
214
     *
215
     * @ORM\Column(name="paymentID", type="integer", nullable=false)
216
     */
217
    private $paymentId = 0;
218
219
    /**
220
     * Key of the assigned customer group.
221
     *
222
     * @var string
223
     *
224
     * @ORM\Column(name="customergroup", type="string", length=15, nullable=false)
225
     */
226
    private $groupKey = '';
227
228
    /**
229
     * Id shop where the customer has registered.
230
     *
231
     * @var int
232
     *
233
     * @ORM\Column(name="subshopID", type="integer", nullable=false)
234
     */
235
    private $shopId = 0;
236
237
    /**
238
     * Id of the price group, which the customer is assigned
239
     *
240
     * @var int|null
241
     *
242
     * @ORM\Column(name="pricegroupID", type="integer", nullable=true)
243
     */
244
    private $priceGroupId;
245
246
    /**
247
     * If this property is set, set password will be encoded with md5 on save.
248
     * To check the customer password use the hashPassword field.
249
     *
250
     * @var string
251
     */
252
    private $password = '';
253
254
    /**
255
     * Tells which hash was used for password encryption
256
     *
257
     * @var string
258
     *
259
     * @ORM\Column(name="encoder", type="string", length=255, nullable=false)
260
     */
261
    private $encoderName = 'md5';
262
263
    /**
264
     * If this property is set, the password will not be encoded on save.
265
     *
266
     * @var string
267
     */
268
    private $rawPassword;
269
270
    /**
271
     * Contains the md5 encoded password
272
     *
273
     * @var string
274
     *
275
     * @ORM\Column(name="password", type="string", length=1024, nullable=false)
276
     */
277
    private $hashPassword = '';
278
279
    /**
280
     * Flag whether the customer account is activated.
281
     *
282
     * @var bool
283
     *
284
     * @ORM\Column(name="active", type="boolean", nullable=false)
285
     */
286
    private $active = 0;
287
288
    /**
289
     * Contains the customer email address which is used to send the order confirmation mail
290
     * or the newsletter.
291
     *
292
     * @var string
293
     *
294
     * @Assert\Email(strict=false)
295
     * @Assert\NotBlank()
296
     * @ORM\Column(name="email", type="string", length=70, nullable=false)
297
     */
298
    private $email;
299
300
    /**
301
     * Contains the date on which the customer account was created.
302
     *
303
     * @var \DateTimeInterface
304
     *
305
     * @ORM\Column(name="firstlogin", type="date", nullable=false)
306
     */
307
    private $firstLogin;
308
309
    /**
310
     * Contains the date on which the customer has logged in recently.
311
     *
312
     * @var \DateTimeInterface
313
     *
314
     * @ORM\Column(name="lastlogin", type="datetime", nullable=false)
315
     */
316
    private $lastLogin;
317
318
    /**
319
     * Flag whether the customer checks the "don't create a shop account" checkbox
320
     *
321
     * @var int
322
     *
323
     * @ORM\Column(name="accountmode", type="integer", nullable=false)
324
     */
325
    private $accountMode = 0;
326
327
    /**
328
     * @var string
329
     *
330
     * @ORM\Column(name="confirmationkey", type="string", length=100, nullable=false)
331
     */
332
    private $confirmationKey = '';
333
334
    /**
335
     * Contains the session id of the last customer session.
336
     *
337
     * @var string
338
     *
339
     * @ORM\Column(name="sessionID", type="string", length=255, nullable=false)
340
     */
341
    private $sessionId = '';
342
343
    /**
344
     * Flag whether the customer wishes to receive the store newsletter
345
     *
346
     * @var int
347
     *
348
     * @ORM\Column(name="newsletter", type="integer", nullable=false)
349
     */
350
    private $newsletter = 0;
351
352
    /**
353
     * @var string
354
     *
355
     * @ORM\Column(name="validation", type="string", length=255, nullable=false)
356
     */
357
    private $validation = '';
358
359
    /**
360
     * Flag whether the customer is a shop partner.
361
     *
362
     * @var int
363
     *
364
     * @ORM\Column(name="affiliate", type="integer", nullable=false)
365
     */
366
    private $affiliate = 0;
367
368
    /**
369
     * Flag whether a payment default has been filed
370
     *
371
     * @var int
372
     *
373
     * @ORM\Column(name="paymentpreset", type="integer", nullable=false)
374
     */
375
    private $paymentPreset = 0;
376
377
    /**
378
     * Id of the language sub shop
379
     *
380
     * @var string
381
     *
382
     * @ORM\Column(name="language", type="string", length=10, nullable=false)
383
     */
384
    private $languageId = 1;
385
386
    /**
387
     * OWNING SIDE
388
     *
389
     * Used for the language subshop association
390
     *
391
     * @var Shop
392
     *
393
     * @ORM\ManyToOne(targetEntity="Shopware\Models\Shop\Shop")
394
     * @ORM\JoinColumn(name="language", referencedColumnName="id")
395
     */
396
    private $languageSubShop;
397
398
    /**
399
     * @var string
400
     *
401
     * @ORM\Column(name="referer", type="string", length=255, nullable=false)
402
     */
403
    private $referer = '';
404
405
    /**
406
     * Contains the internal comment for the customer.
407
     *
408
     * @var string
409
     *
410
     * @ORM\Column(name="internalcomment", type="text", nullable=false)
411
     */
412
    private $internalComment = '';
413
414
    /**
415
     * Count of the failed customer logins
416
     *
417
     * @var int
418
     *
419
     * @ORM\Column(name="failedlogins", type="integer", nullable=false)
420
     */
421
    private $failedLogins = 0;
422
423
    /**
424
     * Contains the time, since the customer is logged into a session.
425
     *
426
     * @var \DateTimeInterface|null
427
     *
428
     * @ORM\Column(name="lockedUntil", type="datetime", nullable=true)
429
     */
430
    private $lockedUntil;
431
432
    /**
433
     * @var string
434
     *
435
     * @Assert\NotBlank()
436
     *
437
     * @ORM\Column(name="salutation", type="text", nullable=false)
438
     */
439
    private $salutation;
440
441
    /**
442
     * @var string
443
     *
444
     * @ORM\Column(name="title", type="text", nullable=false)
445
     */
446
    private $title;
447
448
    /**
449
     * @var string
450
     *
451
     * @Assert\NotBlank()
452
     * @ORM\Column(name="firstname", type="text", nullable=false)
453
     */
454
    private $firstname;
455
456
    /**
457
     * @var string
458
     *
459
     * @Assert\NotBlank()
460
     * @ORM\Column(name="lastname", type="text", nullable=false)
461
     */
462
    private $lastname;
463
464
    /**
465
     * @var \DateTimeInterface
466
     *
467
     * @ORM\Column(name="birthday", type="date", nullable=true)
468
     */
469
    private $birthday;
470
471
    /**
472
     * @var bool
473
     *
474
     * @ORM\Column(name="doubleOptinRegister", type="boolean", nullable=false)
475
     */
476
    private $doubleOptinRegister;
477
478
    /**
479
     * @var \DateTimeInterface|null
480
     *
481
     * @ORM\Column(name="doubleOptinEmailSentDate", type="datetime", nullable=true)
482
     */
483
    private $doubleOptinEmailSentDate;
484
485
    /**
486
     * @var \DateTimeInterface|null
487
     *
488
     * @ORM\Column(name="doubleOptinConfirmDate", type="datetime", nullable=true)
489
     */
490
    private $doubleOptinConfirmDate;
491
492
    /**
493
     * @var string
494
     */
495
    private $customerType;
496
497
    /**
498
     * Contains the date on which the customer account last changed the password
499
     *
500
     * @var \DateTimeInterface
501
     *
502
     * @ORM\Column(name="password_change_date", type="datetime", nullable=false)
503
     */
504
    private $passwordChangeDate;
505
506
    /**
507
     * Contains the ID of the opt-in entry, if any available
508
     *
509
     * @var int
510
     *
511
     * @ORM\Column(name="register_opt_in_id", type="integer", nullable=true)
512
     */
513
    private $registerOptInId;
514
515
    public function __construct()
516
    {
517
        $this->orders = new ArrayCollection();
518
        $this->firstLogin = new \DateTime();
519
        $this->lastLogin = new \DateTime();
520
        $this->passwordChangeDate = new \DateTime();
521
        $this->notifications = new ArrayCollection();
522
        $this->paymentInstances = new ArrayCollection();
523
        $this->paymentData = new ArrayCollection();
524
    }
525
526
    /**
527
     * Returns the unique identifier "id"
528
     *
529
     * @return int
530
     */
531
    public function getId()
532
    {
533
        return $this->id;
534
    }
535
536
    /**
537
     * @return \DateTimeInterface
538
     */
539
    public function getChanged()
540
    {
541
        return $this->changed;
542
    }
543
544
    /**
545
     * Setter method for the password column property which used for the customer login.
546
     *
547
     * @param string $password
548
     *
549
     * @return Customer
550
     */
551
    public function setPassword($password)
552
    {
553
        // Force hashPassword to change with the password
554
        $this->hashPassword = null;
555
        $this->password = $password;
556
557
        return $this;
558
    }
559
560
    /**
561
     * Getter method for the password column property which used for the customer login.
562
     *
563
     * @return string
564
     */
565
    public function getPassword()
566
    {
567
        return $this->hashPassword;
568
    }
569
570
    /**
571
     * Setter method for the rawPassword column property which used for the customer login.
572
     * This property will not be hashed!
573
     *
574
     * @param string $rawPassword
575
     */
576
    public function setRawPassword($rawPassword)
577
    {
578
        // Force hashPassword to change with the rawPassword
579
        $this->hashPassword = null;
580
        $this->rawPassword = $rawPassword;
581
    }
582
583
    /**
584
     * Setter function for the email column property of the customer.
585
     *
586
     * @param string $email
587
     *
588
     * @return Customer
589
     */
590
    public function setEmail($email)
591
    {
592
        $this->email = $this->cleanup($email);
593
594
        return $this;
595
    }
596
597
    /**
598
     * Getter function for the email column property of the customer.
599
     *
600
     * @return string
601
     */
602
    public function getEmail()
603
    {
604
        return $this->email;
605
    }
606
607
    /**
608
     * Setter function for the active column property which is a flag whether the customer account is activated.
609
     *
610
     * @param bool $active
611
     *
612
     * @return Customer
613
     */
614
    public function setActive($active)
615
    {
616
        $this->active = $active;
617
618
        return $this;
619
    }
620
621
    /**
622
     * Getter function for the active column property which is a flag whether the customer account is activated.
623
     *
624
     * @return bool
625
     */
626
    public function getActive()
627
    {
628
        return $this->active;
629
    }
630
631
    /**
632
     * Setter function for the accountMode column property which is a flag whether the customer has activated
633
     * the checkbox "don't create customer account".<br>
634
     * 0 => normal account ("don't create customer account" wasn't checked)<br>
635
     * 1 => hidden account ("don't create customer account" was checked)
636
     *
637
     * @param int $accountMode
638
     *
639
     * @return Customer
640
     */
641
    public function setAccountMode($accountMode)
642
    {
643
        $this->accountMode = $accountMode;
644
645
        return $this;
646
    }
647
648
    /**
649
     * Getter function for the accountMode column property which is a flag whether the customer has activated
650
     * the checkbox "don't create customer account".<br>
651
     * 0 => normal account ("don't create customer account" wasn't checked)<br>
652
     * 1 => hidden account ("don't create customer account" was checked)
653
     *
654
     * @return int
655
     */
656
    public function getAccountMode()
657
    {
658
        return $this->accountMode;
659
    }
660
661
    /**
662
     * Setter function for the confirmationKey column property.
663
     *
664
     * @param string $confirmationKey
665
     *
666
     * @return Customer
667
     */
668
    public function setConfirmationKey($confirmationKey)
669
    {
670
        $this->confirmationKey = $confirmationKey;
671
672
        return $this;
673
    }
674
675
    /**
676
     * Getter function for the confirmationKey column property.
677
     *
678
     * @return string
679
     */
680
    public function getConfirmationKey()
681
    {
682
        return $this->confirmationKey;
683
    }
684
685
    /**
686
     * Setter function for the first login column property of the customer, which contains a DateTime object
687
     * with the date when the customer creates the account. The parameter can be a DateTime object
688
     * or a string with the date. If a string is passed, the string converts to an DateTime object.
689
     *
690
     * @param \DateTimeInterface|string $firstLogin
691
     *
692
     * @return Customer
693
     */
694
    public function setFirstLogin($firstLogin)
695
    {
696
        if (!$firstLogin instanceof \DateTimeInterface) {
697
            $firstLogin = new \DateTime($firstLogin);
698
        }
699
        $this->firstLogin = $firstLogin;
700
701
        return $this;
702
    }
703
704
    /**
705
     * Getter function for the first login column property of the customer, which contains a DateTime object
706
     * with the date when the customer creates the account.
707
     *
708
     * @return \DateTimeInterface
709
     */
710
    public function getFirstLogin()
711
    {
712
        return $this->firstLogin;
713
    }
714
715
    /**
716
     * Setter function for the last login column property of the customer, which contains a DateTime object
717
     * with the date when the customer last logged in. The parameter can be a DateTime object
718
     * or a string with the date. If a string is passed, the string converts to an DateTime object.
719
     *
720
     * @param \DateTimeInterface|string $lastLogin
721
     *
722
     * @return Customer
723
     */
724
    public function setLastLogin($lastLogin)
725
    {
726
        if (!$lastLogin instanceof \DateTimeInterface) {
727
            $lastLogin = new \DateTime($lastLogin);
728
        }
729
        $this->lastLogin = $lastLogin;
730
731
        return $this;
732
    }
733
734
    /**
735
     * Getter function for the last login column property of the customer, which contains a DateTime object
736
     * with the date when the customer last logged in.
737
     *
738
     * @return \DateTimeInterface
739
     */
740
    public function getLastLogin()
741
    {
742
        return $this->lastLogin;
743
    }
744
745
    /**
746
     * Setter function of the session id column property. Used to verify the login without the credentials.
747
     *
748
     * @param string $sessionId
749
     *
750
     * @return Customer
751
     */
752
    public function setSessionId($sessionId)
753
    {
754
        $this->sessionId = $sessionId;
755
756
        return $this;
757
    }
758
759
    /**
760
     * Getter function of the session id column property. Used to verify the login without the credentials. <br>
761
     *
762
     * @return string
763
     */
764
    public function getSessionId()
765
    {
766
        return $this->sessionId;
767
    }
768
769
    /**
770
     * Setter function of the newsletter column property, which is a flag whether the customer wants to receive the newsletter.
771
     * 0 => Customer don't want to receive the newsletter
772
     * 1 => Customer want to receive the newsletter
773
     *
774
     * @param int $newsletter
775
     *
776
     * @return Customer
777
     */
778
    public function setNewsletter($newsletter)
779
    {
780
        $this->newsletter = $newsletter;
781
782
        return $this;
783
    }
784
785
    /**
786
     * Getter function of the newsletter column property, which is a flag whether the customer wants to receive the newsletter.
787
     * 0 => Customer doesn't want to receive the newsletter
788
     * 1 => Customer wants to receive the newsletter
789
     *
790
     * @return int
791
     */
792
    public function getNewsletter()
793
    {
794
        return $this->newsletter;
795
    }
796
797
    /**
798
     * Setter function of the validation column property.
799
     *
800
     * @param string $validation
801
     *
802
     * @return Customer
803
     */
804
    public function setValidation($validation)
805
    {
806
        $this->validation = $validation;
807
808
        return $this;
809
    }
810
811
    /**
812
     * Getter function of the validation column property.
813
     *
814
     * @return string
815
     */
816
    public function getValidation()
817
    {
818
        return $this->validation;
819
    }
820
821
    /**
822
     * Setter function for the affiliate column property, which is a flag whether the customer is a shop partner.
823
     * 0 => Customer isn't a shop partner
824
     * 1 => Customer is a shop partner
825
     *
826
     * @param int $affiliate
827
     *
828
     * @return Customer
829
     */
830
    public function setAffiliate($affiliate)
831
    {
832
        $this->affiliate = $affiliate;
833
834
        return $this;
835
    }
836
837
    /**
838
     * Getter function for the affiliate column property, which is a flag whether the customer is a shop partner.
839
     * 0 => Customer isn't a shop partner
840
     * 1 => Customer is a shop partner
841
     *
842
     * @return int
843
     */
844
    public function getAffiliate()
845
    {
846
        return $this->affiliate;
847
    }
848
849
    /**
850
     * Setter function for the paymentPreset column property, which is a flag whether a payment default has been filed
851
     *
852
     * @param int $paymentPreset
853
     *
854
     * @return Customer
855
     */
856
    public function setPaymentPreset($paymentPreset)
857
    {
858
        $this->paymentPreset = $paymentPreset;
859
860
        return $this;
861
    }
862
863
    /**
864
     * Getter function for the paymentPreset column property, which is a flag whether a payment default has been filed
865
     *
866
     * @return int
867
     */
868
    public function getPaymentPreset()
869
    {
870
        return $this->paymentPreset;
871
    }
872
873
    /**
874
     * Setter function for the referer column property.
875
     *
876
     * @param string $referer
877
     *
878
     * @return Customer
879
     */
880
    public function setReferer($referer)
881
    {
882
        $this->referer = $this->cleanup($referer);
883
884
        return $this;
885
    }
886
887
    /**
888
     * Getter function for the referer column property.
889
     *
890
     * @return string
891
     */
892
    public function getReferer()
893
    {
894
        return $this->referer;
895
    }
896
897
    /**
898
     * Setter function for the internalComment column property.
899
     *
900
     * @param string $internalComment
901
     *
902
     * @return Customer
903
     */
904
    public function setInternalComment($internalComment)
905
    {
906
        $this->internalComment = $this->cleanup($internalComment);
907
908
        return $this;
909
    }
910
911
    /**
912
     * Getter function for the internalComment column property.
913
     *
914
     * @return string
915
     */
916
    public function getInternalComment()
917
    {
918
        return $this->internalComment;
919
    }
920
921
    /**
922
     * Setter function for the failedLogins column property.
923
     *
924
     * @param int $failedLogins
925
     *
926
     * @return Customer
927
     */
928
    public function setFailedLogins($failedLogins)
929
    {
930
        $this->failedLogins = $failedLogins;
931
932
        return $this;
933
    }
934
935
    /**
936
     * Getter function for the failedLogins column property.
937
     *
938
     * @return int
939
     */
940
    public function getFailedLogins()
941
    {
942
        return $this->failedLogins;
943
    }
944
945
    /**
946
     * Setter function for the lockedUntil column property, which contains the time since the customer is logged into a session.
947
     * Expects a \DateTimeInterface object or a time string which will be converted to a \DateTime object.
948
     *
949
     * @param string|\DateTimeInterface|null $lockedUntil
950
     *
951
     * @return Customer
952
     */
953
    public function setLockedUntil($lockedUntil)
954
    {
955
        if (!$lockedUntil instanceof \DateTimeInterface) {
956
            $lockedUntil = new \DateTime($lockedUntil);
957
        }
958
        $this->lockedUntil = $lockedUntil;
959
960
        return $this;
961
    }
962
963
    /**
964
     * Getter function for the lockedUntil column property, which contains the time since the customer is logged into a session.
965
     *
966
     * @return \DateTimeInterface|null
967
     */
968
    public function getLockedUntil()
969
    {
970
        return $this->lockedUntil;
971
    }
972
973
    /**
974
     * Event listener method which is fired when the model is saved.
975
     * This method will also initialize the date time fields if these fields are null.
976
     *
977
     * @ORM\PrePersist()
978
     *
979
     * @throws \LogicException (See AttributeCleanerTrait)
980
     */
981
    public function onSave()
982
    {
983
        if ($this->firstLogin === null) {
984
            $this->firstLogin = new \DateTime();
985
        }
986
        if ($this->lastLogin === null) {
987
            $this->lastLogin = new \DateTime();
988
        }
989
990
        if (!empty($this->rawPassword)) {
991
            $this->hashPassword = $this->rawPassword;
992
        } elseif (!empty($this->password)) {
993
            $this->encoderName = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();
994
            $this->hashPassword = Shopware()->PasswordEncoder()->encodePassword($this->password, $this->encoderName);
995
        }
996
    }
997
998
    /**
999
     * Event listener method which is fired when the model is updated.
1000
     *
1001
     * @ORM\PreUpdate()
1002
     *
1003
     * @throws \LogicException (See AttributeCleanerTrait)
1004
     */
1005
    public function onUpdate()
1006
    {
1007
        if (!empty($this->rawPassword)) {
1008
            $this->hashPassword = $this->rawPassword;
1009
        } elseif (!empty($this->password)) {
1010
            $this->encoderName = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();
1011
            $this->hashPassword = Shopware()->PasswordEncoder()->encodePassword($this->password, $this->encoderName);
1012
        }
1013
1014
        $changeSet = Shopware()->Models()->getUnitOfWork()->getEntityChangeSet($this);
1015
1016
        $passwordChanged = isset($changeSet['hashPassword']) && $changeSet['hashPassword'][0] !== $changeSet['hashPassword'][1];
1017
1018
        if ($passwordChanged) {
1019
            $this->passwordChangeDate = new \DateTime();
1020
        }
1021
    }
1022
1023
    /**
1024
     * @return CustomerAttribute|null
1025
     */
1026
    public function getAttribute()
1027
    {
1028
        return $this->attribute;
1029
    }
1030
1031
    /**
1032
     * @param CustomerAttribute|array|null $attribute
1033
     *
1034
     * @return Customer
1035
     */
1036
    public function setAttribute($attribute)
1037
    {
1038
        return $this->setOneToOne($attribute, CustomerAttribute::class, 'attribute', 'customer');
1039
    }
1040
1041
    /**
1042
     * OWNING SIDE
1043
     * Getter function for the shop association property which contains an instance of the Shopware\Models\Shop\Shop model.
1044
     * The shop models contains all data about the shop, on which the customer has registered.
1045
     * The shop association is only used on the customer side.
1046
     *
1047
     * of the association between customers and shop
1048
     *
1049
     * @return Shop
1050
     */
1051
    public function getShop()
1052
    {
1053
        return $this->shop;
1054
    }
1055
1056
    /**
1057
     * Setter function for the shop association property which contains an instance of the Shopware\Models\Shop\Shop model.
1058
     * The shop models contains all data about the shop, on which the customer has registered.
1059
     * The shop association is only used on the customer side.
1060
     *
1061
     * @param Shop|array|null $shop
1062
     *
1063
     * @return Customer
1064
     */
1065
    public function setShop($shop)
1066
    {
1067
        $this->shop = $shop;
1068
1069
        return $this;
1070
    }
1071
1072
    /**
1073
     * Returns an array collection of Shopware\Models\Order\Order model instances, which
1074
     * contains all data about the a single customer order. The association is defined over
1075
     * the Customer.orders property (INVERSE SIDE) and the Order.customer (OWNING SIDE) property.
1076
     * The order data is joined over the s_order.userID field.
1077
     *
1078
     * @return ArrayCollection<\Shopware\Models\Order\Order>
0 ignored issues
show
Documentation introduced by
The doc-type ArrayCollection<\Shopware\Models\Order\Order> could not be parsed: Expected "|" or "end of type", but got "<" at position 15. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1079
     */
1080
    public function getOrders()
1081
    {
1082
        return $this->orders;
1083
    }
1084
1085
    /**
1086
     * Setter function for the orders association property which contains many instances of the Shopware\Models\Order\Order model which
1087
     * contains all data about the a single customer order. The association is defined over
1088
     * the Customer.orders property (INVERSE SIDE) and the Order.customer (OWNING SIDE) property.
1089
     * The order data is joined over the s_order.userID field.
1090
     *
1091
     * @param ArrayCollection<\Shopware\Models\Order\Order>|null $orders
0 ignored issues
show
Documentation introduced by
The doc-type ArrayCollection<\Shopwar...odels\Order\Order>|null could not be parsed: Expected "|" or "end of type", but got "<" at position 15. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1092
     *
1093
     * @return Customer
1094
     */
1095
    public function setOrders($orders)
1096
    {
1097
        $this->orders = $orders;
1098
1099
        return $this;
1100
    }
1101
1102
    /**
1103
     * OWNING SIDE
1104
     * Returns the instance of the Shopware\Models\Customer\Group model which
1105
     * contains all data about the customer group. The association is defined over
1106
     * the Customer.group property (OWNING SIDE) and the Group.customers (INVERSE SIDE) property.
1107
     * The group data is joined over the s_core_customergroup.id field.
1108
     *
1109
     * of the association between customers and group
1110
     *
1111
     * @return Group|null
1112
     */
1113
    public function getGroup()
1114
    {
1115
        /** @var Group|null $return */
1116
        $return = $this->fetchLazy($this->group, ['key' => $this->groupKey]);
1117
1118
        return $return;
1119
    }
1120
1121
    /**
1122
     * Setter function for the group association property which contains an instance of the Shopware\Models\Customer\Group model which
1123
     * contains all data about the customer group. The association is defined over
1124
     * the Customer.group property (OWNING SIDE) and the Group.customers (INVERSE SIDE) property.
1125
     * The group data is joined over the s_core_customergroup.id field.
1126
     *
1127
     * @param Group|array $group
1128
     *
1129
     * @return Customer
1130
     */
1131
    public function setGroup($group)
1132
    {
1133
        return $this->setManyToOne($group, Group::class, 'group');
1134
    }
1135
1136
    /**
1137
     * @return int
1138
     */
1139
    public function getPaymentId()
1140
    {
1141
        return $this->paymentId;
1142
    }
1143
1144
    /**
1145
     * @param int $paymentId
1146
     */
1147
    public function setPaymentId($paymentId)
1148
    {
1149
        $this->paymentId = $paymentId;
1150
    }
1151
1152
    /**
1153
     * @return PriceGroup|null
1154
     */
1155
    public function getPriceGroup()
1156
    {
1157
        return $this->priceGroup;
1158
    }
1159
1160
    /**
1161
     * @param PriceGroup|null $priceGroup
1162
     */
1163
    public function setPriceGroup($priceGroup)
1164
    {
1165
        $this->priceGroup = $priceGroup;
1166
    }
1167
1168
    public function setLanguageSubShop(Shop $languageSubShop)
1169
    {
1170
        $this->languageSubShop = $languageSubShop;
1171
1172
        $subShop = $languageSubShop->getMain() ?: $languageSubShop;
1173
        $this->setShop($subShop);
1174
    }
1175
1176
    /**
1177
     * @return Shop
1178
     */
1179
    public function getLanguageSubShop()
1180
    {
1181
        return $this->languageSubShop;
1182
    }
1183
1184
    public function setLanguageId(string $languageId): void
1185
    {
1186
        $this->languageId = $languageId;
1187
    }
1188
1189
    public function getLanguageId(): string
1190
    {
1191
        return $this->languageId;
1192
    }
1193
1194
    /**
1195
     * @param ArrayCollection<\Shopware\Models\Payment\PaymentInstance> $paymentInstances
0 ignored issues
show
Documentation introduced by
The doc-type ArrayCollection<\Shopwar...ayment\PaymentInstance> could not be parsed: Expected "|" or "end of type", but got "<" at position 15. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1196
     */
1197
    public function setPaymentInstances($paymentInstances)
1198
    {
1199
        $this->paymentInstances = $paymentInstances;
1200
    }
1201
1202
    /**
1203
     * @return ArrayCollection<\Shopware\Models\Payment\PaymentInstance>
0 ignored issues
show
Documentation introduced by
The doc-type ArrayCollection<\Shopwar...ayment\PaymentInstance> could not be parsed: Expected "|" or "end of type", but got "<" at position 15. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1204
     */
1205
    public function getPaymentInstances()
1206
    {
1207
        return $this->paymentInstances;
1208
    }
1209
1210
    /**
1211
     * @param ArrayCollection<\Shopware\Models\Customer\PaymentData> $paymentData
0 ignored issues
show
Documentation introduced by
The doc-type ArrayCollection<\Shopwar...s\Customer\PaymentData> could not be parsed: Expected "|" or "end of type", but got "<" at position 15. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1212
     */
1213
    public function setPaymentData($paymentData)
1214
    {
1215
        $this->paymentData = $paymentData;
1216
    }
1217
1218
    /**
1219
     * @return ArrayCollection<\Shopware\Models\Customer\PaymentData>
0 ignored issues
show
Documentation introduced by
The doc-type ArrayCollection<\Shopwar...s\Customer\PaymentData> could not be parsed: Expected "|" or "end of type", but got "<" at position 15. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1220
     */
1221
    public function getPaymentData()
1222
    {
1223
        return $this->paymentData;
1224
    }
1225
1226
    /**
1227
     * @param \Shopware\Models\Customer\PaymentData $paymentData
1228
     */
1229
    public function addPaymentData(PaymentData $paymentData)
1230
    {
1231
        $paymentData->setCustomer($this);
1232
1233
        $this->paymentData[] = $paymentData;
1234
    }
1235
1236
    /**
1237
     * @return string
1238
     */
1239
    public function getGroupKey()
1240
    {
1241
        return $this->groupKey;
1242
    }
1243
1244
    /**
1245
     * @return Address|null
1246
     */
1247
    public function getDefaultBillingAddress()
1248
    {
1249
        return $this->defaultBillingAddress;
1250
    }
1251
1252
    /**
1253
     * @param Address $defaultBillingAddress
1254
     *
1255
     * @return ModelEntity
1256
     */
1257
    public function setDefaultBillingAddress($defaultBillingAddress)
1258
    {
1259
        return $this->setOneToOne($defaultBillingAddress, Address::class, 'defaultBillingAddress', 'customer');
1260
    }
1261
1262
    /**
1263
     * @return Address|null
1264
     */
1265
    public function getDefaultShippingAddress()
1266
    {
1267
        return $this->defaultShippingAddress;
1268
    }
1269
1270
    /**
1271
     * @param Address $defaultShippingAddress
1272
     *
1273
     * @return ModelEntity
1274
     */
1275
    public function setDefaultShippingAddress($defaultShippingAddress)
1276
    {
1277
        return $this->setOneToOne($defaultShippingAddress, Address::class, 'defaultShippingAddress', 'customer');
1278
    }
1279
1280
    /**
1281
     * @return string
1282
     */
1283
    public function getSalutation()
1284
    {
1285
        return $this->salutation;
1286
    }
1287
1288
    /**
1289
     * @param string $salutation
1290
     */
1291
    public function setSalutation($salutation)
1292
    {
1293
        $this->salutation = $this->cleanup($salutation);
1294
    }
1295
1296
    /**
1297
     * @return string
1298
     */
1299
    public function getTitle()
1300
    {
1301
        return $this->title;
1302
    }
1303
1304
    /**
1305
     * @param string $title
1306
     */
1307
    public function setTitle($title)
1308
    {
1309
        $this->title = $this->cleanup($title);
1310
    }
1311
1312
    /**
1313
     * @return string
1314
     */
1315
    public function getFirstname()
1316
    {
1317
        return $this->firstname;
1318
    }
1319
1320
    /**
1321
     * @param string $firstname
1322
     */
1323
    public function setFirstname($firstname)
1324
    {
1325
        $this->firstname = $this->cleanup($firstname);
1326
    }
1327
1328
    /**
1329
     * @return string
1330
     */
1331
    public function getLastname()
1332
    {
1333
        return $this->lastname;
1334
    }
1335
1336
    /**
1337
     * @param string $lastname
1338
     */
1339
    public function setLastname($lastname)
1340
    {
1341
        $this->lastname = $this->cleanup($lastname);
1342
    }
1343
1344
    /**
1345
     * @return \DateTimeInterface
1346
     */
1347
    public function getBirthday()
1348
    {
1349
        return $this->birthday;
1350
    }
1351
1352
    /**
1353
     * @param \DateTimeInterface|string|null $birthday
1354
     */
1355
    public function setBirthday($birthday = null)
1356
    {
1357
        if (!$birthday instanceof \DateTimeInterface && $birthday !== null) {
1358
            $birthday = new \DateTime($birthday);
1359
        }
1360
1361
        $this->birthday = $birthday;
1362
    }
1363
1364
    /**
1365
     * @return string
1366
     */
1367
    public function getEncoderName()
1368
    {
1369
        return $this->encoderName;
1370
    }
1371
1372
    /**
1373
     * @param string $encoderName
1374
     */
1375
    public function setEncoderName($encoderName)
1376
    {
1377
        $this->encoderName = $encoderName;
1378
    }
1379
1380
    /**
1381
     * @return string|null
1382
     */
1383
    public function getNumber()
1384
    {
1385
        return $this->number;
1386
    }
1387
1388
    /**
1389
     * @param string|null $number
1390
     */
1391
    public function setNumber($number)
1392
    {
1393
        $this->number = $number;
1394
    }
1395
1396
    /**
1397
     * @return string
1398
     */
1399
    public function getCustomerType()
1400
    {
1401
        return $this->customerType;
1402
    }
1403
1404
    /**
1405
     * @param string $customerType
1406
     */
1407
    public function setCustomerType($customerType)
1408
    {
1409
        $this->customerType = $customerType;
1410
    }
1411
1412
    /**
1413
     * @return array
1414
     */
1415
    public function getAdditional()
1416
    {
1417
        return $this->additional;
1418
    }
1419
1420
    /**
1421
     * @param array $additional
1422
     */
1423
    public function setAdditional($additional)
1424
    {
1425
        $this->additional = $additional;
1426
    }
1427
1428
    /**
1429
     * @return bool
1430
     */
1431
    public function getDoubleOptinRegister()
1432
    {
1433
        return $this->doubleOptinRegister;
1434
    }
1435
1436
    /**
1437
     * @param bool $doubleOptinRegister
1438
     */
1439
    public function setDoubleOptinRegister($doubleOptinRegister)
1440
    {
1441
        $this->doubleOptinRegister = $doubleOptinRegister;
1442
    }
1443
1444
    /**
1445
     * @return \DateTimeInterface|null
1446
     */
1447
    public function getDoubleOptinEmailSentDate()
1448
    {
1449
        return $this->doubleOptinEmailSentDate;
1450
    }
1451
1452
    /**
1453
     * @param \DateTimeInterface|null $doubleOptinEmailSentDate
1454
     */
1455
    public function setDoubleOptinEmailSentDate($doubleOptinEmailSentDate)
1456
    {
1457
        $this->doubleOptinEmailSentDate = $doubleOptinEmailSentDate;
1458
    }
1459
1460
    /**
1461
     * @return \DateTimeInterface|null
1462
     */
1463
    public function getDoubleOptinConfirmDate()
1464
    {
1465
        return $this->doubleOptinConfirmDate;
1466
    }
1467
1468
    /**
1469
     * @param \DateTimeInterface|null $doubleOptinConfirmDate
1470
     */
1471
    public function setDoubleOptinConfirmDate($doubleOptinConfirmDate)
1472
    {
1473
        $this->doubleOptinConfirmDate = $doubleOptinConfirmDate;
1474
    }
1475
1476
    public function getPasswordChangeDate(): \DateTimeInterface
1477
    {
1478
        return $this->passwordChangeDate;
1479
    }
1480
1481
    /**
1482
     * @ORM\PrePersist()
1483
     * @ORM\PreUpdate()
1484
     */
1485
    public function updateChangedTimestamp()
1486
    {
1487
        $this->changed = new \DateTime();
1488
    }
1489
1490
    public function getRegisterOptInId(): ?int
1491
    {
1492
        return $this->registerOptInId;
1493
    }
1494
1495
    /**
1496
     * @param int $registerOptInId
1497
     */
1498
    public function setRegisterOptInId(int $registerOptInId = null): void
1499
    {
1500
        $this->registerOptInId = $registerOptInId;
1501
    }
1502
}
1503