Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
CustomerCollection example
return
$this
->
fmap
(
fn
(
OrderCustomerEntity
$orderCustomer
)
=>
$orderCustomer
->
getCustomerId
(
)
)
;
}
public
function
filterByCustomerId
(
string
$id
)
: self
{
return
$this
->
filter
(
fn
(
OrderCustomerEntity
$orderCustomer
)
=>
$orderCustomer
->
getCustomerId
(
)
===
$id
)
;
}
public
function
getCustomers
(
)
: CustomerCollection
{
return
new
CustomerCollection
(
$this
->
fmap
(
fn
(
OrderCustomerEntity
$orderCustomer
)
=>
$orderCustomer
->
getCustomer
(
)
)
)
;
}
public
function
getLastOrderDate
(
)
: ?\DateTimeInterface
{
$lastOrderDate
= null;
foreach
(
$this
->
getOrders
(
)
as
$order
)
{
if
(
!
$lastOrderDate
||
$order
->
getOrderDate
(
)
<
$lastOrderDate
)
{
$lastOrderDate
=
$order
->
getOrderDate
(
)
;
}
public
function
testConfirmCustomer
(
)
: void
{
$customer
=
$this
->
mockCustomer
(
)
;
$this
->customerRepository->
expects
(
static
::
exactly
(
2
)
)
->
method
(
'search'
)
->
willReturn
(
new
EntitySearchResult
(
'customer',
1,
new
CustomerCollection
(
[
$customer
]
)
,
null,
new
Criteria
(
)
,
$this
->context->
getContext
(
)
)
)
;
$confirmResult
=
$this
->route->
confirm
(
$this
->
mockRequestDataBag
(
)
,
$this
->context
)
;
static
::
assertTrue
(
$confirmResult
->headers->
has
(
PlatformRequest::HEADER_CONTEXT_TOKEN
)
)
;
}
'isValid' => true
]
,
json_decode
(
$response
->
getContent
(
)
, true, 512, \JSON_THROW_ON_ERROR
)
)
;
}
public
function
testCheckCustomerEmailValidWithConstraintException
(
)
: void
{
static
::
expectException
(
ConstraintViolationException::
class
)
;
$customer
=
$this
->
mockCustomer
(
)
;
$this
->
createInstance
(
new
CustomerCollection
(
[
$customer
]
)
)
;
$request
=
new
Request
(
[
]
,
[
'email' => '
[email protected]
'
]
)
;
$this
->administrationController->
checkCustomerEmailValid
(
$request
,
$this
->context
)
;
}
public
function
testCheckCustomerEmailValidWithBoundSalesChannelIdInvalid
(
)
: void
{
if
(
Feature::
isActive
(
'v6.6.0.0'
)
)
{
$this
->
expectException
(
RoutingException::
class
)
;
}
else
{
$this
->
expectException
(
InvalidRequestParameterException::
class
)
;
}
return
$this
->
fmap
(
fn
(
OrderEntity
$order
)
=>
$order
->
getSalesChannelId
(
)
)
;
}
public
function
filterBySalesChannelId
(
string
$id
)
: self
{
return
$this
->
filter
(
fn
(
OrderEntity
$order
)
=>
$order
->
getSalesChannelId
(
)
===
$id
)
;
}
public
function
getOrderCustomers
(
)
: CustomerCollection
{
return
new
CustomerCollection
(
$this
->
fmap
(
fn
(
OrderEntity
$order
)
=>
$order
->
getOrderCustomer
(
)
)
)
;
}
public
function
getCurrencies
(
)
: CurrencyCollection
{
return
new
CurrencyCollection
(
$this
->
fmap
(
fn
(
OrderEntity
$order
)
=>
$order
->
getCurrency
(
)
)
)
;
}
$customer1
=
new
CustomerEntity
(
)
;
$customer1
->
setId
(
'C1'
)
;
$customer1
->
setCustomerNumber
(
'C1'
)
;
$customer2
=
new
CustomerEntity
(
)
;
$customer2
->
setId
(
'C2'
)
;
$customer2
->
setCustomerNumber
(
'C2'
)
;
$promotion
=
new
PromotionEntity
(
)
;
$promotion
->
setCustomerRestriction
(
true
)
;
$promotion
->
setPersonaCustomers
(
new
CustomerCollection
(
[
$customer1
,
$customer2
]
)
)
;
$custRule1
=
new
CustomerNumberRule
(
)
;
$custRule1
->
assign
(
[
'numbers' =>
[
'C1'
]
, 'operator' => Rule::OPERATOR_EQ
]
)
;
$custRule2
=
new
CustomerNumberRule
(
)
;
$custRule2
->
assign
(
[
'numbers' =>
[
'C2'
]
, 'operator' => Rule::OPERATOR_EQ
]
)
;
$expected
=
new
AndRule
(
[
// this is the customer rules OR condition
new
OrRule
(
[
public
function
testGroupRegistrationAcceptMatches
(
?int
$expectedResCode
, ?array
$customers
, Request
$request
, ?string
$errorMessage
)
: void
{
$context
= Context::
createDefaultContext
(
)
;
if
(
$customers
!== null
)
{
$customerCollection
=
new
CustomerCollection
(
$customers
)
;
$this
->
setRestorerReturn
(
)
;
$this
->
setSearchReturn
(
$context
,
$customerCollection
)
;
$this
->
setCustomerGroupSearchReturn
(
$context
)
;
}
if
(
$errorMessage
!== null &&
$expectedResCode
=== null
)
{
static
::
expectExceptionMessage
(
$errorMessage
)
;
}
$res
=
$this
->controllerMock->
accept
(
$request
,
$context
)
;
static
::
assertSame
(
$expectedResCode
,
$res
->
getStatusCode
(
)
)
;
}