bug #14538 [Product] Fix product variant choice labels (NoResponseMate)

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
-------

c3ea16ea7b [Product] Fix product variant choice labels
This commit is contained in:
Kevin Kaniaburka 2022-11-16 13:39:57 +01:00 committed by GitHub
commit f6ff6beb0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 4 deletions

View file

@ -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"

View file

@ -292,7 +292,7 @@ final class CartContext implements Context
$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;

View file

@ -37,7 +37,7 @@ final class ProductVariantChoiceType extends AbstractType
->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,

View file

@ -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 %}

View file

@ -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>