Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
filterByLanguageId example
$criteria
=
new
Criteria
(
[
$id
]
)
;
$criteria
->
addAssociation
(
'translations'
)
;
/** @var CategoryEntity $cat */
$cat
=
$repo
->
search
(
$criteria
, Context::
createDefaultContext
(
)
)
->
first
(
)
;
$catTranslations
=
$cat
->
getTranslations
(
)
;
static
::
assertNotNull
(
$catTranslations
)
;
static
::
assertCount
(
2,
$catTranslations
)
;
/** @var CategoryTranslationEntity $transDe */
$transDe
=
$catTranslations
->
filterByLanguageId
(
$this
->deLanguageId
)
->
first
(
)
;
static
::
assertEquals
(
'deutsch',
$transDe
->
getName
(
)
)
;
/** @var CategoryTranslationEntity $transSystem */
$transSystem
=
$catTranslations
->
filterByLanguageId
(
Defaults::LANGUAGE_SYSTEM
)
->
first
(
)
;
static
::
assertEquals
(
'system',
$transSystem
->
getName
(
)
)
;
}
public
function
testPricesAreConvertedWithCurrencyFactor
(
)
: void
{
$productId
= Uuid::
randomHex
(
)
;
$repository
->
create
(
[
$data
]
,
$context
)
;
$criteria
=
new
Criteria
(
[
$id
]
)
;
$criteria
->
addAssociation
(
'translations'
)
;
/** @var CategoryEntity $category */
$category
=
$repository
->
search
(
$criteria
,
$context
)
->
first
(
)
;
static
::
assertInstanceOf
(
CategoryTranslationCollection::
class
,
$category
->
getTranslations
(
)
)
;
/** @var CategoryTranslationEntity $enTranslation */
$enTranslation
=
$category
->
getTranslations
(
)
->
filterByLanguageId
(
Defaults::LANGUAGE_SYSTEM
)
->
first
(
)
;
static
::
assertEquals
(
'en translation',
$enTranslation
->
getName
(
)
)
;
/** @var CategoryTranslationEntity $deTranslation */
$deTranslation
=
$category
->
getTranslations
(
)
->
filterByLanguageId
(
$this
->
getDeDeLanguageId
(
)
)
->
first
(
)
;
static
::
assertEquals
(
'de übersetzung',
$deTranslation
->
getName
(
)
)
;
}
public
function
testTranslationValuesHavePriorityOverDefaultValueWithIds
(
)
: void
{
$context
= Context::
createDefaultContext
(
)
;