在 Shopware 6 中创建新类别出现错误 /0/translations/2fbb5fe2e29a4d70aa5854ce7ce3e20b/name
Create a new category in Shopware 6 get error /0/translations/2fbb5fe2e29a4d70aa5854ce7ce3e20b/name
尝试创建新类别时出现此错误。
/0/translations/2fbb5fe2e29a4d70aa5854ce7ce3e20b/name This value should not be blank.
这是我的数组:(如你所见。我的错误与键名有关。但键名有一个值)
[
0 => [
"categories" => [
"id" => "7767b163a5124c83ad8f6c701ffabade",
"parentId" => null,
"name" => "Supply",
"path" => "professional",
"level" => 5,
"active" => true,
"description" => null,
"translations" => [
"2fbb5fe2e29a4d70aa5854ce7ce3e20b" =>[
"defaultLanguageId"=>"2fbb5fe2e29a4d70aa5854ce7ce3e20b",
"name" => "Professional",
"metaTitle" => "",
"metaDescription" => "",
"description" => "",
],
"f7e5c2a4bb194c339714f9798d8f853d" => [
"name" => "Materiale Profession",
"defaultLanguageId"=>"2fbb5fe2e29a4d70aa5854ce7ce3e20b",
"metaTitle" => "",
"metaDescription" => "",
"description" => "",
],
"51d36b57c6144235bcb0332a3ca20a5c" => [
"name" => "Profesional",
"defaultLanguageId"=>"2fbb5fe2e29a4d70aa5854ce7ce3e20b",
"metaTitle" => "",
"metaDescription" => "",
"description" => "",
],
"66623e62998e42c695fba0d22b023c63" =>[
"name" => "Professionnel",
"defaultLanguageId"=>"2fbb5fe2e29a4d70aa5854ce7ce3e20b",
"metaTitle" => "",
"metaDescription" => "",
"description" => "",
],
]
]
]]
此外,如果没有翻译,它是行不通的。
我对创建产品没有问题。
$this->productRepository->create($products, $context);
只有在我要创建类别时才会出现此错误
$this->categoryRepository->create($category, $context);
有人知道我的问题出在哪里吗?
我认为错误的原因是您的示例中的额外 categories
数组键。存储库需要一个关联数组列表,其中实体的字段作为键,这意味着在您的示例中您只提供 categories
字段,它不是有效的类别有效负载。
此外,在您的情况下,您可以大大简化代码,因为您似乎只想更新不同语言的名称。
您可以尝试以下负载:
[
0 => [
"id" => "7767b163a5124c83ad8f6c701ffabade",
"parentId" => null,
"name" => [
"2fbb5fe2e29a4d70aa5854ce7ce3e20b" => "Professional",
"f7e5c2a4bb194c339714f9798d8f853d" => "Materiale Profession",
...
],
"path" => "professional",
"level" => 5,
"active" => true,
"description" => null,
]
]
注意缺少数组索引 categories
。
尝试创建新类别时出现此错误。
/0/translations/2fbb5fe2e29a4d70aa5854ce7ce3e20b/name This value should not be blank.
这是我的数组:(如你所见。我的错误与键名有关。但键名有一个值)
[
0 => [
"categories" => [
"id" => "7767b163a5124c83ad8f6c701ffabade",
"parentId" => null,
"name" => "Supply",
"path" => "professional",
"level" => 5,
"active" => true,
"description" => null,
"translations" => [
"2fbb5fe2e29a4d70aa5854ce7ce3e20b" =>[
"defaultLanguageId"=>"2fbb5fe2e29a4d70aa5854ce7ce3e20b",
"name" => "Professional",
"metaTitle" => "",
"metaDescription" => "",
"description" => "",
],
"f7e5c2a4bb194c339714f9798d8f853d" => [
"name" => "Materiale Profession",
"defaultLanguageId"=>"2fbb5fe2e29a4d70aa5854ce7ce3e20b",
"metaTitle" => "",
"metaDescription" => "",
"description" => "",
],
"51d36b57c6144235bcb0332a3ca20a5c" => [
"name" => "Profesional",
"defaultLanguageId"=>"2fbb5fe2e29a4d70aa5854ce7ce3e20b",
"metaTitle" => "",
"metaDescription" => "",
"description" => "",
],
"66623e62998e42c695fba0d22b023c63" =>[
"name" => "Professionnel",
"defaultLanguageId"=>"2fbb5fe2e29a4d70aa5854ce7ce3e20b",
"metaTitle" => "",
"metaDescription" => "",
"description" => "",
],
]
]
]]
此外,如果没有翻译,它是行不通的。 我对创建产品没有问题。
$this->productRepository->create($products, $context);
只有在我要创建类别时才会出现此错误
$this->categoryRepository->create($category, $context);
有人知道我的问题出在哪里吗?
我认为错误的原因是您的示例中的额外 categories
数组键。存储库需要一个关联数组列表,其中实体的字段作为键,这意味着在您的示例中您只提供 categories
字段,它不是有效的类别有效负载。
此外,在您的情况下,您可以大大简化代码,因为您似乎只想更新不同语言的名称。
您可以尝试以下负载:
[
0 => [
"id" => "7767b163a5124c83ad8f6c701ffabade",
"parentId" => null,
"name" => [
"2fbb5fe2e29a4d70aa5854ce7ce3e20b" => "Professional",
"f7e5c2a4bb194c339714f9798d8f853d" => "Materiale Profession",
...
],
"path" => "professional",
"level" => 5,
"active" => true,
"description" => null,
]
]
注意缺少数组索引 categories
。