From 9b743e909c5a0a7a58d03ea060951b70d97b7732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20H=C3=B6rmann?= Date: Thu, 13 Jul 2023 17:31:01 +0200 Subject: [PATCH] Enable the display of main Products in the category listing --- .../card/group/box-card-group-input.html.twig | 2 +- .../group/box-card-group-select.html.twig | 2 +- .../ProductListingConfigurationLoader.php | 27 ++++++++++--------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Resources/views/storefront/component/product/card/group/box-card-group-input.html.twig b/src/Resources/views/storefront/component/product/card/group/box-card-group-input.html.twig index 676da88..3c44ebb 100644 --- a/src/Resources/views/storefront/component/product/card/group/box-card-group-input.html.twig +++ b/src/Resources/views/storefront/component/product/card/group/box-card-group-input.html.twig @@ -44,7 +44,7 @@ value="{{ option.id }}" class="sas-product-configurator-option-input{% if isCombinableCls %} {{ isCombinableCls }}{% endif %}" title="{{ optionIdentifier }}" - data-url="{{ url('sas.frontend.variant.switch', {'productId': product.parentId}) }}" + data-url="{{ url('sas.frontend.variant.switch', {'productId': product.parentId ?? product.id}) }}" id="{{ optionIdentifier }}" {% if isActive %}checked="checked"{% endif %}> diff --git a/src/Resources/views/storefront/component/product/card/group/box-card-group-select.html.twig b/src/Resources/views/storefront/component/product/card/group/box-card-group-select.html.twig index c25e36d..d382c86 100644 --- a/src/Resources/views/storefront/component/product/card/group/box-card-group-select.html.twig +++ b/src/Resources/views/storefront/component/product/card/group/box-card-group-select.html.twig @@ -6,7 +6,7 @@ {% endblock %} {% block component_product_box_configurator_select %} - {% for option in group.options %} {% set selected = false %} diff --git a/src/Storefront/Page/ProductListingConfigurationLoader.php b/src/Storefront/Page/ProductListingConfigurationLoader.php index 513c56c..dc477b6 100644 --- a/src/Storefront/Page/ProductListingConfigurationLoader.php +++ b/src/Storefront/Page/ProductListingConfigurationLoader.php @@ -50,22 +50,22 @@ public function loadListing(ProductCollection $products, SalesChannelContext $co /** @var SalesChannelProductEntity $product */ foreach ($products as $product) { $productSettings = $this->loadSettings(clone $settings); + $parentId = $product->getParentId() ?? $product->getId(); - if ($product->getConfiguratorSettings() !== null || !$product->getParentId() || empty($productSettings[$product->getParentId()])) { - $product->addExtension('groups', new PropertyGroupCollection()); + if ($product->getConfiguratorSettings() !== null || empty($productSettings[$parentId])) { + $product->addExtension('groups', new PropertyGroupCollection()); continue; } - $productSetting = $productSettings[$product->getParentId()]; - + $productSetting = $productSettings[$parentId]; $groups = $this->sortSettings($productSetting, $product); - if (!array_key_exists($product->getParentId(), $allCombinations)) { + if (!array_key_exists($parentId, $allCombinations)) { continue; } - $combinations = $allCombinations[$product->getParentId()]; + $combinations = $allCombinations[$parentId]; $current = $this->buildCurrentOptions($product, $groups); @@ -330,15 +330,16 @@ private function buildCurrentOptions(SalesChannelProductEntity $product, Propert $keyMap = $groups->getOptionIdMap(); $current = []; - foreach ($product->getOptionIds() as $optionId) { - $groupId = $keyMap[$optionId] ?? null; - if ($groupId === null) { - continue; - } + if (null !== $optionIds = $product->getOptionIds()) { + foreach ($optionIds as $optionId) { + $groupId = $keyMap[$optionId] ?? null; + if ($groupId === null) { + continue; + } - $current[$groupId] = $optionId; + $current[$groupId] = $optionId; + } } - return $current; } }