Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTR: PISHPS-285: test mollie storfront plugins #752

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Resources/app/storefront/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import MollieRegistration from './register';
// 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();

molliePlugins.register();
}
}
2 changes: 2 additions & 0 deletions src/Resources/app/storefront/src/mollie-payments/Plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import ShopwarePlugin from '@shopware-storefront-sdk/plugin-system/plugin.class';
export default class Plugin extends ShopwarePlugin{}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class';
import HttpClient from '../services/HttpClient';
import Plugin from "../Plugin";

/**
* This plugin manage the credit card mandate of the customer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class';
import HttpClient from '../services/HttpClient';
import Plugin from "../Plugin";

export default class MollieApplePayDirect extends Plugin {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class';
import HttpClient from '../services/HttpClient';
import Plugin from "../Plugin";

export default class MollieApplePayPaymentMethod extends Plugin {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class';
import Plugin from "../Plugin";

export default class MollieBancomatPlugin extends Plugin {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class';
import HttpClient from '../services/HttpClient';
import Plugin from "../Plugin";

/**
* This plugin manage the credit card mandate of customer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class';
import HttpClient from '../services/HttpClient'
import Plugin from "../Plugin";


export default class MollieIDealIssuer extends Plugin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class';
import HttpClient from '../services/HttpClient'
import Plugin from "../Plugin";


export default class MolliePosTerminalPlugin extends Plugin {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/app/storefront/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ module.exports = {
),
},
},
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/services/subscriber.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<service id="Kiener\MolliePayments\Subscriber\StorefrontBuildSubscriber">
<argument type="service" id="Kiener\MolliePayments\Service\SettingsService"/>
<argument type="service" id="Shopware\Storefront\Theme\StorefrontPluginRegistry"/>
<argument>%kernel.shopware_version%</argument>
<argument type="service" id="Kiener\MolliePayments\Compatibility\VersionCompare"/>
<tag name="kernel.event_subscriber"/>
</service>

Expand Down
23 changes: 17 additions & 6 deletions src/Subscriber/StorefrontBuildSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,16 +26,16 @@ class StorefrontBuildSubscriber implements EventSubscriberInterface
*/
private $versionCompare;


/**
* @param SettingsService $settingsService
* @param string $shopwareVersion
* @param StorefrontPluginRegistryInterface $pluginRegistry
* @param VersionCompare $versionCompare
*/
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;
}

/**
Expand All @@ -60,10 +61,20 @@ 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);
$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);
}
}
Loading