Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setAddress example
$viewData
->
setChangeShipping
(
(bool)
$changeableAddresses
->
get
(
'changeShipping'
)
)
;
$viewData
->
setChangeBilling
(
(bool)
$changeableAddresses
->
get
(
'changeBilling'
)
)
;
$addressId
=
$dataBag
->
get
(
'id'
)
;
if
(
!
$addressId
)
{
return
;
}
$viewData
->
setAddress
(
$this
->
getById
(
$addressId
,
$context
,
$customer
)
)
;
}
/** * @throws CustomerNotLoggedInException * @throws InvalidUuidException */
private
function
handleAddressSelection
(
AddressEditorModalStruct
$viewData
,
RequestDataBag
$dataBag
,
SalesChannelContext
$context
,
CustomerEntity
$customer
)
:
if
(
$page
->
getMetaInformation
(
)
)
{
$page
->
getMetaInformation
(
)
->
setRobots
(
'noindex,follow'
)
;
}
$page
->
setCountries
(
$this
->
getCountries
(
$salesChannelContext
)
)
;
$page
->
setCart
(
$this
->cartService->
getCart
(
$salesChannelContext
->
getToken
(
)
,
$salesChannelContext
)
)
;
$page
->
setSalutations
(
$this
->
getSalutations
(
$salesChannelContext
)
)
;
$addressId
=
$request
->attributes->
get
(
'addressId'
)
;
if
(
$addressId
)
{
$address
=
$this
->
getById
(
(string)
$addressId
,
$salesChannelContext
)
;
$page
->
setAddress
(
$address
)
;
}
$this
->eventDispatcher->
dispatch
(
new
CheckoutRegisterPageLoadedEvent
(
$page
,
$salesChannelContext
,
$request
)
)
;
return
$page
;
}
private
function
getById
(
string
$addressId
, SalesChannelContext
$context
)
: CustomerAddressEntity
{
$page
->
setSalutations
(
$this
->
getSalutations
(
$salesChannelContext
)
)
;
$page
->
setCountries
(
$this
->
getCountries
(
$salesChannelContext
)
)
;
$criteria
=
(
new
Criteria
(
)
)
->
addSorting
(
new
FieldSorting
(
'firstName', FieldSorting::ASCENDING
)
)
;
$page
->
setAddresses
(
$this
->listAddressRoute->
load
(
$criteria
,
$salesChannelContext
,
$customer
)
->
getAddressCollection
(
)
)
;
$page
->
setCart
(
$this
->cartService->
getCart
(
$salesChannelContext
->
getToken
(
)
,
$salesChannelContext
)
)
;
$page
->
setAddress
(
$page
->
getAddresses
(
)
->
get
(
$request
->
get
(
'addressId'
)
)
)
;
$this
->eventDispatcher->
dispatch
(
new
AddressListingPageLoadedEvent
(
$page
,
$salesChannelContext
,
$request
)
)
;
return
$page
;
}
/** * @throws InconsistentCriteriaIdsException */
$page
= AddressDetailPage::
createFrom
(
$page
)
;
if
(
$page
->
getMetaInformation
(
)
)
{
$page
->
getMetaInformation
(
)
->
setRobots
(
'noindex,follow'
)
;
}
$page
->
setSalutations
(
$this
->
getSalutations
(
$salesChannelContext
)
)
;
$page
->
setCountries
(
$this
->
getCountries
(
$salesChannelContext
)
)
;
$page
->
setAddress
(
$this
->
getAddress
(
$request
,
$salesChannelContext
,
$customer
)
)
;
$this
->eventDispatcher->
dispatch
(
new
AddressDetailPageLoadedEvent
(
$page
,
$salesChannelContext
,
$request
)
)
;
return
$page
;
}
/** * @throws InconsistentCriteriaIdsException */
final
class
MailboxHeader
extends
AbstractHeader
{
private
Address
$address
;
public
function
__construct
(
string
$name
, Address
$address
)
{
parent::
__construct
(
$name
)
;
$this
->
setAddress
(
$address
)
;
}
/** * @param Address $body * * @throws RfcComplianceException */
public
function
setBody
(
mixed
$body
)
: void
{
$this
->
setAddress
(
$body
)
;
}
final
class
MailboxHeader
extends
AbstractHeader
{
private
Address
$address
;
public
function
__construct
(
string
$name
, Address
$address
)
{
parent::
__construct
(
$name
)
;
$this
->
setAddress
(
$address
)
;
}
/** * @param Address $body * * @throws RfcComplianceException */
public
function
setBody
(
mixed
$body
)
: void
{
$this
->
setAddress
(
$body
)
;
}
final
class
PathHeader
extends
AbstractHeader
{
private
Address
$address
;
public
function
__construct
(
string
$name
, Address
$address
)
{
parent::
__construct
(
$name
)
;
$this
->
setAddress
(
$address
)
;
}
/** * @param Address $body * * @throws RfcComplianceException */
public
function
setBody
(
mixed
$body
)
: void
{
$this
->
setAddress
(
$body
)
;
}
final
class
PathHeader
extends
AbstractHeader
{
private
Address
$address
;
public
function
__construct
(
string
$name
, Address
$address
)
{
parent::
__construct
(
$name
)
;
$this
->
setAddress
(
$address
)
;
}
/** * @param Address $body * * @throws RfcComplianceException */
public
function
setBody
(
mixed
$body
)
: void
{
$this
->
setAddress
(
$body
)
;
}
$header
=
new
MailboxHeader
(
'Sender',
$address
=
new
Address
(
'fabien@symfony.com'
)
)
;
$this
->
assertEquals
(
$address
,
$header
->
getAddress
(
)
)
;
$this
->
assertEquals
(
$address
,
$header
->
getBody
(
)
)
;
}
public
function
testAddress
(
)
{
$header
=
new
MailboxHeader
(
'Sender',
new
Address
(
'fabien@symfony.com'
)
)
;
$header
->
setBody
(
$address
=
new
Address
(
'helene@symfony.com'
)
)
;
$this
->
assertEquals
(
$address
,
$header
->
getAddress
(
)
)
;
$this
->
assertEquals
(
$address
,
$header
->
getBody
(
)
)
;
$header
->
setAddress
(
$address
=
new
Address
(
'thomas@symfony.com'
)
)
;
$this
->
assertEquals
(
$address
,
$header
->
getAddress
(
)
)
;
$this
->
assertEquals
(
$address
,
$header
->
getBody
(
)
)
;
}
public
function
testgetBodyAsString
(
)
{
$header
=
new
MailboxHeader
(
'Sender',
new
Address
(
'fabien@symfony.com'
)
)
;
$this
->
assertEquals
(
'fabien@symfony.com',
$header
->
getBodyAsString
(
)
)
;
$header
->
setAddress
(
new
Address
(
'fabien@sïmfony.com'
)
)
;
$this
->
assertEquals
(
'fabien@xn--smfony-iwa.com',
$header
->
getBodyAsString
(
)
)
;