Skip to content

Commit

Permalink
bug #14538 [Product] Fix product variant choice labels (NoResponseMate)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.11                  |
| Bug fix?        | yes                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no |
| Related tickets | fixes #14276                      |
| License         | MIT                                                          |

Commits
-------

c3ea16e [Product] Fix product variant choice labels
  • Loading branch information
coldic3 committed Nov 16, 2022
2 parents 7f45d53 + c3ea16e commit f6ff6be
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
Expand Up @@ -19,3 +19,15 @@ Feature: Adding a product with selected variant to the cart
And this item should have name "T-shirt banana"
And this item should have variant "Small logo"
And this item should have code "SMALL_LOGO"

@ui @no-api
Scenario: Adding a product with multiple nameless variants to the cart
Given the store has a "T-shirt banana" configurable product
And this product has a nameless variant with code "banana-s"
And this product also has a nameless variant with code "banana-m"
When I add "T-shirt banana (banana-m)" variant of this product to the cart
Then I should be on my cart summary page
And I should be notified that the product has been successfully added
And there should be one item in my cart
And this item should have name "T-shirt banana"
And this item should have code "banana-m"
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Ui/Shop/CartContext.php
Expand Up @@ -292,7 +292,7 @@ public function iAddProductToTheCartSelectingVariant($variantName, ProductInterf

$this->sharedStorage->set('product', $product);
foreach ($product->getVariants() as $variant) {
if ($variant->getName() === $variantName) {
if ($variantName === ($variant->getName() ?? $variant->getDescriptor())) {
$this->sharedStorage->set('variant', $variant);

break;
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function configureOptions(OptionsResolver $resolver): void
->setDefaults([
'choices' => fn (Options $options): iterable => $options['product']->getVariants(),
'choice_value' => 'code',
'choice_label' => fn (ProductVariantInterface $variant): string => $variant->getName(),
'choice_label' => fn (ProductVariantInterface $variant): string => $variant->getName() ?? $variant->getDescriptor(),
'choice_translation_domain' => false,
'multiple' => false,
'expanded' => true,
Expand Down
Expand Up @@ -13,7 +13,7 @@
{% set channelPricing = variant.getChannelPricingForChannel(sylius.channel) %}
<tr {{ sylius_test_html_attribute('product-variants-row') }}>
<td>
{{ variant.name }}
{{ variant.name|default(variant.descriptor) }}
{% if product.hasOptions() %}
<div class="ui horizontal divided list">
{% for optionValue in variant.optionValues %}
Expand Down
Expand Up @@ -9,7 +9,7 @@
<div class="content">
<a href="{{ path('sylius_shop_product_show', {'slug': product.slug}) }}">
<div class="sylius-product-name" {{ sylius_test_html_attribute('product-name', item.productName) }}>{{ item.productName }}</div>
<span class="sub header sylius-product-variant-code" {{ sylius_test_html_attribute('product-variant-code') }}>
<span class="sub header sylius-product-variant-code" {{ sylius_test_html_attribute('product-variant-code', variant.code) }}>
{{ variant.code }}
</span>
</a>
Expand Down

0 comments on commit f6ff6be

Please sign in to comment.