From 6798d16333bea55d250fcd1f4f23d06041400ec0 Mon Sep 17 00:00:00 2001 From: Rafikooo Date: Thu, 11 Dec 2025 12:03:34 +0100 Subject: [PATCH 1/2] [Admin] Remove choice_value from autocomplete types to fix performance issue When choice_value is set to 'code' on Symfony UX Autocomplete types, DoctrineChoiceLoader cannot use optimized getEntitiesByIds() query, causing ALL entities to be loaded instead of just the selected ones. This change removes choice_value from all UX Autocomplete types, letting Symfony use the default entity ID which enables the optimized WHERE id IN (...) query. Refs: #17953 --- .../AdminBundle/Form/Type/ChannelPriceHistoryConfigType.php | 1 - .../AdminBundle/Form/Type/ProductAttributeAutocompleteType.php | 1 - .../Bundle/AdminBundle/Form/Type/ProductAutocompleteType.php | 1 - src/Sylius/Bundle/AdminBundle/Form/Type/ProductImageType.php | 1 - .../AdminBundle/Form/Type/ProductVariantAutocompleteType.php | 1 - .../Bundle/AdminBundle/Form/Type/TaxonAutocompleteType.php | 1 - .../Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php | 2 +- .../ProductBundle/Form/Type/ProductOptionAutocompleteType.php | 1 - 8 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Sylius/Bundle/AdminBundle/Form/Type/ChannelPriceHistoryConfigType.php b/src/Sylius/Bundle/AdminBundle/Form/Type/ChannelPriceHistoryConfigType.php index 3f29dce0f19..9ba58efa6d1 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Type/ChannelPriceHistoryConfigType.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Type/ChannelPriceHistoryConfigType.php @@ -44,7 +44,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'required' => false, 'multiple' => true, 'expanded' => false, - 'choice_value' => 'code', ]) ; diff --git a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAttributeAutocompleteType.php b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAttributeAutocompleteType.php index 7aab23edfff..6af348deaeb 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAttributeAutocompleteType.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAttributeAutocompleteType.php @@ -33,7 +33,6 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefaults([ 'class' => $this->productAttributeClass, 'choice_name' => 'name', - 'choice_value' => 'code', ]); } diff --git a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAutocompleteType.php b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAutocompleteType.php index 12e534608c3..d78570512f4 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAutocompleteType.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductAutocompleteType.php @@ -33,7 +33,6 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefaults([ 'class' => $this->productClass, 'choice_name' => 'name', - 'choice_value' => 'code', ]); } diff --git a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductImageType.php b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductImageType.php index 38890a3017d..853908d73d9 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductImageType.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductImageType.php @@ -37,7 +37,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'multiple' => true, 'required' => false, 'choice_label' => 'descriptor', - 'choice_value' => 'code', 'query_builder' => function (EntityRepository $er) use ($options): QueryBuilder { return $er->createQueryBuilder('o') ->where('o.product = :product') diff --git a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductVariantAutocompleteType.php b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductVariantAutocompleteType.php index 99338cea05f..94cecf7947c 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Type/ProductVariantAutocompleteType.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Type/ProductVariantAutocompleteType.php @@ -33,7 +33,6 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefaults([ 'class' => $this->productVariantClass, 'choice_name' => 'descriptor', - 'choice_value' => 'code', ]); } diff --git a/src/Sylius/Bundle/AdminBundle/Form/Type/TaxonAutocompleteType.php b/src/Sylius/Bundle/AdminBundle/Form/Type/TaxonAutocompleteType.php index adb0cf38d96..da65cb1372d 100644 --- a/src/Sylius/Bundle/AdminBundle/Form/Type/TaxonAutocompleteType.php +++ b/src/Sylius/Bundle/AdminBundle/Form/Type/TaxonAutocompleteType.php @@ -33,7 +33,6 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefaults([ 'class' => $this->taxonClass, 'choice_label' => 'fullname', - 'choice_value' => 'code', ]); } diff --git a/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php b/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php index 4220bc1545f..b2f7355315f 100644 --- a/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php +++ b/src/Sylius/Bundle/AdminBundle/Twig/Component/Taxon/FormComponent.php @@ -53,7 +53,7 @@ public function __construct( public function generateTaxonSlug(#[LiveArg] string $localeCode): void { $name = $this->formValues['translations'][$localeCode]['name']; - $parent = $this->repository->findOneBy(['code' => $this->formValues['parent']]); + $parent = $this->repository->find($this->formValues['parent']); $this->formValues['translations'][$localeCode]['slug'] = $this->slugGenerator->generate($name, $localeCode, $parent); } diff --git a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductOptionAutocompleteType.php b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductOptionAutocompleteType.php index edc5f89af5d..ef4f31ca40b 100644 --- a/src/Sylius/Bundle/ProductBundle/Form/Type/ProductOptionAutocompleteType.php +++ b/src/Sylius/Bundle/ProductBundle/Form/Type/ProductOptionAutocompleteType.php @@ -24,7 +24,6 @@ final class ProductOptionAutocompleteType extends AbstractType public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'choice_value' => 'code', 'choice_name' => 'name', 'resource' => 'sylius.product_option', ]); From 062a7ebc84690b3a9ee5bab71bf24ab56d644a51 Mon Sep 17 00:00:00 2001 From: Rafikooo Date: Thu, 11 Dec 2025 12:04:12 +0100 Subject: [PATCH 2/2] [Behat] Update tests to work with entity IDs instead of codes in autocomplete After removing choice_value from autocomplete types, the form values are now entity IDs instead of codes. This commit updates Behat tests to: - Use selectByName/removeByName instead of selectByValue/removeByValue - Use getSelectedItems() or option[selected] text for assertions - Compare with entity names instead of codes - Add JS/non-JS driver handling for parent taxon selection Refs: #17953 --- .../ManagingCatalogPromotionsContext.php | 40 +++++++++---------- .../Ui/Admin/ManagingProductsContext.php | 9 ++++- .../Ui/Admin/ManagingTaxonsContext.php | 2 +- .../Admin/CatalogPromotion/FormElement.php | 20 +++++----- .../CatalogPromotion/FormElementInterface.php | 6 +-- ...xonsFromShowingLowestPriceInputElement.php | 8 ++-- .../Admin/Product/AssociationsFormElement.php | 11 +++-- .../Admin/Product/MediaFormElement.php | 30 +++++++++++--- .../Product/MediaFormElementInterface.php | 2 + .../Behat/Element/Admin/Taxon/FormElement.php | 15 ++++++- 10 files changed, 94 insertions(+), 49 deletions(-) diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php index 2bcc04343b4..ddef7d30bc9 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php @@ -224,10 +224,10 @@ public function iAddANewCatalogPromotionScope(): void */ public function iAddScopeThatAppliesOnVariants(ProductVariantInterface ...$variants): void { - $variantCodes = array_map(fn (ProductVariantInterface $variant) => $variant->getCode(), $variants); + $variantNames = array_map(fn (ProductVariantInterface $variant) => $variant->getName(), $variants); $this->formElement->addScope(InForVariantsScopeVariantChecker::TYPE); - $this->formElement->selectScopeOption($variantCodes); + $this->formElement->selectScopeOption($variantNames); } /** @@ -235,10 +235,10 @@ public function iAddScopeThatAppliesOnVariants(ProductVariantInterface ...$varia */ public function iAddScopeThatAppliesOnTaxons(TaxonInterface ...$taxons): void { - $taxonsCodes = array_map(fn (TaxonInterface $taxon) => $taxon->getCode(), $taxons); + $taxonNames = array_map(fn (TaxonInterface $taxon) => $taxon->getName(), $taxons); $this->formElement->addScope(InForTaxonsScopeVariantChecker::TYPE); - $this->formElement->selectScopeOption($taxonsCodes); + $this->formElement->selectScopeOption($taxonNames); } /** @@ -247,7 +247,7 @@ public function iAddScopeThatAppliesOnTaxons(TaxonInterface ...$taxons): void public function iAddScopeThatAppliesOnProduct(ProductInterface $product): void { $this->formElement->addScope(InForProductScopeVariantChecker::TYPE); - $this->formElement->selectScopeOption([$product->getCode()]); + $this->formElement->selectScopeOption([$product->getName()]); } /** @@ -255,7 +255,7 @@ public function iAddScopeThatAppliesOnProduct(ProductInterface $product): void */ public function iAddVariantToItsScope(ProductVariantInterface $productVariant): void { - $this->formElement->selectScopeOption([$productVariant->getCode()]); + $this->formElement->selectScopeOption([$productVariant->getName()]); } /** @@ -263,7 +263,7 @@ public function iAddVariantToItsScope(ProductVariantInterface $productVariant): */ public function iRemoveVariantFromItsScope(ProductVariantInterface $productVariant): void { - $this->formElement->removeScopeOption([$productVariant->getCode()]); + $this->formElement->removeScopeOption([$productVariant->getName()]); } /** @@ -754,10 +754,10 @@ public function itShouldHaveVariantBasedScope( ): void { $this->updatePage->open(['id' => $catalogPromotion->getId()]); - $selectedVariants = $this->formElement->getLastScopeCodes(); + $selectedVariants = $this->formElement->getLastScopeNames(); foreach ($variants as $productVariant) { - Assert::inArray($productVariant->getCode(), $selectedVariants); + Assert::inArray($productVariant->getName(), $selectedVariants); } $this->sharedStorage->set('catalog_promotion', $catalogPromotion); @@ -772,10 +772,10 @@ public function itShouldHaveTaxonsBasedScope( ): void { $this->updatePage->open(['id' => $catalogPromotion->getId()]); - $selectedTaxons = $this->formElement->getLastScopeCodes(); + $selectedTaxons = $this->formElement->getLastScopeNames(); foreach ($taxons as $taxon) { - Assert::inArray($taxon->getCode(), $selectedTaxons); + Assert::inArray($taxon->getName(), $selectedTaxons); } } @@ -784,9 +784,9 @@ public function itShouldHaveTaxonsBasedScope( */ public function thisCatalogPromotionShouldBeAppliedOnTaxon(TaxonInterface $taxon): void { - $selectedTaxons = $this->formElement->getLastScopeCodes(); + $selectedTaxons = $this->formElement->getLastScopeNames(); - Assert::inArray($taxon->getCode(), $selectedTaxons); + Assert::inArray($taxon->getName(), $selectedTaxons); } /** @@ -806,8 +806,8 @@ public function theCatalogPromotionShouldApplyToAllVariantsOfProduct( */ public function thisCatalogPromotionShouldBeAppliedOnProduct(ProductInterface $product): void { - $selectedProducts = $this->formElement->getLastScopeCodes(); - Assert::inArray($product->getCode(), $selectedProducts); + $selectedProducts = $this->formElement->getLastScopeNames(); + Assert::inArray($product->getName(), $selectedProducts); } /** @@ -816,10 +816,10 @@ public function thisCatalogPromotionShouldBeAppliedOnProduct(ProductInterface $p */ public function itShouldApplyToVariants(ProductVariantInterface ...$variants): void { - $selectedVariants = $this->formElement->getLastScopeCodes(); + $selectedVariants = $this->formElement->getLastScopeNames(); foreach ($variants as $productVariant) { - Assert::inArray($productVariant->getCode(), $selectedVariants); + Assert::inArray($productVariant->getName(), $selectedVariants); } } @@ -828,10 +828,10 @@ public function itShouldApplyToVariants(ProductVariantInterface ...$variants): v */ public function itShouldNotApplyToVariants(ProductVariantInterface ...$variants): void { - $selectedVariants = $this->formElement->getLastScopeCodes(); + $selectedVariants = $this->formElement->getLastScopeNames(); foreach ($variants as $productVariant) { - Assert::false(in_array($productVariant->getCode(), $selectedVariants)); + Assert::false(in_array($productVariant->getName(), $selectedVariants, true)); } } @@ -1191,7 +1191,7 @@ private function createCatalogPromotion( $this->formElement->setExclusiveness($exclusive); $this->formElement->checkChannel($channel); $this->formElement->addScope(InForProductScopeVariantChecker::TYPE); - $this->formElement->selectScopeOption([$product->getCode()]); + $this->formElement->selectScopeOption([$product->getName()]); $this->formElement->addAction(PercentageDiscountPriceCalculator::TYPE); $this->formElement->fillActionOption('Amount', $discount); $this->createPage->create(); diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php index 865f867eabc..d6a43702f16 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php @@ -964,7 +964,14 @@ public function thisProductShouldHaveAnImageWithType(string $type): void */ public function itsImageShouldHaveVariantSelected(ProductVariantInterface $productVariant): void { - Assert::true($this->mediaFormElement->hasImageWithVariant($productVariant)); + Assert::true( + $this->mediaFormElement->hasImageWithVariant($productVariant), + sprintf( + 'Expected variant "%s" to be selected, but got "%s".', + $productVariant->getName(), + $this->mediaFormElement->getFirstImageSelectedVariantName() ?? 'none', + ), + ); } /** diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php index ddb8eb2e680..2d1fe603658 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php @@ -271,7 +271,7 @@ public function theProductShouldNoLongerHaveAMainTaxon(ProductInterface $product */ public function thisTaxonShouldBelongsTo(TaxonInterface $taxon): void { - Assert::same($this->formElement->getParent(), $taxon->getCode()); + Assert::same($this->formElement->getParent(), $taxon->getName()); } /** diff --git a/src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElement.php b/src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElement.php index df82f632920..f67de396c83 100644 --- a/src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElement.php @@ -98,14 +98,14 @@ public function addAction(string $type): void $this->waitForFormUpdate(); } - public function selectScopeOption(array $values): void + public function selectScopeOption(array $names): void { $lastScope = $this->getElement('last_scope'); - foreach ($values as $value) { - $this->autocompleteHelper->selectByValue( + foreach ($names as $name) { + $this->autocompleteHelper->selectByName( $this->getDriver(), $lastScope->find('css', 'select')->getXpath(), - $value, + $name, ); } @@ -128,12 +128,12 @@ public function fillActionOptionForChannel(string $channelCode, string $option, $lastAction->find('css', sprintf('[id$="_configuration_%s"]', $channelCode))->fillField($option, $value); } - public function getLastScopeCodes(): array + public function getLastScopeNames(): array { $lastScope = $this->getElement('last_scope'); return array_map( - fn (NodeElement $element) => $element->getValue(), + fn (NodeElement $element) => $element->getText(), $lastScope->findAll('css', 'option[selected="selected"]'), ); } @@ -176,14 +176,14 @@ public function getValidationMessages(): array return array_map(fn (NodeElement $element) => $element->getText(), $errors); } - public function removeScopeOption(array $values): void + public function removeScopeOption(array $names): void { $lastScope = $this->getElement('last_scope'); - foreach ($values as $value) { - $this->autocompleteHelper->removeByValue( + foreach ($names as $name) { + $this->autocompleteHelper->removeByName( $this->getDriver(), $lastScope->find('css', 'select')->getXpath(), - $value, + $name, ); } diff --git a/src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElementInterface.php b/src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElementInterface.php index c2a02f4040e..cd161c4c8d9 100644 --- a/src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElementInterface.php @@ -41,13 +41,13 @@ public function addScope(string $type): void; public function addAction(string $type): void; - public function selectScopeOption(array $values): void; + public function selectScopeOption(array $names): void; public function fillActionOption(string $option, string $value): void; public function fillActionOptionForChannel(string $channelCode, string $option, string $value): void; - public function getLastScopeCodes(): array; + public function getLastScopeNames(): array; public function getLastActionOption(string $option): string; @@ -61,7 +61,7 @@ public function checkIfActionConfigurationFormIsVisible(): bool; public function getValidationMessages(): array; - public function removeScopeOption(array $values): void; + public function removeScopeOption(array $names): void; public function removeLastAction(): void; diff --git a/src/Sylius/Behat/Element/Admin/Channel/ExcludeTaxonsFromShowingLowestPriceInputElement.php b/src/Sylius/Behat/Element/Admin/Channel/ExcludeTaxonsFromShowingLowestPriceInputElement.php index dae2c7a0f77..2e2bc07467a 100644 --- a/src/Sylius/Behat/Element/Admin/Channel/ExcludeTaxonsFromShowingLowestPriceInputElement.php +++ b/src/Sylius/Behat/Element/Admin/Channel/ExcludeTaxonsFromShowingLowestPriceInputElement.php @@ -33,10 +33,10 @@ public function excludeTaxon(TaxonInterface $taxon): void { $excludeTaxonElement = $this->getElement('taxons_excluded_from_showing_lowest_price'); - $this->autocompleteHelper->selectByValue( + $this->autocompleteHelper->selectByName( $this->getDriver(), $excludeTaxonElement->getXpath(), - $taxon->getCode(), + $taxon->getName(), ); $this->waitForFormUpdate(); } @@ -45,10 +45,10 @@ public function removeExcludedTaxon(TaxonInterface $taxon): void { $excludeTaxonElement = $this->getElement('taxons_excluded_from_showing_lowest_price'); - $this->autocompleteHelper->removeByValue( + $this->autocompleteHelper->removeByName( $this->getDriver(), $excludeTaxonElement->getXpath(), - $taxon->getCode(), + $taxon->getName(), ); $this->waitForFormUpdate(); } diff --git a/src/Sylius/Behat/Element/Admin/Product/AssociationsFormElement.php b/src/Sylius/Behat/Element/Admin/Product/AssociationsFormElement.php index c9f2c0aad64..545c5049480 100644 --- a/src/Sylius/Behat/Element/Admin/Product/AssociationsFormElement.php +++ b/src/Sylius/Behat/Element/Admin/Product/AssociationsFormElement.php @@ -50,10 +50,10 @@ public function removeAssociatedProduct(ProductInterface $product, ProductAssoci $this->changeTab(); $associationField = $this->getElement('associations', ['%association%' => $productAssociationType->getCode()]); - $this->autocompleteHelper->removeByValue( + $this->autocompleteHelper->removeByName( $this->getDriver(), $associationField->getXpath(), - $product->getCode(), + $product->getName(), ); } @@ -62,7 +62,12 @@ public function hasAssociatedProduct(ProductInterface $product, ProductAssociati $this->changeTab(); $associationField = $this->getElement('associations', ['%association%' => $productAssociationType->getCode()]); - return in_array($product->getCode(), $associationField->getValue(), true); + $selectedItems = $this->autocompleteHelper->getSelectedItems( + $this->getDriver(), + $associationField->getXpath(), + ); + + return in_array($product->getName(), $selectedItems, true); } protected function getDefinedElements(): array diff --git a/src/Sylius/Behat/Element/Admin/Product/MediaFormElement.php b/src/Sylius/Behat/Element/Admin/Product/MediaFormElement.php index 69405611206..88985b82e89 100644 --- a/src/Sylius/Behat/Element/Admin/Product/MediaFormElement.php +++ b/src/Sylius/Behat/Element/Admin/Product/MediaFormElement.php @@ -48,10 +48,10 @@ public function attachImage(string $path, ?string $type = null, ?ProductVariantI } if (null !== $productVariant) { - $this->autocompleteHelper->selectByValue( + $this->autocompleteHelper->selectByName( $this->getDriver(), $imageSubform->find('css', '[data-test-product-variant]')->getXpath(), - $productVariant->getCode(), + $productVariant->getName(), ); } @@ -106,12 +106,30 @@ public function hasImageWithType(string $type): bool } public function hasImageWithVariant(ProductVariantInterface $productVariant): bool + { + $selectedVariantName = $this->getFirstImageSelectedVariantName(); + + if (null === $selectedVariantName) { + return false; + } + + return str_contains($selectedVariantName, $productVariant->getName()); + } + + public function getFirstImageSelectedVariantName(): ?string { $this->changeTab(); - $images = $this->getElement('images'); + $imageSubform = $this->getFirstImageSubform(); + $variantField = $imageSubform->find('css', '[data-test-product-variant]'); + + $selectedOption = $variantField->find('css', 'option[selected]'); + + if (null === $selectedOption) { + return null; + } - return $images->has('css', sprintf('[data-test-product-variant*="%s"]', $productVariant->getCode())); + return $selectedOption->getText(); } public function countImages(): int @@ -189,10 +207,10 @@ public function selectVariantForFirstImage(ProductVariantInterface $productVaria $this->changeTab(); $imageSubform = $this->getFirstImageSubform(); - $this->autocompleteHelper->selectByValue( + $this->autocompleteHelper->selectByName( $this->getDriver(), $imageSubform->find('css', '[data-test-product-variant]')->getXpath(), - $productVariant->getCode(), + $productVariant->getName(), ); } diff --git a/src/Sylius/Behat/Element/Admin/Product/MediaFormElementInterface.php b/src/Sylius/Behat/Element/Admin/Product/MediaFormElementInterface.php index 843c32781df..a934518b83c 100644 --- a/src/Sylius/Behat/Element/Admin/Product/MediaFormElementInterface.php +++ b/src/Sylius/Behat/Element/Admin/Product/MediaFormElementInterface.php @@ -29,6 +29,8 @@ public function hasImageWithType(string $type): bool; public function hasImageWithVariant(ProductVariantInterface $productVariant): bool; + public function getFirstImageSelectedVariantName(): ?string; + public function countImages(): int; public function getImages(): array; diff --git a/src/Sylius/Behat/Element/Admin/Taxon/FormElement.php b/src/Sylius/Behat/Element/Admin/Taxon/FormElement.php index 6f35d783937..e5d0ef74789 100644 --- a/src/Sylius/Behat/Element/Admin/Taxon/FormElement.php +++ b/src/Sylius/Behat/Element/Admin/Taxon/FormElement.php @@ -66,7 +66,20 @@ public function describeItAs(string $description, string $localeCode): void public function getParent(): string { - return $this->getElement('parent')->getValue(); + $parentElement = $this->getElement('parent'); + + if (DriverHelper::isJavascript($this->getDriver())) { + $items = $this->autocompleteHelper->getSelectedItems( + $this->getDriver(), + $parentElement->getXpath(), + ); + + return count($items) > 0 ? reset($items) : ''; + } + + $selectedOption = $parentElement->find('css', 'option[selected]'); + + return $selectedOption?->getText() ?? ''; } public function chooseParent(TaxonInterface $taxon): void