Skip to content

Commit

Permalink
feat: add shopware 6.6 compatibility (#67)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: tinect <[email protected]>
  • Loading branch information
shyim and tinect authored Feb 15, 2024
1 parent 5cee4c6 commit e649591
Show file tree
Hide file tree
Showing 26 changed files with 149 additions and 60 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Code Style
on:
workflow_dispatch:
pull_request:
push:
branches:
- main

jobs:
cs:
if: github.event_name != 'schedule'
uses: shopware/github-actions/.github/workflows/cs-fixer.yml@main
phpstan:
uses: shopware/github-actions/.github/workflows/phpstan.yml@main
with:
extensionName: FroshProductCompare
shopwareVersion: v6.6.0.0-rc1

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ phpstan.neon
src/Resources/public/administration/frosh-product-compare.*.hot-update.js
frosh-product-compare.js
frosh-product-compare.css
node_modules
8 changes: 7 additions & 1 deletion .shopware-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ store:
priority: 4
activate:
de: true
en: true
en: true

build:
zip:
assets:
npm_strict: true

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "frosh/product-compare",
"description": "A Simple Product Compare plugin for Shopware 6",
"version": "2.0.0",
"version": "3.0.0",
"type": "shopware-platform-plugin",
"license": "MIT",
"authors": [
Expand All @@ -15,8 +15,8 @@
}
],
"require": {
"shopware/core": "^6.5",
"shopware/storefront": "^6.5"
"shopware/core": "~6.6",
"shopware/storefront": "~6.6"
},
"extra": {
"shopware-plugin-class": "Frosh\\FroshProductCompare\\FroshProductCompare",
Expand Down
9 changes: 5 additions & 4 deletions src/Controller/CompareProductController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\Controller;

Expand All @@ -8,16 +10,15 @@
use Shopware\Storefront\Page\GenericPageLoaderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Attribute\Route;

#[Route(defaults: ['_routeScope' => ['storefront']])]
class CompareProductController extends StorefrontController
{
public function __construct(
private readonly CompareProductPageLoader $compareProductPageLoader,
private readonly GenericPageLoaderInterface $genericPageLoader
) {
}
) {}

#[Route(path: '/compare', name: 'frontend.compare.page', options: ['seo' => false], defaults: ['_httpCache' => false], methods: ['GET'])]
public function comparePage(Request $request, SalesChannelContext $context): Response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\CrossSellingComparable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\CrossSellingComparable;

Expand Down
4 changes: 3 additions & 1 deletion src/CrossSellingComparable/CrossSellingComparableEntity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\CrossSellingComparable;

Expand Down
4 changes: 3 additions & 1 deletion src/DAL/Extension/ProductCrossSellingEntityExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\DAL\Extension;

Expand Down
4 changes: 3 additions & 1 deletion src/FroshProductCompare.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare;

Expand Down
8 changes: 4 additions & 4 deletions src/Migration/Migration1594488930CrossSellingComparable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\Migration;

Expand Down Expand Up @@ -28,7 +30,5 @@ public function update(Connection $connection): void
');
}

public function updateDestructive(Connection $connection): void
{
}
public function updateDestructive(Connection $connection): void {}
}
4 changes: 3 additions & 1 deletion src/Page/CompareProductPage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\Page;

Expand Down
7 changes: 4 additions & 3 deletions src/Page/CompareProductPageLoader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\Page;

Expand Down Expand Up @@ -33,8 +35,7 @@ public function __construct(
private readonly EntityRepository $customFieldRepository,
private readonly SystemConfigService $systemConfigService,
private readonly ProductReviewLoader $productReviewLoader
) {
}
) {}

/**
* @param array<string> $productIds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{% block sw_prduct_cross_selling_form_active_field %}
{% parent %}
<sw-field
v-model="crossSelling.extensions.crossSellingComparable.isComparable"
type="switch"
<sw-switch-field
v-model:value="crossSelling.extensions.crossSellingComparable.isComparable"
class="sw-product-detail-cross-selling__comparable-switch"
:label="$tc('frosh-product-compare.crossSelling.compareLayout')">
</sw-field>
</sw-switch-field>
{% endblock %}

{% block sw_prduct_cross_selling_form_limit_field %}
<sw-number-field
numberType="int"
:disabled="crossSelling.extensions.crossSellingComparable.isComparable"
:label="$tc('sw-product.crossselling.inputCrossSellingLimit')"
v-model="crossSelling.limit">
v-model:value="crossSelling.limit">
</sw-number-field>
{% endblock %}
40 changes: 40 additions & 0 deletions src/Resources/app/storefront/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Resources/app/storefront/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"@friendsofshopware/storefront-types": "^0.1.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import Storage from 'src/helper/storage/storage.helper';

class CompareLocalStorageHelper {
static key = 'compare-widget-added-products';

static maximumCompareProducts = 4;

static getAddedProductsList() {
let products = Storage.getItem(this.key);
let products;

try {
products = JSON.parse(products) || [];
products = JSON.parse(window.localStorage.getItem(this.key)) || [];
} catch {
this.clear();
products = {};
Expand Down Expand Up @@ -60,13 +58,13 @@ class CompareLocalStorageHelper {
}

static persist(products) {
Storage.setItem(this.key, JSON.stringify(products));
window.localStorage.setItem(this.key, JSON.stringify(products));

document.$emitter.publish('changedProductCompare', { products });
}

static clear() {
Storage.setItem(this.key, null);
window.localStorage.removeItem(this.key);
}

static _checkCompareProductStorage(products) {
Expand Down
9 changes: 0 additions & 9 deletions src/Resources/app/storefront/src/main.js

This file was deleted.

7 changes: 7 additions & 0 deletions src/Resources/app/storefront/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import CompareWidgetPlugin from './plugin/compare-widget.plugin';
import AddToCompareButtonPlugin from './plugin/add-to-compare-button.plugin';
import CompareFloatPlugin from './plugin/compare-float.plugin';

window.PluginManager.register('AddToCompareButton', AddToCompareButtonPlugin, '[data-add-to-compare-button]');
window.PluginManager.register('CompareWidget', CompareWidgetPlugin, '[data-compare-widget]');
window.PluginManager.register('CompareFloat', CompareFloatPlugin, '[data-compare-float]');
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Plugin from 'src/plugin-system/plugin.class';
import CompareLocalStorageHelper from '../helper/compare-local-storage.helper';

export default class AddToCompareButtonPlugin extends Plugin {
export default class AddToCompareButtonPlugin extends window.PluginBaseClass {
static options = {
isAddedToCompareClass: 'is-added-to-compare'
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Plugin from 'src/plugin-system/plugin.class';
import DeviceDetection from 'src/helper/device-detection.helper';
import AjaxOffcanvas from 'src/plugin/offcanvas/ajax-offcanvas.plugin';
import PseudoModalUtil from 'src/utility/modal-extension/pseudo-modal.util';
import CompareLocalStorageHelper from '../helper/compare-local-storage.helper';

export default class CompareFloatPlugin extends Plugin {
export default class CompareFloatPlugin extends window.PluginBaseClass {
static options = {
buttonSelector: '.js-compare-float-button'
};
Expand Down Expand Up @@ -36,7 +34,7 @@ export default class CompareFloatPlugin extends Plugin {
* @private
*/
_registerEvents() {
const submitEvent = (DeviceDetection.isTouchDevice()) ? 'touchstart' : 'click';
const submitEvent = ('ontouchstart' in document.documentElement) ? 'touchstart' : 'click';

if (this._button) {
this._button.addEventListener(submitEvent, () => {
Expand Down
19 changes: 11 additions & 8 deletions src/Resources/app/storefront/src/plugin/compare-widget.plugin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import Plugin from 'src/plugin-system/plugin.class';
import HttpClient from 'src/service/http-client.service';
import ElementLoadingIndicatorUtil from 'src/utility/loading-indicator/element-loading-indicator.util';
import CompareLocalStorageHelper from '../helper/compare-local-storage.helper';

export default class CompareWidgetPlugin extends Plugin {
export default class CompareWidgetPlugin extends window.PluginBaseClass {
init() {
this._client = new HttpClient();
this._clearBtn = this.el.querySelector('.btn-clear');
this._printBtn = this.el.querySelector('.btn-printer');
this.registerShowDifferencesBtnEvent();
Expand Down Expand Up @@ -54,13 +51,19 @@ export default class CompareWidgetPlugin extends Plugin {

ElementLoadingIndicatorUtil.create(this.el);

this._client.post(window.router['frontend.compare.content'], JSON.stringify(data), (response) => {
fetch(window.router['frontend.compare.content'], {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data),
}).then(r => r.text()).then((text) => {
ElementLoadingIndicatorUtil.remove(this.el);

this.renderCompareProducts(response);
this.renderCompareProducts(text);

this.$emitter.publish('insertStoredContent', { response });
});
this.$emitter.publish('insertStoredContent', { response: text });
})
}

renderCompareProducts(html) {
Expand Down
7 changes: 7 additions & 0 deletions src/Resources/app/storefront/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"types": ["@friendsofshopware/storefront-types"],
"target": "ES2020",
"module": "CommonJS"
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/routes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<import resource="../../Controller" type="annotation" />
<import resource="../../Controller" type="attribute" />
</routes>
7 changes: 4 additions & 3 deletions src/Subscriber/FroshCrossSellingProductListingSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\Subscriber;

Expand All @@ -25,8 +27,7 @@ class FroshCrossSellingProductListingSubscriber implements EventSubscriberInterf
public function __construct(
private readonly CompareProductPageLoader $compareProductPageLoader,
private readonly ProductGatewayInterface $productGateway
) {
}
) {}

public static function getSubscribedEvents(): array
{
Expand Down
4 changes: 3 additions & 1 deletion src/Subscriber/FroshProductGatewayCriteriaSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Frosh\FroshProductCompare\Subscriber;

Expand Down

0 comments on commit e649591

Please sign in to comment.