Skip to content

Commit 5383f1e

Browse files
feat: Support SW6.7 (#89)
Co-authored-by: Felix Schneider <[email protected]> Co-authored-by: Felix Schneider <[email protected]>
1 parent ddfd277 commit 5383f1e

File tree

15 files changed

+105
-104
lines changed

15 files changed

+105
-104
lines changed

.github/workflows/code-style.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ jobs:
1414
uses: shopware/github-actions/.github/workflows/phpstan.yml@main
1515
with:
1616
extensionName: FroshProductCompare
17-
shopwareVersion: v6.6.0.0-rc1
17+
shopwareVersion: v6.7.0.0
1818

composer.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "frosh/product-compare",
33
"description": "A Simple Product Compare plugin for Shopware 6",
4-
"version": "3.1.0",
4+
"version": "4.0.0",
55
"type": "shopware-platform-plugin",
66
"license": "MIT",
77
"authors": [
@@ -15,8 +15,8 @@
1515
}
1616
],
1717
"require": {
18-
"shopware/core": "~6.6",
19-
"shopware/storefront": "~6.6"
18+
"shopware/core": "~6.7.0",
19+
"shopware/storefront": "~6.7.0"
2020
},
2121
"extra": {
2222
"shopware-plugin-class": "Frosh\\FroshProductCompare\\FroshProductCompare",
@@ -44,9 +44,5 @@
4444
"Frosh\\FroshProductCompare\\": "src/"
4545
}
4646
},
47-
"conflict": {
48-
"shopware/storefront": "<6,>=7",
49-
"shopware/administration": "<6,>=7"
50-
},
5147
"prefer-stable": true
5248
}

src/Controller/CompareProductController.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,22 @@ class CompareProductController extends StorefrontController
1717
{
1818
public function __construct(
1919
private readonly CompareProductPageLoader $compareProductPageLoader,
20-
private readonly GenericPageLoaderInterface $genericPageLoader
20+
private readonly GenericPageLoaderInterface $genericPageLoader,
2121
) {}
2222

2323
#[Route(path: '/compare', name: 'frontend.compare.page', options: ['seo' => false], defaults: ['_httpCache' => false], methods: ['GET'])]
2424
public function comparePage(Request $request, SalesChannelContext $context): Response
2525
{
2626
$page = $this->genericPageLoader->load($request, $context);
2727

28-
return $this->renderStorefront('@FroshProductCompare/storefront/page/compare.html.twig', compact('page'));
28+
return $this->renderStorefront('@FroshProductCompare/storefront/page/compare.html.twig', ['page' => $page]);
2929
}
3030

3131
#[Route(path: '/compare/content', name: 'frontend.compare.content', options: ['seo' => false], defaults: ['_httpCache' => false, 'XmlHttpRequest' => true], methods: ['POST'])]
3232
public function comparePageContent(Request $request, SalesChannelContext $context): Response
3333
{
34-
$productIds = $request->get('productIds', []);
35-
36-
if (!\is_array($productIds)) {
37-
$productIds = [];
38-
}
34+
$productIds = $request->request->all('productIds');
35+
$productIds = array_values(array_filter($productIds, is_string(...)));
3936

4037
$page = $this->compareProductPageLoader->load($productIds, $request, $context);
4138

@@ -45,11 +42,8 @@ public function comparePageContent(Request $request, SalesChannelContext $contex
4542
#[Route(path: '/compare/offcanvas', name: 'frontend.compare.offcanvas', options: ['seo' => false], defaults: ['_httpCache' => false, 'XmlHttpRequest' => true], methods: ['POST'])]
4643
public function offcanvas(Request $request, SalesChannelContext $context): Response
4744
{
48-
$productIds = $request->get('productIds', []);
49-
50-
if (!\is_array($productIds)) {
51-
$productIds = [];
52-
}
45+
$productIds = $request->request->all('productIds');
46+
$productIds = array_filter($productIds, is_string(...));
5347

5448
$page = $this->compareProductPageLoader->loadPreview($productIds, $request, $context);
5549

src/DAL/Extension/ProductCrossSellingEntityExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ class ProductCrossSellingEntityExtension extends EntityExtension
1616
public function extendFields(FieldCollection $collection): void
1717
{
1818
$collection->add(
19-
(new OneToOneAssociationField('crossSellingComparable', 'id', 'product_cross_selling_id', CrossSellingComparableDefinition::class))->addFlags(new CascadeDelete())
19+
(new OneToOneAssociationField('crossSellingComparable', 'id', 'product_cross_selling_id', CrossSellingComparableDefinition::class))->addFlags(new CascadeDelete()),
2020
);
2121
}
2222

2323
public function getDefinitionClass(): string
2424
{
2525
return ProductCrossSellingDefinition::class;
2626
}
27+
28+
public function getEntityName(): string
29+
{
30+
return ProductCrossSellingDefinition::ENTITY_NAME;
31+
}
2732
}

src/DependencyInjection/services.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<argument type="service" id="Shopware\Storefront\Page\GenericPageLoader"/>
2121
<argument type="service" id="custom_field.repository" />
2222
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService" />
23-
<argument type="service" id="Shopware\Storefront\Page\Product\Review\ProductReviewLoader" />
23+
<argument type="service" id="Shopware\Core\Content\Product\SalesChannel\Review\ProductReviewLoader" />
2424
</service>
2525

2626
<service id="Frosh\FroshProductCompare\Controller\CompareProductController" public="true">
@@ -29,9 +29,6 @@
2929
<call method="setContainer">
3030
<argument type="service" id="service_container"/>
3131
</call>
32-
<call method="setTwig">
33-
<argument type="service" id="twig"/>
34-
</call>
3532
</service>
3633

3734
<!-- Subscriber -->
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frosh\FroshProductCompare\Migration;
6+
7+
use Doctrine\DBAL\Connection;
8+
use Shopware\Core\Framework\Migration\MigrationStep;
9+
use Shopware\Core\Framework\Uuid\Uuid;
10+
11+
class Migration1755069230MigrateSelectedPropertiesToId extends MigrationStep
12+
{
13+
public function getCreationTimestamp(): int
14+
{
15+
return 1755069230;
16+
}
17+
18+
public function update(Connection $connection): void
19+
{
20+
$systemConfigEntries = $connection->fetchAllKeyValue("SELECT LOWER(HEX(id)), configuration_value FROM system_config WHERE configuration_key = 'FroshProductCompare.config.selectedProperties'");
21+
22+
foreach ($systemConfigEntries as $systemConfigId => $rawConfigurationValue) {
23+
if(!is_string($rawConfigurationValue)) {
24+
continue;
25+
}
26+
27+
$migratedPropertyIds = [];
28+
$selectedPropertiesConfig = json_decode($rawConfigurationValue, true, 512, JSON_THROW_ON_ERROR);
29+
if (!is_array($selectedPropertiesConfig)) {
30+
continue;
31+
}
32+
$selectedPropertiesConfig = $selectedPropertiesConfig['_value'] ?? [];
33+
34+
if(!is_array($selectedPropertiesConfig)) {
35+
continue;
36+
}
37+
38+
foreach ($selectedPropertiesConfig as $propertyData) {
39+
$extractedPropertyId = !is_array($propertyData) ? $propertyData : ($propertyData['id'] ?? null);
40+
if (!empty($extractedPropertyId)) {
41+
$migratedPropertyIds[] = $extractedPropertyId;
42+
}
43+
}
44+
45+
$connection->executeStatement('UPDATE IGNORE system_config SET configuration_value = :configuration_value WHERE id = :id', [
46+
'configuration_value' => json_encode(['_value' => $migratedPropertyIds], JSON_THROW_ON_ERROR),
47+
'id' => Uuid::fromHexToBytes($systemConfigId),
48+
]);
49+
}
50+
}
51+
}

src/Page/CompareProductPageLoader.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Frosh\FroshProductCompare\Page;
66

7-
use Shopware\Core\Content\Product\Aggregate\ProductReview\ProductReviewCollection;
87
use Shopware\Core\Content\Product\Cart\ProductGatewayInterface;
98
use Shopware\Core\Content\Product\ProductCollection;
109
use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingResult;
10+
use Shopware\Core\Content\Product\SalesChannel\Review\AbstractProductReviewLoader;
1111
use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity;
1212
use Shopware\Core\Content\Property\Aggregate\PropertyGroupOption\PropertyGroupOptionCollection;
1313
use Shopware\Core\Content\Property\Aggregate\PropertyGroupOption\PropertyGroupOptionEntity;
@@ -23,7 +23,6 @@
2323
use Shopware\Core\System\SalesChannel\SalesChannelContext;
2424
use Shopware\Core\System\SystemConfig\SystemConfigService;
2525
use Shopware\Storefront\Page\GenericPageLoaderInterface;
26-
use Shopware\Storefront\Page\Product\Review\ProductReviewLoader;
2726
use Symfony\Component\HttpFoundation\Request;
2827

2928
class CompareProductPageLoader
@@ -35,7 +34,7 @@ public function __construct(
3534
private readonly GenericPageLoaderInterface $genericLoader,
3635
private readonly EntityRepository $customFieldRepository,
3736
private readonly SystemConfigService $systemConfigService,
38-
private readonly ProductReviewLoader $productReviewLoader
37+
private readonly AbstractProductReviewLoader $productReviewLoader,
3938
) {}
4039

4140
/**
@@ -112,11 +111,8 @@ public function loadProductCompareData(ProductListingResult $products, SalesChan
112111
$showSelectedProperties = $this->systemConfigService->getBool('FroshProductCompare.config.showSelectedProperties', $context->getSalesChannelId());
113112

114113
if ($showSelectedProperties) {
115-
$selectedProperties = $this->systemConfigService->get('FroshProductCompare.config.selectedProperties', $context->getSalesChannelId());
116-
117-
if (\is_array($selectedProperties)) {
118-
$selectedPropertyIds = \array_column($selectedProperties, 'id');
119-
}
114+
/** @var list<string> $selectedPropertyIds */
115+
$selectedPropertyIds = $this->systemConfigService->get('FroshProductCompare.config.selectedProperties', $context->getSalesChannelId());
120116
}
121117

122118
$reviewAllowed = $this->isReviewAllowed($context);
@@ -254,7 +250,7 @@ private function sortProperties(SalesChannelProductEntity $product, array $selec
254250
*/
255251
private function getGroupByProperty(array $sorted, PropertyGroupOptionEntity $option): ?PropertyGroupEntity
256252
{
257-
if (!empty($sorted[$option->getGroupId()]) && $sorted[$option->getGroupId()] instanceof PropertyGroupEntity) {
253+
if (!empty($sorted[$option->getGroupId()])) {
258254
return $sorted[$option->getGroupId()];
259255
}
260256

@@ -265,17 +261,9 @@ private function getGroupByProperty(array $sorted, PropertyGroupOptionEntity $op
265261
return PropertyGroupEntity::createFrom($option->getGroup());
266262
}
267263

268-
private function loadProductReviewCount(SalesChannelProductEntity $product, SalesChannelContext $context): int {
269-
$request = new Request();
270-
$request->request->set('parentId', $product->getParentId());
271-
$request->request->set('productId', $product->getId());
272-
$reviews = $this->productReviewLoader->load($request, $context);
273-
274-
if ($reviews->getEntities() instanceof ProductReviewCollection) {
275-
return $reviews->getTotalReviews();
276-
}
277-
278-
return 0;
264+
private function loadProductReviewCount(SalesChannelProductEntity $product, SalesChannelContext $context): int
265+
{
266+
return $this->productReviewLoader->load(new Request(), $context, $product->getId(), $product->getParentId())->count();
279267
}
280268

281269
private function loadCustomFields(SalesChannelContext $context, ProductCollection $products): CustomFieldCollection
@@ -305,7 +293,7 @@ private function loadCustomFields(SalesChannelContext $context, ProductCollectio
305293
}
306294

307295
/**
308-
* @return array<string>
296+
* @return list<string>
309297
*/
310298
private function getAvailableCustomFieldNames(ProductCollection $products): array
311299
{

src/Resources/app/administration/src/extension/sw-product/component/sw-product-cross-selling-form/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@ Component.override('sw-product-cross-selling-form', {
3636
if (Utils.get(this.crossSelling, 'extensions.crossSellingComparable.isComparable', false)) {
3737
this.crossSelling.limit = MAXIMUM_COMPARE_PRODUCT_ITEMS;
3838
}
39+
},
40+
computed: {
41+
allowEditLimit() {
42+
return this.crossSelling.extensions.crossSellingComparable.isComparable || !this.allowEdit
43+
}
3944
}
4045
});
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{% block sw_prduct_cross_selling_form_active_field %}
22
{% parent %}
3-
<sw-switch-field
4-
v-model:value="crossSelling.extensions.crossSellingComparable.isComparable"
3+
<mt-switch
4+
v-model="crossSelling.extensions.crossSellingComparable.isComparable"
55
class="sw-product-detail-cross-selling__comparable-switch"
6-
:label="$tc('frosh-product-compare.crossSelling.compareLayout')">
7-
</sw-switch-field>
6+
:label="$tc('frosh-product-compare.crossSelling.compareLayout')"
7+
bordered>
8+
</mt-switch>
89
{% endblock %}
910

1011
{% block sw_prduct_cross_selling_form_limit_field %}
11-
<sw-number-field
12+
<mt-number-field
1213
numberType="int"
13-
:disabled="crossSelling.extensions.crossSellingComparable.isComparable"
14+
:disabled="allowEditLimit"
1415
:label="$tc('sw-product.crossselling.inputCrossSellingLimit')"
15-
v-model:value="crossSelling.limit">
16-
</sw-number-field>
16+
v-model="crossSelling.limit">
17+
</mt-number-field>
1718
{% endblock %}

src/Resources/app/administration/src/extension/sw-settings/sw-property-multi-select/index.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)