Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setLastLogin example
if
(
$customer
->
getBirthday
(
)
)
{
$customer
->
setAge
(
$customer
->
getBirthday
(
)
->
diff
(
new
DateTime
(
)
)
->y
)
;
}
if
(
!
empty
(
$data
[
'__customer_lockeduntil'
]
)
)
{
$customer
->
setLockedUntil
(
new
DateTime
(
$data
[
'__customer_lockeduntil'
]
)
)
;
}
if
(
!
empty
(
$data
[
'__customer_firstlogin'
]
)
)
{
$customer
->
setFirstLogin
(
new
DateTime
(
$data
[
'__customer_firstlogin'
]
)
)
;
}
if
(
!
empty
(
$data
[
'__customer_lastlogin'
]
)
)
{
$customer
->
setLastLogin
(
new
DateTime
(
$data
[
'__customer_lastlogin'
]
)
)
;
}
if
(
$data
[
'__customer_customergroup'
]
)
{
$customer
->
setCustomerGroup
(
$this
->customerGroupHydrator->
hydrate
(
$data
)
)
;
}
if
(
isset
(
$data
[
'__customerAttribute_id'
]
)
)
{
$this
->attributeHydrator->
addAttribute
(
$customer
,
$data
, 'customerAttribute'
)
;
}
public
function
testIfMatchesCorrect
(
string
$operator
,
bool
$isMatching
,
float
$daysPassed
,
?\DateTimeImmutable
$day
,
bool
$noCustomer
= false
)
: void
{
$salesChannelContext
=
$this
->
createMock
(
SalesChannelContext::
class
)
;
$customer
=
new
CustomerEntity
(
)
;
$customer
->
setLastLogin
(
$day
)
;
if
(
$noCustomer
)
{
$customer
= null;
}
$salesChannelContext
->
method
(
'getCustomer'
)
->
willReturn
(
$customer
)
;
$scope
=
$this
->
createMock
(
CheckoutRuleScope::
class
)
;
$scope
->
method
(
'getSalesChannelContext'
)
->
willReturn
(
$salesChannelContext
)
;
$scope
->
method
(
'getCurrentTime'
)
->
willReturn
(
self::
getTestTimestamp
(
)
)
;
$this
->rule->
assign
(
[
'operator' =>
$operator
,
if
(
$customer
->
getValidation
(
)
!== ContextService::FALLBACK_CUSTOMER_GROUP
)
{
$customer
->
setCustomerType
(
Customer::CUSTOMER_TYPE_BUSINESS
)
;
}
$customerConfirmed
= !
$customer
->
getDoubleOptinRegister
(
)
||
$customer
->
getDoubleOptinConfirmDate
(
)
!== null;
$customer
->
setActive
(
$customerConfirmed
)
;
if
(
!
$customerConfirmed
)
{
// Reset login information if Double-Opt-In is active
$customer
->
setFirstLogin
(
null
)
;
$customer
->
setLastLogin
(
null
)
;
$customer
->
setDoubleOptinEmailSentDate
(
new
DateTime
(
)
)
;
}
// Password validation
if
(
$customer
->
getPassword
(
)
)
{
$customer
->
setEncoderName
(
$this
->passwordManager->
getDefaultPasswordEncoderName
(
)
)
;
$customer
->
setPassword
(
$this
->passwordManager->
encodePassword
(
$customer
->
getPassword
(
)
,