mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Admin][Taxon] Fallback from parent code to id when generating a slug
This commit is contained in:
parent
2d5aa6864f
commit
a24c696fdf
2 changed files with 16 additions and 6 deletions
|
|
@ -106,8 +106,6 @@ Feature: Editing taxon's slug
|
|||
And I save my changes
|
||||
Then the slug of the "Renaissance weapons" taxon should be "renaissance"
|
||||
|
||||
|
||||
|
||||
@ui @javascript
|
||||
Scenario: Automatically changing a child taxon's slug when changing the parent
|
||||
Given the store has "Renaissance weapons" taxonomy
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ final class TaxonSlugController
|
|||
}
|
||||
|
||||
$locale = (string) $request->query->get('locale');
|
||||
$parentCode = $request->query->get('parentCode');
|
||||
|
||||
/** @var TaxonInterface $taxon */
|
||||
$taxon = $this->taxonFactory->createNew();
|
||||
|
|
@ -47,12 +46,25 @@ final class TaxonSlugController
|
|||
$taxon->setFallbackLocale($locale);
|
||||
$taxon->setName($name);
|
||||
|
||||
if (null !== $parentCode) {
|
||||
$taxon->setParent($this->taxonRepository->findOneBy(['code' => $parentCode]));
|
||||
}
|
||||
$taxon->setParent($this->getParentTaxon($request));
|
||||
|
||||
return new JsonResponse([
|
||||
'slug' => $this->taxonSlugGenerator->generate($taxon, $locale),
|
||||
]);
|
||||
}
|
||||
|
||||
private function getParentTaxon(Request $request): ?TaxonInterface
|
||||
{
|
||||
$parentCode = $request->query->get('parentCode');
|
||||
if (null !== $parentCode) {
|
||||
return $this->taxonRepository->findOneBy(['code' => $parentCode]);
|
||||
}
|
||||
|
||||
$parentId = $request->query->get('parentId');
|
||||
if (null !== $parentId) {
|
||||
return $this->taxonRepository->find($parentId);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue