Skip to content

Commit 1aa881b

Browse files
committed
feat: collect all possible propertyGroups of each product for comparison
1 parent 3273924 commit 1aa881b

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

src/Page/CompareProductPage.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
namespace Frosh\FroshProductCompare\Page;
44

55
use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingResult;
6+
use Shopware\Core\Content\Property\PropertyGroupCollection;
67
use Shopware\Storefront\Page\Page;
78

89
class CompareProductPage extends Page
910
{
1011
protected ProductListingResult $products;
12+
protected PropertyGroupCollection $properties;
1113

1214
public function getProducts(): ProductListingResult
1315
{
@@ -18,4 +20,14 @@ public function setProducts(ProductListingResult $products): void
1820
{
1921
$this->products = $products;
2022
}
23+
24+
public function getProperties(): PropertyGroupCollection
25+
{
26+
return $this->properties;
27+
}
28+
29+
public function setProperties(PropertyGroupCollection $properties): void
30+
{
31+
$this->properties = $properties;
32+
}
2133
}

src/Page/CompareProductPageLoader.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function load(array $productIds, Request $request, SalesChannelContext $s
9696

9797
$page = $this->genericLoader->load($request, $salesChannelContext);
9898

99+
/** @var CompareProductPage $page */
99100
$page = CompareProductPage::createFrom($page);
100101

101102
if (empty($productIds)) {
@@ -111,6 +112,22 @@ public function load(array $productIds, Request $request, SalesChannelContext $s
111112

112113
$page->setProducts($result);
113114

115+
$properties = new PropertyGroupCollection();
116+
117+
/** @var SalesChannelProductEntity $product */
118+
foreach ($result as $product) {
119+
foreach ($product->getSortedProperties() as $group) {
120+
// we don't need more data of the PropertyGroup so we just set id and translated instead of cloning
121+
$propertyGroup = new PropertyGroupEntity();
122+
$propertyGroup->setId($group->getId());
123+
$propertyGroup->setTranslated($group->getTranslated());
124+
125+
$properties->add($propertyGroup);
126+
}
127+
}
128+
129+
$page->setProperties($properties);
130+
114131
return $page;
115132
}
116133

src/Resources/views/storefront/component/compare/partial/properties.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% for product in products %}
33
{% set matchProperty = false %}
44
{% for group in product.sortedProperties %}
5-
{% if group.id == property.id %}
5+
{% if group.id == linePropertyId %}
66
{% set matchProperty = true %}
77
{% block frosh_product_compare_properties_cell %}
88
<td class="properties-value">

src/Resources/views/storefront/component/compare/section/specification.html.twig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
<th class="text-uppercase" colspan="{{ productsCount + 1 }}">{{ "froshProductCompare.section.specification.title"|trans|sw_sanitize }}</th>
55
</tr>
66

7-
{% set setProperties = products.first.sortedProperties %}
8-
9-
{% for property in setProperties %}
7+
{% for property in page.properties %}
108
<tr class="property">
119
<th class="capitalize">{{ property.translated.name|e }}</th>
1210
{% sw_include '@Storefront/storefront/component/compare/partial/properties.html.twig' with {
13-
property: property,
11+
linePropertyId: property.id,
1412
} %}
1513
</tr>
1614
{% endfor %}

0 commit comments

Comments
 (0)