From 71564f42ffcdd135e629620acd6181da247d6747 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Tue, 21 May 2024 15:40:36 +0200 Subject: [PATCH 1/8] NTR: PISHPS-285: test mollie storfront plugins --- .../app/storefront/build/webpack.config.js | 13 -- .../core/creditcard-mandate.plugin.js | 3 +- .../plugins/apple-pay-direct.plugin.js | 3 +- .../apple-pay-payment-method.plugin.js | 3 +- .../plugins/bancomat-plugin.js | 4 +- .../creditcard-mandate-manage.plugin.js | 3 +- .../plugins/ideal-issuer.plugin.js | 3 +- .../plugins/pos-terminal.plugin.js | 3 +- .../shopware-storefront-sdk/README.md | 17 --- .../helper/DeviceDetection.d.ts | 1 - .../helper/DeviceDetection.js | 7 - .../helper/String.d.ts | 4 - .../shopware-storefront-sdk/helper/String.js | 24 ---- .../shopware-storefront-sdk/package.json | 25 ---- .../plugin-system/NativeEventEmitter.d.ts | 22 ---- .../plugin-system/NativeEventEmitter.js | 86 ------------ .../plugin-system/plugin.class.d.ts | 16 --- .../plugin-system/plugin.class.js | 123 ------------------ .../app/storefront/webpack.config.js | 9 -- src/Resources/views/mollie/head.html.twig | 2 +- src/Subscriber/StorefrontBuildSubscriber.php | 6 - 21 files changed, 8 insertions(+), 369 deletions(-) delete mode 100644 src/Resources/app/storefront/build/webpack.config.js delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/README.md delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.d.ts delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.js delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.d.ts delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.js delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/package.json delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.d.ts delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.js delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.d.ts delete mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.js diff --git a/src/Resources/app/storefront/build/webpack.config.js b/src/Resources/app/storefront/build/webpack.config.js deleted file mode 100644 index 950a0d439..000000000 --- a/src/Resources/app/storefront/build/webpack.config.js +++ /dev/null @@ -1,13 +0,0 @@ -const {resolve, join} = require("path"); - -module.exports = () => { - return { - resolve: { - alias: { - '@shopware-storefront-sdk': resolve( - join(__dirname, '..', 'src_vendor', 'shopware-storefront-sdk'), - ), - }, - }, - }; -}; \ No newline at end of file diff --git a/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js b/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js index 211fe6f47..dfcf13966 100644 --- a/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js @@ -1,10 +1,9 @@ -import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class'; import HttpClient from '../services/HttpClient'; /** * This plugin manage the credit card mandate of the customer */ -export default class MollieCreditCardMandate extends Plugin { +export default class MollieCreditCardMandate extends window.PluginBaseClass { static options = { newCardMandateOption: null, mollieCreditCardFormClass: '.mollie-components-credit-card', diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js index b4853b5cf..0b2d667e4 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js @@ -1,7 +1,6 @@ -import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class'; import HttpClient from '../services/HttpClient'; -export default class MollieApplePayDirect extends Plugin { +export default class MollieApplePayDirect extends window.PluginBaseClass { /** * diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js index 3d819c3e4..a79b06208 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js @@ -1,7 +1,6 @@ -import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class'; import HttpClient from '../services/HttpClient'; -export default class MollieApplePayPaymentMethod extends Plugin { +export default class MollieApplePayPaymentMethod extends window.PluginBaseClass { /** * diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js index b08b04aed..29cef07fe 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js @@ -1,6 +1,4 @@ -import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class'; - -export default class MollieBancomatPlugin extends Plugin { +export default class MollieBancomatPlugin extends window.PluginBaseClass { init() { diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js index 6413a5df4..6b8098b47 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js @@ -1,10 +1,9 @@ -import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class'; import HttpClient from '../services/HttpClient'; /** * This plugin manage the credit card mandate of customer */ -export default class MollieCreditCardMandateManage extends Plugin { +export default class MollieCreditCardMandateManage extends window.PluginBaseClass { static options = { shopUrl: null, customerId: null, diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js index fc4085199..eb0bf898f 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js @@ -1,8 +1,7 @@ -import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class'; import HttpClient from '../services/HttpClient' -export default class MollieIDealIssuer extends Plugin { +export default class MollieIDealIssuer extends window.PluginBaseClass { _shopUrl = ''; _customerId = ''; diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js index 7aeadada5..a7f4fa2d1 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js @@ -1,8 +1,7 @@ -import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class'; import HttpClient from '../services/HttpClient' -export default class MolliePosTerminalPlugin extends Plugin { +export default class MolliePosTerminalPlugin extends window.PluginBaseClass { _shopUrl = ''; _customerId = ''; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/README.md b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/README.md deleted file mode 100644 index 22ae1747b..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Shopware Storefront SDK - -## Description - -The Shopware Storefront SDK is a set of classes and methods to easily access the Shopware Storefront. -So in your plugins, you can add this package as dependency and use the classes from this package instead of default Shopware files. - -## Features - -- Build Shopware Version independent plugin -- Ability to build your plugin javascript without having the Shopware 6 code-base - -## Installation - -```bash -npm install shopware-storefront-sdk -``` diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.d.ts b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.d.ts deleted file mode 100644 index 5e35d30a1..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function isTouchDevice(): boolean; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.js b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.js deleted file mode 100644 index 5e808288e..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.isTouchDevice = void 0; -function isTouchDevice() { - return ('ontouchstart' in document.documentElement); -} -exports.isTouchDevice = isTouchDevice; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.d.ts b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.d.ts deleted file mode 100644 index 8819ee9df..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export declare function ucFirst(value: string): string; -export declare function lcFirst(value: string): string; -export declare function toLowerCamelCase(value: string, separator: string): string; -export declare function toUpperCamelCase(value: string, separator: string): string; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.js b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.js deleted file mode 100644 index 5103b7436..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.toUpperCamelCase = exports.toLowerCamelCase = exports.lcFirst = exports.ucFirst = void 0; -function ucFirst(value) { - return value.charAt(0).toUpperCase() + value.slice(1); -} -exports.ucFirst = ucFirst; -function lcFirst(value) { - return value.charAt(0).toLowerCase() + value.slice(1); -} -exports.lcFirst = lcFirst; -function toLowerCamelCase(value, separator) { - var upperCamelCase = toUpperCamelCase(value, separator); - return lcFirst(upperCamelCase); -} -exports.toLowerCamelCase = toLowerCamelCase; -function toUpperCamelCase(value, separator) { - if (!separator) { - return ucFirst(value.toLowerCase()); - } - var stringParts = value.split(separator); - return stringParts.map(function (string) { return ucFirst(string.toLowerCase()); }).join(''); -} -exports.toUpperCamelCase = toUpperCamelCase; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/package.json b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/package.json deleted file mode 100644 index badc32db9..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "shopware-storefront-sdk", - "version": "0.0.2", - "description": "Provides Shopware Storefront Utilities as Typescript", - "main": "sdk.js", - "types": "sdk.d.ts", - "scripts": { - "publish-to-npm": "rm -rf dist; tsc --build && cp package.json dist && cat ./package.json | grep -v '\\\"private\\\":' > dist/package.json; cp README.md dist" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/FriendsOfShopware/shopware-storefront-sdk.git" - }, - "bugs": { - "url": "https://github.com/FriendsOfShopware/shopware-storefront-sdk/issues" - }, - "author": "FriendsOfShopware", - "license": "MIT", - "dependencies": { - "deepmerge": "^4.2.2" - }, - "devDependencies": { - "typescript": "^4.7.4" - } -} diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.d.ts b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.d.ts deleted file mode 100644 index 083a001e9..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -interface NativeEventEmitterPublish { - detail?: object; - cancelable?: boolean; -} -interface NativeEventEmitterSubscribeOpts { - once?: boolean; - scope?: Function; -} -export default class NativeEventEmitter { - private _listeners; - private _el; - constructor(el: HTMLElement); - publish(eventName: string, detail?: NativeEventEmitterPublish, cancelable?: boolean): CustomEvent; - subscribe(eventName: string, callback: Function, opts?: NativeEventEmitterSubscribeOpts): boolean; - unsubscribe(eventName: String): boolean; - reset(): boolean; - get el(): HTMLElement; - set el(value: HTMLElement); - get listeners(): any[]; - set listeners(value: any[]); -} -export {}; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.js b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.js deleted file mode 100644 index 9aa92d954..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.js +++ /dev/null @@ -1,86 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var NativeEventEmitter = /** @class */ (function () { - function NativeEventEmitter(el) { - this._el = el; - // @ts-ignore - el.$emitter = this; - this._listeners = []; - } - NativeEventEmitter.prototype.publish = function (eventName, detail, cancelable) { - if (detail === void 0) { detail = {}; } - if (cancelable === void 0) { cancelable = false; } - var event = new CustomEvent(eventName, { - detail: detail, - cancelable: cancelable, - }); - this.el.dispatchEvent(event); - return event; - }; - NativeEventEmitter.prototype.subscribe = function (eventName, callback, opts) { - if (opts === void 0) { opts = {}; } - var emitter = this; - var splitEventName = eventName.split('.'); - var cb = opts.scope ? callback.bind(opts.scope) : callback; - // Support for listeners which are fired once - if (opts.once && opts.once === true) { - var onceCallback_1 = cb; - cb = function onceListener(event) { - emitter.unsubscribe(eventName); - onceCallback_1(event); - }; - } - this.el.addEventListener(splitEventName[0], cb); - this.listeners.push({ - splitEventName: splitEventName, - opts: opts, - cb: cb, - }); - return true; - }; - NativeEventEmitter.prototype.unsubscribe = function (eventName) { - var _this = this; - var splitEventName = eventName.split('.'); - this.listeners = this.listeners.reduce(function (accumulator, listener) { - var foundEvent = listener.splitEventName.sort().toString() === splitEventName.sort().toString(); - if (foundEvent) { - _this.el.removeEventListener(listener.splitEventName[0], listener.cb); - return accumulator; - } - accumulator.push(listener); - return accumulator; - }, []); - return true; - }; - NativeEventEmitter.prototype.reset = function () { - var _this = this; - this.listeners.forEach(function (listener) { - _this.el.removeEventListener(listener.splitEventName[0], listener.cb); - }); - // Reset registry - this.listeners = []; - return true; - }; - Object.defineProperty(NativeEventEmitter.prototype, "el", { - get: function () { - return this._el; - }, - set: function (value) { - this._el = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NativeEventEmitter.prototype, "listeners", { - get: function () { - return this._listeners; - }, - set: function (value) { - this._listeners = value; - }, - enumerable: false, - configurable: true - }); - return NativeEventEmitter; -}()); -exports.default = NativeEventEmitter; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.d.ts b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.d.ts deleted file mode 100644 index 2f3f09c02..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -export default abstract class PluginClass { - private readonly el; - private $emitter; - private readonly _pluginName; - private readonly options; - private _initialized; - constructor(el: HTMLElement, options?: any, pluginName?: boolean | string); - private _init; - _update(): void; - abstract init(): void; - update(): void; - _registerInstance(): void; - private _getPluginName; - private _mergeOptions; - private parseJsonOrFail; -} diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.js b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.js deleted file mode 100644 index d3728aac0..000000000 --- a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.js +++ /dev/null @@ -1,123 +0,0 @@ -"use strict"; - -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : {"default": mod}; -}; - -Object.defineProperty(exports, "__esModule", {value: true}); - -var NativeEventEmitter_1 = __importDefault(require("./NativeEventEmitter")); - -var deepmerge_1 = __importDefault(require("deepmerge")); - -var PluginClass = /** @class */ (function () { - - function PluginClass(el, options, pluginName) { - - if (options === void 0) { - options = {}; - } - if (pluginName === void 0) { - pluginName = false; - } - this.el = el; - this.$emitter = new NativeEventEmitter_1.default(this.el); - this._pluginName = this._getPluginName(pluginName); - this.options = this._mergeOptions(options); - this._initialized = false; - this._registerInstance(); - this._init(); - } - - PluginClass.prototype._init = function () { - if (this._initialized) - return; - this.init(); - this._initialized = true; - }; - - PluginClass.prototype._update = function () { - if (!this._initialized) - return; - this.update(); - }; - - PluginClass.prototype.update = function () { - }; - - PluginClass.prototype._registerInstance = function () { - var elementPluginInstances = window.PluginManager.getPluginInstancesFromElement(this.el); - elementPluginInstances.set(this._pluginName, this); - var plugin = window.PluginManager.getPlugin(this._pluginName, false); - plugin.get('instances').push(this); - }; - - PluginClass.prototype._getPluginName = function (pluginName) { - if (pluginName === false) { - // @ts-ignore - return this.constructor.name; - } - return pluginName; - }; - - PluginClass.prototype._mergeOptions = function (options) { - var dashedPluginName = this._pluginName.replace(/([A-Z])/g, '-$1').replace(/^-/, '').toLowerCase(); - var dataAttributeConfig = this.parseJsonOrFail(dashedPluginName); - - let dataAttributeOptions = ''; - - if (typeof this.el.getAttribute === 'function') { - dataAttributeOptions = this.el.getAttribute("data-".concat(dashedPluginName, "-options")) || ''; - } - - // static plugin options - // previously merged options - // explicit options when creating a plugin instance with 'new' - var merge = [ - // @ts-ignore - this.constructor.options, - this.options, - options, - ]; - - // options which are set via data-plugin-name-config="config name" - if (dataAttributeConfig) { - merge.push(window.PluginConfigManager.get(this._pluginName, dataAttributeConfig)); - } - - // options which are set via data-plugin-name-options="{json..}" - try { - if (dataAttributeOptions) - merge.push(JSON.parse(dataAttributeOptions)); - } catch (e) { - throw new Error("The data attribute \"data-".concat(dashedPluginName, "-options\" could not be parsed to json: ").concat(e.message || '')); - } - - return deepmerge_1.default.all(merge.filter(function (config) { - return config instanceof Object && !(config instanceof Array); - }) - .map(function (config) { - return config || {}; - })); - }; - - PluginClass.prototype.parseJsonOrFail = function (dashedPluginName) { - - if (typeof this.el.getAttribute !== 'function') { - return ''; - } - - const value = this.el.getAttribute("data-".concat(dashedPluginName, "-config")) || ''; - - try { - return JSON.parse(value); - } catch (e) { - return value; - } - }; - - return PluginClass; - -}()); - -exports.default = PluginClass; diff --git a/src/Resources/app/storefront/webpack.config.js b/src/Resources/app/storefront/webpack.config.js index e2f5a76a7..bbaaa627d 100644 --- a/src/Resources/app/storefront/webpack.config.js +++ b/src/Resources/app/storefront/webpack.config.js @@ -1,5 +1,4 @@ const path = require('path') -const {resolve, join} = require("path"); module.exports = { mode: 'production', @@ -8,12 +7,4 @@ module.exports = { path: path.resolve(__dirname, '..', '..', 'public'), filename: 'mollie-payments.js', }, - resolve: { - extensions: ['.js'], - alias: { - '@shopware-storefront-sdk': resolve( - join(__dirname, 'src_vendor', 'shopware-storefront-sdk'), - ), - }, - }, } diff --git a/src/Resources/views/mollie/head.html.twig b/src/Resources/views/mollie/head.html.twig index 28d382a6c..72fe6c2c9 100644 --- a/src/Resources/views/mollie/head.html.twig +++ b/src/Resources/views/mollie/head.html.twig @@ -31,7 +31,7 @@ window.mollie_javascript_use_shopware = '{{ mollie_javascript_use_shopware }}' - {% if mollie_javascript_already_exists == false and mollie_javascript_use_shopware != '1' and includeJsInHeader == true %} + {% if mollie_javascript_use_shopware != '1' and includeJsInHeader == true %} {% endif %} diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index f29d977e1..b7eb4e34f 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -59,11 +59,5 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void $useJsValue = (int)$settings->isUseShopwareJavascript(); $event->setParameter('mollie_javascript_use_shopware', $useJsValue); - $mollieJavascriptAlreadyExists = false; - if ($this->versionCompare->gte('6.6')) { - $molliePayments = $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments'); - $mollieJavascriptAlreadyExists = $molliePayments && ($molliePayments->getScriptFiles()->count() > 0); - } - $event->setParameter('mollie_javascript_already_exists', $mollieJavascriptAlreadyExists); } } From d2019a14d73b2abb33c49b4fc2cbaea537d18a0b Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Tue, 21 May 2024 16:04:37 +0200 Subject: [PATCH 2/8] NTR: Cs fix --- src/Subscriber/StorefrontBuildSubscriber.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index b7eb4e34f..abfa06696 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -58,6 +58,5 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void $useJsValue = (int)$settings->isUseShopwareJavascript(); $event->setParameter('mollie_javascript_use_shopware', $useJsValue); - } } From 2eea3a8b27fe45f7a5696fa25127efade45eec96 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 22 May 2024 08:24:30 +0200 Subject: [PATCH 3/8] NTR: test plugin registration --- src/Resources/app/storefront/src/main.js | 7 ++----- src/Resources/config/services/subscriber.xml | 2 +- src/Resources/views/mollie/head.html.twig | 2 +- src/Subscriber/StorefrontBuildSubscriber.php | 12 +++++++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Resources/app/storefront/src/main.js b/src/Resources/app/storefront/src/main.js index 41b14800b..25eebab38 100644 --- a/src/Resources/app/storefront/src/main.js +++ b/src/Resources/app/storefront/src/main.js @@ -5,9 +5,6 @@ import MollieRegistration from './register'; // if it's however necessary to use the built-in all.js, then this would // also work, as long as its built in the Shopware version that uses it. -if (window.mollie_javascript_use_shopware !== undefined && window.mollie_javascript_use_shopware === '1') { +const molliePlugins = new MollieRegistration(); - const molliePlugins = new MollieRegistration(); - - molliePlugins.register(); -} +molliePlugins.register(); diff --git a/src/Resources/config/services/subscriber.xml b/src/Resources/config/services/subscriber.xml index 7f635b9a6..5c400c9dc 100644 --- a/src/Resources/config/services/subscriber.xml +++ b/src/Resources/config/services/subscriber.xml @@ -43,7 +43,7 @@ - %kernel.shopware_version% + diff --git a/src/Resources/views/mollie/head.html.twig b/src/Resources/views/mollie/head.html.twig index 72fe6c2c9..28d382a6c 100644 --- a/src/Resources/views/mollie/head.html.twig +++ b/src/Resources/views/mollie/head.html.twig @@ -31,7 +31,7 @@ window.mollie_javascript_use_shopware = '{{ mollie_javascript_use_shopware }}' - {% if mollie_javascript_use_shopware != '1' and includeJsInHeader == true %} + {% if mollie_javascript_already_exists == false and mollie_javascript_use_shopware != '1' and includeJsInHeader == true %} {% endif %} diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index abfa06696..e709bd307 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -25,16 +25,15 @@ class StorefrontBuildSubscriber implements EventSubscriberInterface */ private $versionCompare; - /** * @param SettingsService $settingsService * @param string $shopwareVersion */ - public function __construct(SettingsService $settingsService, StorefrontPluginRegistryInterface $pluginRegistry, string $shopwareVersion) + public function __construct(SettingsService $settingsService, StorefrontPluginRegistryInterface $pluginRegistry, VersionCompare $versionCompare) { $this->settingsService = $settingsService; $this->pluginRegistry = $pluginRegistry; - $this->versionCompare = new VersionCompare($shopwareVersion); + $this->versionCompare = $versionCompare; } /** @@ -58,5 +57,12 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void $useJsValue = (int)$settings->isUseShopwareJavascript(); $event->setParameter('mollie_javascript_use_shopware', $useJsValue); + + $mollieJavascriptAlreadyExists = false; + if ($this->versionCompare->gte('6.6')) { + $molliePayments = $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments'); + $mollieJavascriptAlreadyExists = $molliePayments && ($molliePayments->getScriptFiles()->count() > 0); + } + $event->setParameter('mollie_javascript_already_exists', $mollieJavascriptAlreadyExists); } } From c0c17af9b2aa929e5b6cff6ffbbaab0104d98d25 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 22 May 2024 08:31:09 +0200 Subject: [PATCH 4/8] NTR: stan --- src/Subscriber/StorefrontBuildSubscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index e709bd307..e5fd2003a 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -27,7 +27,8 @@ class StorefrontBuildSubscriber implements EventSubscriberInterface /** * @param SettingsService $settingsService - * @param string $shopwareVersion + * @param StorefrontPluginRegistryInterface $pluginRegistry + * @param VersionCompare $versionCompare */ public function __construct(SettingsService $settingsService, StorefrontPluginRegistryInterface $pluginRegistry, VersionCompare $versionCompare) { From f6f9a31232ed35d7367fcb561783433ec397a7f2 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 22 May 2024 08:40:48 +0200 Subject: [PATCH 5/8] NTR: force javascript use shopware in 6.6 --- src/Resources/app/storefront/src/main.js | 7 ++++--- src/Subscriber/StorefrontBuildSubscriber.php | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Resources/app/storefront/src/main.js b/src/Resources/app/storefront/src/main.js index 25eebab38..4a9a0a3ff 100644 --- a/src/Resources/app/storefront/src/main.js +++ b/src/Resources/app/storefront/src/main.js @@ -5,6 +5,7 @@ import MollieRegistration from './register'; // if it's however necessary to use the built-in all.js, then this would // also work, as long as its built in the Shopware version that uses it. -const molliePlugins = new MollieRegistration(); - -molliePlugins.register(); +if (window.mollie_javascript_use_shopware !== undefined && window.mollie_javascript_use_shopware === '1') { + const molliePlugins = new MollieRegistration(); + molliePlugins.register(); +} \ No newline at end of file diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index e5fd2003a..563209a36 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -63,6 +63,7 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void if ($this->versionCompare->gte('6.6')) { $molliePayments = $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments'); $mollieJavascriptAlreadyExists = $molliePayments && ($molliePayments->getScriptFiles()->count() > 0); + $event->setParameter('mollie_javascript_use_shopware', true); } $event->setParameter('mollie_javascript_already_exists', $mollieJavascriptAlreadyExists); } From c9f025b19af6bf5a9e7982cc0f3fcf62e919ca8f Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 22 May 2024 09:23:29 +0200 Subject: [PATCH 6/8] NTR: fix loading of script files --- .../storefront/src/mollie-payments/Plugin.js | 2 ++ .../core/creditcard-mandate.plugin.js | 3 ++- .../plugins/apple-pay-direct.plugin.js | 3 ++- .../plugins/apple-pay-payment-method.plugin.js | 3 ++- .../mollie-payments/plugins/bancomat-plugin.js | 4 +++- .../plugins/creditcard-mandate-manage.plugin.js | 3 ++- .../plugins/ideal-issuer.plugin.js | 3 ++- .../plugins/pos-terminal.plugin.js | 3 ++- src/Subscriber/StorefrontBuildSubscriber.php | 17 ++++++++++++++--- 9 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 src/Resources/app/storefront/src/mollie-payments/Plugin.js diff --git a/src/Resources/app/storefront/src/mollie-payments/Plugin.js b/src/Resources/app/storefront/src/mollie-payments/Plugin.js new file mode 100644 index 000000000..142fd8432 --- /dev/null +++ b/src/Resources/app/storefront/src/mollie-payments/Plugin.js @@ -0,0 +1,2 @@ + +export default class Plugin extends window.PluginBaseClass{} \ No newline at end of file diff --git a/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js b/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js index dfcf13966..f9942cb00 100644 --- a/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/core/creditcard-mandate.plugin.js @@ -1,9 +1,10 @@ import HttpClient from '../services/HttpClient'; +import Plugin from "../Plugin"; /** * This plugin manage the credit card mandate of the customer */ -export default class MollieCreditCardMandate extends window.PluginBaseClass { +export default class MollieCreditCardMandate extends Plugin { static options = { newCardMandateOption: null, mollieCreditCardFormClass: '.mollie-components-credit-card', diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js index 0b2d667e4..93c264ace 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-direct.plugin.js @@ -1,6 +1,7 @@ import HttpClient from '../services/HttpClient'; +import Plugin from "../Plugin"; -export default class MollieApplePayDirect extends window.PluginBaseClass { +export default class MollieApplePayDirect extends Plugin { /** * diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js index a79b06208..a2856efa8 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/apple-pay-payment-method.plugin.js @@ -1,6 +1,7 @@ import HttpClient from '../services/HttpClient'; +import Plugin from "../Plugin"; -export default class MollieApplePayPaymentMethod extends window.PluginBaseClass { +export default class MollieApplePayPaymentMethod extends Plugin { /** * diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js index 29cef07fe..eee0d5b46 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/bancomat-plugin.js @@ -1,4 +1,6 @@ -export default class MollieBancomatPlugin extends window.PluginBaseClass { +import Plugin from "../Plugin"; + +export default class MollieBancomatPlugin extends Plugin { init() { diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js index 6b8098b47..0903a86c0 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/creditcard-mandate-manage.plugin.js @@ -1,9 +1,10 @@ import HttpClient from '../services/HttpClient'; +import Plugin from "../Plugin"; /** * This plugin manage the credit card mandate of customer */ -export default class MollieCreditCardMandateManage extends window.PluginBaseClass { +export default class MollieCreditCardMandateManage extends Plugin { static options = { shopUrl: null, customerId: null, diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js index eb0bf898f..a684e203b 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/ideal-issuer.plugin.js @@ -1,7 +1,8 @@ import HttpClient from '../services/HttpClient' +import Plugin from "../Plugin"; -export default class MollieIDealIssuer extends window.PluginBaseClass { +export default class MollieIDealIssuer extends Plugin { _shopUrl = ''; _customerId = ''; diff --git a/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js b/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js index a7f4fa2d1..610f1dd7c 100644 --- a/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/plugins/pos-terminal.plugin.js @@ -1,7 +1,8 @@ import HttpClient from '../services/HttpClient' +import Plugin from "../Plugin"; -export default class MolliePosTerminalPlugin extends window.PluginBaseClass { +export default class MolliePosTerminalPlugin extends Plugin { _shopUrl = ''; _customerId = ''; diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index 563209a36..ae0cdf3a0 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -5,6 +5,7 @@ use Kiener\MolliePayments\Compatibility\VersionCompare; use Kiener\MolliePayments\Service\SettingsService; use Shopware\Storefront\Event\StorefrontRenderEvent; +use Shopware\Storefront\Theme\StorefrontPluginConfiguration\StorefrontPluginConfiguration; use Shopware\Storefront\Theme\StorefrontPluginRegistryInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -60,11 +61,21 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void $event->setParameter('mollie_javascript_use_shopware', $useJsValue); $mollieJavascriptAlreadyExists = false; + if ($this->versionCompare->gte('6.6')) { - $molliePayments = $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments'); - $mollieJavascriptAlreadyExists = $molliePayments && ($molliePayments->getScriptFiles()->count() > 0); - $event->setParameter('mollie_javascript_use_shopware', true); + $plugin = $this->pluginRegistry->getConfigurations()->getByTechnicalName('MolliePayments'); + + if ($plugin instanceof StorefrontPluginConfiguration) { + $scriptFiles = $plugin->getScriptFiles(); + + if ($useJsValue === 0) { + $scriptFiles->remove(0); + } + $mollieJavascriptAlreadyExists = $scriptFiles->count() > 0; + } } + $event->setParameter('mollie_javascript_already_exists', $mollieJavascriptAlreadyExists); + $event->setParameter('mollie_javascript_already_exists', false); } } From fa83d3339375b0cfd8d4f0e64a90da9b8b059db1 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 22 May 2024 16:19:06 +0200 Subject: [PATCH 7/8] NTR: restore plugin class --- .../app/storefront/build/webpack.config.js | 13 ++ .../storefront/src/mollie-payments/Plugin.js | 4 +- .../shopware-storefront-sdk/README.md | 17 +++ .../helper/DeviceDetection.d.ts | 1 + .../helper/DeviceDetection.js | 7 + .../helper/String.d.ts | 4 + .../shopware-storefront-sdk/helper/String.js | 24 ++++ .../shopware-storefront-sdk/package.json | 25 ++++ .../plugin-system/NativeEventEmitter.d.ts | 22 ++++ .../plugin-system/NativeEventEmitter.js | 86 ++++++++++++ .../plugin-system/plugin.class.d.ts | 16 +++ .../plugin-system/plugin.class.js | 123 ++++++++++++++++++ .../app/storefront/webpack.config.js | 11 +- 13 files changed, 350 insertions(+), 3 deletions(-) create mode 100644 src/Resources/app/storefront/build/webpack.config.js create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/README.md create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.d.ts create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.js create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.d.ts create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.js create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/package.json create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.d.ts create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.js create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.d.ts create mode 100644 src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.js diff --git a/src/Resources/app/storefront/build/webpack.config.js b/src/Resources/app/storefront/build/webpack.config.js new file mode 100644 index 000000000..950a0d439 --- /dev/null +++ b/src/Resources/app/storefront/build/webpack.config.js @@ -0,0 +1,13 @@ +const {resolve, join} = require("path"); + +module.exports = () => { + return { + resolve: { + alias: { + '@shopware-storefront-sdk': resolve( + join(__dirname, '..', 'src_vendor', 'shopware-storefront-sdk'), + ), + }, + }, + }; +}; \ No newline at end of file diff --git a/src/Resources/app/storefront/src/mollie-payments/Plugin.js b/src/Resources/app/storefront/src/mollie-payments/Plugin.js index 142fd8432..aaa57af29 100644 --- a/src/Resources/app/storefront/src/mollie-payments/Plugin.js +++ b/src/Resources/app/storefront/src/mollie-payments/Plugin.js @@ -1,2 +1,2 @@ - -export default class Plugin extends window.PluginBaseClass{} \ No newline at end of file +import ShopwarePlugin from '@shopware-storefront-sdk/plugin-system/plugin.class'; +export default class Plugin extends ShopwarePlugin{} \ No newline at end of file diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/README.md b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/README.md new file mode 100644 index 000000000..22ae1747b --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/README.md @@ -0,0 +1,17 @@ +# Shopware Storefront SDK + +## Description + +The Shopware Storefront SDK is a set of classes and methods to easily access the Shopware Storefront. +So in your plugins, you can add this package as dependency and use the classes from this package instead of default Shopware files. + +## Features + +- Build Shopware Version independent plugin +- Ability to build your plugin javascript without having the Shopware 6 code-base + +## Installation + +```bash +npm install shopware-storefront-sdk +``` diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.d.ts b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.d.ts new file mode 100644 index 000000000..5e35d30a1 --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.d.ts @@ -0,0 +1 @@ +export declare function isTouchDevice(): boolean; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.js b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.js new file mode 100644 index 000000000..5e808288e --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/DeviceDetection.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isTouchDevice = void 0; +function isTouchDevice() { + return ('ontouchstart' in document.documentElement); +} +exports.isTouchDevice = isTouchDevice; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.d.ts b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.d.ts new file mode 100644 index 000000000..8819ee9df --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.d.ts @@ -0,0 +1,4 @@ +export declare function ucFirst(value: string): string; +export declare function lcFirst(value: string): string; +export declare function toLowerCamelCase(value: string, separator: string): string; +export declare function toUpperCamelCase(value: string, separator: string): string; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.js b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.js new file mode 100644 index 000000000..5103b7436 --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/helper/String.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toUpperCamelCase = exports.toLowerCamelCase = exports.lcFirst = exports.ucFirst = void 0; +function ucFirst(value) { + return value.charAt(0).toUpperCase() + value.slice(1); +} +exports.ucFirst = ucFirst; +function lcFirst(value) { + return value.charAt(0).toLowerCase() + value.slice(1); +} +exports.lcFirst = lcFirst; +function toLowerCamelCase(value, separator) { + var upperCamelCase = toUpperCamelCase(value, separator); + return lcFirst(upperCamelCase); +} +exports.toLowerCamelCase = toLowerCamelCase; +function toUpperCamelCase(value, separator) { + if (!separator) { + return ucFirst(value.toLowerCase()); + } + var stringParts = value.split(separator); + return stringParts.map(function (string) { return ucFirst(string.toLowerCase()); }).join(''); +} +exports.toUpperCamelCase = toUpperCamelCase; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/package.json b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/package.json new file mode 100644 index 000000000..badc32db9 --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/package.json @@ -0,0 +1,25 @@ +{ + "name": "shopware-storefront-sdk", + "version": "0.0.2", + "description": "Provides Shopware Storefront Utilities as Typescript", + "main": "sdk.js", + "types": "sdk.d.ts", + "scripts": { + "publish-to-npm": "rm -rf dist; tsc --build && cp package.json dist && cat ./package.json | grep -v '\\\"private\\\":' > dist/package.json; cp README.md dist" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/FriendsOfShopware/shopware-storefront-sdk.git" + }, + "bugs": { + "url": "https://github.com/FriendsOfShopware/shopware-storefront-sdk/issues" + }, + "author": "FriendsOfShopware", + "license": "MIT", + "dependencies": { + "deepmerge": "^4.2.2" + }, + "devDependencies": { + "typescript": "^4.7.4" + } +} diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.d.ts b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.d.ts new file mode 100644 index 000000000..083a001e9 --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.d.ts @@ -0,0 +1,22 @@ +interface NativeEventEmitterPublish { + detail?: object; + cancelable?: boolean; +} +interface NativeEventEmitterSubscribeOpts { + once?: boolean; + scope?: Function; +} +export default class NativeEventEmitter { + private _listeners; + private _el; + constructor(el: HTMLElement); + publish(eventName: string, detail?: NativeEventEmitterPublish, cancelable?: boolean): CustomEvent; + subscribe(eventName: string, callback: Function, opts?: NativeEventEmitterSubscribeOpts): boolean; + unsubscribe(eventName: String): boolean; + reset(): boolean; + get el(): HTMLElement; + set el(value: HTMLElement); + get listeners(): any[]; + set listeners(value: any[]); +} +export {}; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.js b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.js new file mode 100644 index 000000000..9aa92d954 --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/NativeEventEmitter.js @@ -0,0 +1,86 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var NativeEventEmitter = /** @class */ (function () { + function NativeEventEmitter(el) { + this._el = el; + // @ts-ignore + el.$emitter = this; + this._listeners = []; + } + NativeEventEmitter.prototype.publish = function (eventName, detail, cancelable) { + if (detail === void 0) { detail = {}; } + if (cancelable === void 0) { cancelable = false; } + var event = new CustomEvent(eventName, { + detail: detail, + cancelable: cancelable, + }); + this.el.dispatchEvent(event); + return event; + }; + NativeEventEmitter.prototype.subscribe = function (eventName, callback, opts) { + if (opts === void 0) { opts = {}; } + var emitter = this; + var splitEventName = eventName.split('.'); + var cb = opts.scope ? callback.bind(opts.scope) : callback; + // Support for listeners which are fired once + if (opts.once && opts.once === true) { + var onceCallback_1 = cb; + cb = function onceListener(event) { + emitter.unsubscribe(eventName); + onceCallback_1(event); + }; + } + this.el.addEventListener(splitEventName[0], cb); + this.listeners.push({ + splitEventName: splitEventName, + opts: opts, + cb: cb, + }); + return true; + }; + NativeEventEmitter.prototype.unsubscribe = function (eventName) { + var _this = this; + var splitEventName = eventName.split('.'); + this.listeners = this.listeners.reduce(function (accumulator, listener) { + var foundEvent = listener.splitEventName.sort().toString() === splitEventName.sort().toString(); + if (foundEvent) { + _this.el.removeEventListener(listener.splitEventName[0], listener.cb); + return accumulator; + } + accumulator.push(listener); + return accumulator; + }, []); + return true; + }; + NativeEventEmitter.prototype.reset = function () { + var _this = this; + this.listeners.forEach(function (listener) { + _this.el.removeEventListener(listener.splitEventName[0], listener.cb); + }); + // Reset registry + this.listeners = []; + return true; + }; + Object.defineProperty(NativeEventEmitter.prototype, "el", { + get: function () { + return this._el; + }, + set: function (value) { + this._el = value; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(NativeEventEmitter.prototype, "listeners", { + get: function () { + return this._listeners; + }, + set: function (value) { + this._listeners = value; + }, + enumerable: false, + configurable: true + }); + return NativeEventEmitter; +}()); +exports.default = NativeEventEmitter; diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.d.ts b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.d.ts new file mode 100644 index 000000000..2f3f09c02 --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.d.ts @@ -0,0 +1,16 @@ +export default abstract class PluginClass { + private readonly el; + private $emitter; + private readonly _pluginName; + private readonly options; + private _initialized; + constructor(el: HTMLElement, options?: any, pluginName?: boolean | string); + private _init; + _update(): void; + abstract init(): void; + update(): void; + _registerInstance(): void; + private _getPluginName; + private _mergeOptions; + private parseJsonOrFail; +} diff --git a/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.js b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.js new file mode 100644 index 000000000..d3728aac0 --- /dev/null +++ b/src/Resources/app/storefront/src_vendor/shopware-storefront-sdk/plugin-system/plugin.class.js @@ -0,0 +1,123 @@ +"use strict"; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : {"default": mod}; +}; + +Object.defineProperty(exports, "__esModule", {value: true}); + +var NativeEventEmitter_1 = __importDefault(require("./NativeEventEmitter")); + +var deepmerge_1 = __importDefault(require("deepmerge")); + +var PluginClass = /** @class */ (function () { + + function PluginClass(el, options, pluginName) { + + if (options === void 0) { + options = {}; + } + if (pluginName === void 0) { + pluginName = false; + } + this.el = el; + this.$emitter = new NativeEventEmitter_1.default(this.el); + this._pluginName = this._getPluginName(pluginName); + this.options = this._mergeOptions(options); + this._initialized = false; + this._registerInstance(); + this._init(); + } + + PluginClass.prototype._init = function () { + if (this._initialized) + return; + this.init(); + this._initialized = true; + }; + + PluginClass.prototype._update = function () { + if (!this._initialized) + return; + this.update(); + }; + + PluginClass.prototype.update = function () { + }; + + PluginClass.prototype._registerInstance = function () { + var elementPluginInstances = window.PluginManager.getPluginInstancesFromElement(this.el); + elementPluginInstances.set(this._pluginName, this); + var plugin = window.PluginManager.getPlugin(this._pluginName, false); + plugin.get('instances').push(this); + }; + + PluginClass.prototype._getPluginName = function (pluginName) { + if (pluginName === false) { + // @ts-ignore + return this.constructor.name; + } + return pluginName; + }; + + PluginClass.prototype._mergeOptions = function (options) { + var dashedPluginName = this._pluginName.replace(/([A-Z])/g, '-$1').replace(/^-/, '').toLowerCase(); + var dataAttributeConfig = this.parseJsonOrFail(dashedPluginName); + + let dataAttributeOptions = ''; + + if (typeof this.el.getAttribute === 'function') { + dataAttributeOptions = this.el.getAttribute("data-".concat(dashedPluginName, "-options")) || ''; + } + + // static plugin options + // previously merged options + // explicit options when creating a plugin instance with 'new' + var merge = [ + // @ts-ignore + this.constructor.options, + this.options, + options, + ]; + + // options which are set via data-plugin-name-config="config name" + if (dataAttributeConfig) { + merge.push(window.PluginConfigManager.get(this._pluginName, dataAttributeConfig)); + } + + // options which are set via data-plugin-name-options="{json..}" + try { + if (dataAttributeOptions) + merge.push(JSON.parse(dataAttributeOptions)); + } catch (e) { + throw new Error("The data attribute \"data-".concat(dashedPluginName, "-options\" could not be parsed to json: ").concat(e.message || '')); + } + + return deepmerge_1.default.all(merge.filter(function (config) { + return config instanceof Object && !(config instanceof Array); + }) + .map(function (config) { + return config || {}; + })); + }; + + PluginClass.prototype.parseJsonOrFail = function (dashedPluginName) { + + if (typeof this.el.getAttribute !== 'function') { + return ''; + } + + const value = this.el.getAttribute("data-".concat(dashedPluginName, "-config")) || ''; + + try { + return JSON.parse(value); + } catch (e) { + return value; + } + }; + + return PluginClass; + +}()); + +exports.default = PluginClass; diff --git a/src/Resources/app/storefront/webpack.config.js b/src/Resources/app/storefront/webpack.config.js index bbaaa627d..d5c692a76 100644 --- a/src/Resources/app/storefront/webpack.config.js +++ b/src/Resources/app/storefront/webpack.config.js @@ -1,4 +1,5 @@ const path = require('path') +const {resolve, join} = require("path"); module.exports = { mode: 'production', @@ -7,4 +8,12 @@ module.exports = { path: path.resolve(__dirname, '..', '..', 'public'), filename: 'mollie-payments.js', }, -} + resolve: { + extensions: ['.js'], + alias: { + '@shopware-storefront-sdk': resolve( + join(__dirname, 'src_vendor', 'shopware-storefront-sdk'), + ), + }, + }, +} \ No newline at end of file From 01043240f550c0bfa3851dfee3b06f734bd51b12 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Thu, 23 May 2024 07:57:51 +0200 Subject: [PATCH 8/8] NTR: remove invalid line --- src/Subscriber/StorefrontBuildSubscriber.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Subscriber/StorefrontBuildSubscriber.php b/src/Subscriber/StorefrontBuildSubscriber.php index ae0cdf3a0..c21febd87 100644 --- a/src/Subscriber/StorefrontBuildSubscriber.php +++ b/src/Subscriber/StorefrontBuildSubscriber.php @@ -76,6 +76,5 @@ public function onStorefrontRender(StorefrontRenderEvent $event): void } $event->setParameter('mollie_javascript_already_exists', $mollieJavascriptAlreadyExists); - $event->setParameter('mollie_javascript_already_exists', false); } }