Skip to content

Commit d6c7364

Browse files
authored
Merge pull request #25 from tinect/fixcollection
A few improvements
2 parents 302da19 + 3589e17 commit d6c7364

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

src/Controller/CompareProductController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(
3434
public function comparePage(Request $request, SalesChannelContext $context): Response
3535
{
3636
$page = $this->genericPageLoader->load($request, $context);
37-
return $this->renderStorefront('@Storefront/storefront/page/compare.html.twig', compact('page'));
37+
return $this->renderStorefront('@FroshProductCompare/storefront/page/compare.html.twig', compact('page'));
3838
}
3939

4040
/**
@@ -46,7 +46,7 @@ public function comparePageContent(Request $request, SalesChannelContext $contex
4646

4747
$page = $this->compareProductPageLoader->load($productIds, $request, $context);
4848

49-
return $this->renderStorefront('@Storefront/storefront/component/compare/content.html.twig', ['page' => $page]);
49+
return $this->renderStorefront('@FroshProductCompare/storefront/component/compare/content.html.twig', ['page' => $page]);
5050
}
5151

5252
/**
@@ -58,6 +58,6 @@ public function offcanvas(Request $request, SalesChannelContext $context): Respo
5858

5959
$page = $this->compareProductPageLoader->loadPreview($productIds, $request, $context);
6060

61-
return $this->renderStorefront('@Storefront/storefront/component/compare/offcanvas-compare-list.html.twig', ['page' => $page]);
61+
return $this->renderStorefront('@FroshProductCompare/storefront/component/compare/offcanvas-compare-list.html.twig', ['page' => $page]);
6262
}
6363
}

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: 4 additions & 2 deletions
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">
@@ -21,7 +21,9 @@
2121
{% endfor %}
2222
{% if not matchProperty %}
2323
<td class="properties-value">
24-
<span>N/A</span>
24+
{% block frosh_product_compare_properties_item_notset %}
25+
<span>N/A</span>
26+
{% endblock %}
2527
</td>
2628
{% endif %}
2729
{% endfor %}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</tr>
2727
{% endif %}
2828

29-
{% if not hideRating %}
29+
{% if not hideRating and config('core.listing.showReview') %}
3030
<tr>
3131
<th>{{ "froshProductCompare.section.overview.rating"|trans|sw_sanitize }}</th>
3232
{% sw_include '@Storefront/storefront/component/compare/partial/rating-cells.html.twig' %}

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)