Skip to content

Commit

Permalink
Merge pull request #1 from hungmac-sw/fixed-bug-and-add-share-theme
Browse files Browse the repository at this point in the history
Fixed bug preview theme, Added copy & share button
  • Loading branch information
hungmac-sw authored Jun 7, 2020
2 parents f10deec + 1cf78ed commit 702d695
Show file tree
Hide file tree
Showing 19 changed files with 271 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.0.0

* Button Copy Link & Share Theme hinzugefügt
* Behobener Fehler kann keine Vorschau anderer Seiten außer der Homepage anzeigen

# 0.30.4

* Erste Veröffentlichung mit Feature-Vorschau-Thema im Detail des Vertriebskanals
5 changes: 5 additions & 0 deletions CHANGELOG_en-GB.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.0.0

* Added button copy link & share theme
* Fixed bug can't preview other pages except the homepage

# 0.30.4

* First release with feature preview theme in sales channel detail
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Preview theme for Shopware 6
# Theme preview for Shopware 6

[![Gitter](https://badges.gitter.im/mac/community.svg)](https://gitter.im/mac/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

Expand Down
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{
"name": "mac/theme-preview",
"description": "Theme preview plugin for Shopware 6",
"version": "0.30.4",
"version": "1.0.0",
"type": "shopware-platform-plugin",
"license": "MIT",
"authors": [
{
"name": "Hung Mac"
}
],
"require": {
"shopware/core": "~6.2.0"
},
"autoload": {
"psr-4": {
"MacThemePreview\\": "src/"
Expand All @@ -20,8 +17,8 @@
"extra": {
"shopware-plugin-class": "MacThemePreview\\MacThemePreview",
"label": {
"de-DE": "Theme Preview Plugin for Shopware 6",
"en-GB": "Theme Preview Plugin für Shopware 6"
"de-DE": "Theme Preview Plugin für Shopware 6",
"en-GB": "Theme Preview Plugin for Shopware 6"
}
},
"suggest": {
Expand Down
28 changes: 28 additions & 0 deletions src/Framework/Cookie/CustomCookieProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

namespace MacThemePreview\Framework\Cookie;

use Shopware\Storefront\Framework\Cookie\CookieProviderInterface;

class CustomCookieProvider implements CookieProviderInterface {

private $originalService;

function __construct(CookieProviderInterface $service)
{
$this->originalService = $service;
}

public function getCookieGroups(): array
{
return array_merge(
$this->originalService->getCookieGroups(),
[
[
'snippet_name' => 'cookie.theme',
'cookie' => 'preview-theme-id',
]
]
);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import template from './sw-theme-modal.html.twig';

const { Component } = Shopware;
const { Component, Mixin } = Shopware;
const { Criteria } = Shopware.Data;
const domUtils = Shopware.Utils.dom;

Component.override('sw-theme-modal', {
template,

mixins: [
Mixin.getByName('notification')
],

inject: [
'macThemePreviewService'
],
Expand All @@ -14,7 +19,8 @@ Component.override('sw-theme-modal', {
return {
selected: null,
themes: [],
isLoadingPreview: false
isLoadingPreview: false,
isLoadingCopy: false
};
},

Expand Down Expand Up @@ -55,16 +61,52 @@ Component.override('sw-theme-modal', {
},

selectPreview() {
const theme = this.themes.find((theme) => theme.id === this.selected);
if (!!theme && !!this.salesChannel.domains) {
if (this.checkConditions()) {
this.isLoadingPreview = true;

this.macThemePreviewService.themeCompile(this.salesChannel.id, theme.id).then(() => {
this.macThemePreviewService.themeCompile(this.salesChannel.id, this.selected).then(() => {
this.isLoadingPreview = false;
const previewUrl = this.salesChannel.domains.first().url + '/?preview-theme-id=' + this.selected;
window.open(previewUrl);
window.open(this.renderPreviewUrl());
});
}
},

copyToClipboard() {
if (this.checkConditions()) {
this.isLoadingCopy = true;
this.macThemePreviewService.themeCompile(this.salesChannel.id, this.selected).then(() => {
this.isLoadingCopy = false;
domUtils.copyToClipboard(this.renderPreviewUrl());
this.createNotificationInfo({
title: this.$tc('global.default.info'),
message: this.$tc('mac-theme-preview.notification.notificationCopyLinkSuccess')
});
});
}
},

renderPreviewUrl() {
return this.salesChannel.domains.first().url + '/?preview-theme-id=' + this.selected;
},

checkConditions() {
const theme = this.themes.find((theme) => theme.id === this.selected);
if (!theme) {
this.createNotificationError({
title: this.$tc('global.default.error'),
message: this.$tc('global.notification.unspecifiedSaveErrorMessage')
});
return false;
}

if (!this.salesChannel.domains.first()) {
this.createNotificationError({
title: this.$tc('global.default.error'),
message: this.$tc('mac-theme-preview.notification.notificationEmptyDomain')
});
return false;
}

return true;
}
}
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% block sw_theme_modal_footer %}
<template slot="modal-footer">
<sw-button v-if="selected" @click="copyToClipboard" :isLoading="isLoadingCopy">
{{ $tc('mac-theme-preview.buttonCopyLink') }}
</sw-button>

<sw-button v-if="selected" @click="selectPreview" :isLoading="isLoadingPreview">
{{ $tc('mac-theme-preview.previewButton') }}
</sw-button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"mac-theme-preview": {
"previewButton": "Vorschau"
"previewButton": "Vorschau",
"buttonCopyLink": "Kopieren & teilen",
"notificationCopyLinkSuccess": "URL in Zwischenablage kopiert.",
"notificationEmptyDomain": "Dieser Vertriebskanal hat keine Domain."
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"mac-theme-preview": {
"previewButton": "Preview"
"previewButton": "Preview",
"buttonCopyLink": "Copy & Share",
"notification": {
"notificationCopyLinkSuccess": "URL has been copied to clipboard.",
"notificationEmptyDomain": "This sales channel have no domain."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ApiService
class MacThemePreviewService extends ApiService {
constructor(httpClient, loginService, apiEndpoint = 'mac-theme-preview') {
super(httpClient, loginService, apiEndpoint);
this.name = 'macThemePreviewService';
this.name = 'MacThemePreviewService';
}

themeCompile(salesChannelId, themeId) {
Expand Down
Loading

0 comments on commit 702d695

Please sign in to comment.