Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
AddressModel example
throw
new
NotFoundException
(
sprintf
(
'Customer by id %s not found',
$customerId
)
)
;
}
$this
->
setupContext
(
$customer
->
getShop
(
)
->
getId
(
)
)
;
if
(
!
$params
[
'country'
]
)
{
throw
new
CustomValidationException
(
'A country is required.'
)
;
}
$params
=
$this
->
prepareAddressData
(
$params
)
;
$address
=
new
AddressModel
(
)
;
$address
->
fromArray
(
$params
)
;
$this
->addressService->
create
(
$address
,
$customer
)
;
if
(
!
empty
(
$params
[
'__options_set_default_billing_address'
]
)
)
{
$this
->addressService->
setDefaultBillingAddress
(
$address
)
;
}
if
(
!
empty
(
$params
[
'__options_set_default_shipping_address'
]
)
)
{
$this
->addressService->
setDefaultShippingAddress
(
$address
)
;
}
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,
]
)
)
;
$registerService
->
register
(
$context
,
$customer
,
$billing
,
$shipping
)
;