Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
prepareCustomerData example
// Normalize call between create and update to allow same parameters
if
(
isset
(
$params
[
'defaultBillingAddress'
]
)
)
{
$params
[
'billing'
]
=
$params
[
'defaultBillingAddress'
]
;
unset
(
$params
[
'defaultBillingAddress'
]
)
;
}
if
(
isset
(
$params
[
'defaultShippingAddress'
]
)
)
{
$params
[
'shipping'
]
=
$params
[
'defaultShippingAddress'
]
;
unset
(
$params
[
'defaultShippingAddress'
]
)
;
}
$params
=
$this
->
prepareCustomerData
(
$params
,
$customer
)
;
$params
=
$this
->
prepareAssociatedData
(
$params
,
$customer
)
;
$customer
->
fromArray
(
$params
)
;
$billing
=
$this
->
createAddress
(
$params
[
'billing'
]
)
??
new
AddressModel
(
)
;
$shipping
=
$this
->
createAddress
(
$params
[
'shipping'
]
?? null
)
;
$registerService
=
$this
->
getContainer
(
)
->
get
(
RegisterServiceInterface::
class
)
;
$context
=
$this
->
getContainer
(
)
->
get
(
ContextServiceInterface::
class
)
->
getShopContext
(
)
->
getShop
(
)
;
$context
->
addAttribute
(
'sendOptinMail',
new
Attribute
(
[
'sendOptinMail'
=>
(
$params
[
'sendOptinMail'
]
?? false
)
=== true,
]
)
)
;
if
(
!
(
$paymentData
instanceof PaymentData
)
&& !
empty
(
$params
[
'paymentData'
]
)
&& !
empty
(
array_filter
(
$params
[
'paymentData'
]
[
0
]
)
)
)
{
$paymentData
=
new
PaymentData
(
)
;
$customer
->
addPaymentData
(
$paymentData
)
;
/** @var Payment $payment */
$payment
=
$this
->
getManager
(
)
->
getRepository
(
Payment::
class
)
->
find
(
$paymentId
)
;
$paymentData
->
setPaymentMean
(
$payment
)
;
}
$params
=
$this
->
prepareCustomerData
(
$params
,
$customer
,
$paymentData
)
;
// Set parameter to the customer model.
$customer
->
fromArray
(
$params
)
;
// If user will be activated, but the first login is still 0, because he was in doi-process
if
(
$customer
->
getActive
(
)
&&
(
!
$customer
->
getFirstLogin
(
)
||
$customer
->
getFirstLogin
(
)
->
getTimestamp
(
)
=== 0
)
)
{
$customer
->
setFirstLogin
(
new
DateTime
(
)
)
;
}
$password
=
$this
->
Request
(
)
->
getParam
(
'newPassword'
)
;