Skip to content

Commit

Permalink
WIP-Add data
Browse files Browse the repository at this point in the history
  • Loading branch information
Isengo1989 committed Mar 4, 2024
1 parent 483e938 commit 9cdfe5c
Showing 1 changed file with 318 additions and 1 deletion.
319 changes: 318 additions & 1 deletion guides/plugins/plugins/administration/using-data-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,323 @@ Shopware.Component.register('swag-basic-example', {
});
```

#### Working with entity extensions

The following example shows how to pass on and save data of entity extensions.

```javascript
import template from './swag-paypal-pos-wizard.html.twig';
import './swag-paypal-pos-wizard.scss';
import {
PAYPAL_POS_SALES_CHANNEL_EXTENSION,
PAYPAL_POS_SALES_CHANNEL_TYPE_ID,
} from '../../../../../constant/swag-paypal.constant';

const { Component, Context } = Shopware;
const { Criteria } = Shopware.Data;

Check warning on line 712 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L712

Add a space between sentences. (SENTENCE_WHITESPACE) Suggestions: ` Data` Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US Category: TYPOGRAPHY
Raw output
guides/plugins/plugins/administration/using-data-handling.md:712:30: Add a space between sentences. (SENTENCE_WHITESPACE)
 Suggestions: ` Data`
 Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US
 Category: TYPOGRAPHY

Component.extend('swag-paypal-pos-wizard', 'sw-first-run-wizard-modal', {
template,

inject: [
'SwagPayPalPosApiService',
'SwagPayPalPosSettingApiService',
'SwagPayPalPosWebhookRegisterService',
'salesChannelService',
'repositoryFactory',
],

mixins: [
'swag-paypal-pos-catch-error',
'notification',
],

data() {
return {
showModal: true,
isLoading: false,
salesChannel: {},
cloneSalesChannelId: null,
stepperPages: [
'connection',
'connectionSuccess',
'connectionDisconnect',
'customization',
'productSelection',
'syncLibrary',
'syncPrices',
'finish',
],
stepper: {},
currentStep: {},
};
},

metaInfo() {
return {
title: this.wizardTitle,
};
},

computed: {
displayStepperPages() {
return this.stepperPages.filter((item) => {
return item !== 'connectionDisconnect';
});
},

stepInitialItemVariants() {
const maxNavigationIndex = this.stepperPages.length;
const { navigationIndex } = this.currentStep;
const navigationSteps = [];

for (let i = 1; i <= maxNavigationIndex; i += 1) {
if (i < navigationIndex) {
navigationSteps.push('success');
} else if (i === navigationIndex) {
navigationSteps.push('info');
} else {
navigationSteps.push('disabled');
}
}
return navigationSteps;
},

paypalPosSalesChannelRepository() {
return this.repositoryFactory.create('swag_paypal_pos_sales_channel');

Check warning on line 782 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L782

The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1]) Suggestions: `PayPal` URL: https://en.wikipedia.org/wiki/PayPal Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1 Category: CASING
Raw output
guides/plugins/plugins/administration/using-data-handling.md:782:55: The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1])
 Suggestions: `PayPal`
 URL: https://en.wikipedia.org/wiki/PayPal 
 Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1
 Category: CASING
},

salesChannelRepository() {
return this.repositoryFactory.create('sales_channel');
},

salesChannelCriteria() {
return (new Criteria(1, 500))
.addAssociation(PAYPAL_POS_SALES_CHANNEL_EXTENSION)
.addAssociation('countries')
.addAssociation('currencies')
.addAssociation('domains')
.addAssociation('languages');
},

wizardTitle() {
const params = [
this.$tc('global.sw-admin-menu.textShopwareAdmin'),
this.$tc('swag-paypal-pos.general.moduleTitle'),
this.title,
];

return params.reverse().join(' | ');
},
},

watch: {
'$route'(to) {
this.handleRouteUpdate(to);
},
},

mounted() {
this.mountedComponent();
},

methods: {
handleRouteUpdate(to) {
const toName = to.name.replace('swag.paypal.pos.wizard.', '');

Check warning on line 821 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L821

The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1]) Suggestions: `PayPal` URL: https://en.wikipedia.org/wiki/PayPal Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1 Category: CASING
Raw output
guides/plugins/plugins/administration/using-data-handling.md:821:49: The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1])
 Suggestions: `PayPal`
 URL: https://en.wikipedia.org/wiki/PayPal 
 Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1
 Category: CASING

this.currentStep = this.stepper[toName];
},

createdComponent() {
this.generateStepper();

const salesChannelId = this.$route.params.id;
if (salesChannelId) {
this.loadSalesChannel();
return;
}

this.createNewSalesChannel();
},

mountedComponent() {
const step = this.$route.name.replace('swag.paypal.pos.wizard.', '');

Check warning on line 839 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L839

The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1]) Suggestions: `PayPal` URL: https://en.wikipedia.org/wiki/PayPal Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1 Category: CASING
Raw output
guides/plugins/plugins/administration/using-data-handling.md:839:56: The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1])
 Suggestions: `PayPal`
 URL: https://en.wikipedia.org/wiki/PayPal 
 Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1
 Category: CASING
this.currentStep = this.stepper[step];
},

generateStepper() {
let index = 1;
this.stepper = this.stepperPages.reduce((accumulator, pageName) => {
if (pageName === 'connectionDisconnect') {
index -= 1;
}

accumulator[pageName] = {
name: `swag.paypal.pos.wizard.${pageName}`,

Check warning on line 851 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L851

The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1]) Suggestions: `PayPal` URL: https://en.wikipedia.org/wiki/PayPal Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1 Category: CASING
Raw output
guides/plugins/plugins/administration/using-data-handling.md:851:32: The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1])
 Suggestions: `PayPal`
 URL: https://en.wikipedia.org/wiki/PayPal 
 Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1
 Category: CASING
variant: 'large',
navigationIndex: index,
};

if (index === 1) {
this.currentStep = accumulator[pageName];
}
index += 1;

return accumulator;
}, {});
},

onCloseModal() {
if (!this.salesChannel._isNew && (this.$route.params.id || this.salesChannel.id)) {
this.routeToDetailOverview();

return;
}

this.routeToDashboard();
},

onFinishWizard() {
this.routeToDetailOverview(true);
},

routeToDashboard() {
this.showModal = false;

this.$nextTick(() => {
this.$router.push({ name: 'sw.dashboard.index' });
});
},

routeToDetailOverview(finished = false) {
this.showModal = false;

this.save(finished).then(() => {
if (finished) {
this.SwagPayPalPosApiService.startCompleteSync(this.salesChannel.id);

Check warning on line 892 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L892

Add a space between sentences. (SENTENCE_WHITESPACE) Suggestions: ` SwagPayPalPosApiService` Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US Category: TYPOGRAPHY
Raw output
guides/plugins/plugins/administration/using-data-handling.md:892:25: Add a space between sentences. (SENTENCE_WHITESPACE)
 Suggestions: ` SwagPayPalPosApiService`
 Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US
 Category: TYPOGRAPHY
}

this.$router.push({
name: 'swag.paypal.pos.detail.overview',

Check warning on line 896 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L896

The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1]) Suggestions: `PayPal` URL: https://en.wikipedia.org/wiki/PayPal Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1 Category: CASING
Raw output
guides/plugins/plugins/administration/using-data-handling.md:896:32: The official name of this payment provider is spelled with two capital “P”. (PAYPAL[1])
 Suggestions: `PayPal`
 URL: https://en.wikipedia.org/wiki/PayPal 
 Rule: https://community.languagetool.org/rule/show/PAYPAL?lang=en-US&subId=1
 Category: CASING
params: { id: this.salesChannel.id },

Check warning on line 897 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L897

This abbreviation for “identification” is spelled all-uppercase. (ID_CASING[2]) Suggestions: `ID` Rule: https://community.languagetool.org/rule/show/ID_CASING?lang=en-US&subId=2 Category: CASING
Raw output
guides/plugins/plugins/administration/using-data-handling.md:897:30: This abbreviation for “identification” is spelled all-uppercase. (ID_CASING[2])
 Suggestions: `ID`
 Rule: https://community.languagetool.org/rule/show/ID_CASING?lang=en-US&subId=2
 Category: CASING
});
});
},

save(activateSalesChannel = false, silentWebhook = false) {
if (activateSalesChannel) {
this.salesChannel.active = true;
}

return this.salesChannelRepository.save(this.salesChannel, Context.api).then(async () => {
this.isLoading = false;
this.isSaveSuccessful = true;
this.isNewEntity = false;

this.$root.$emit('sales-channel-change');
await this.loadSalesChannel();

this.cloneProductVisibility();
this.registerWebhook(silentWebhook);
}).catch(() => {
this.isLoading = false;

this.createNotificationError({
message: this.$tc('sw-sales-channel.detail.messageSaveError', 0, {
name: this.salesChannel.name || this.placeholder(this.salesChannel, 'name'),
}),
});
});
},

registerWebhook(silent = false) {
const webhookPromise = this.SwagPayPalPosWebhookRegisterService.registerWebhook(this.salesChannel.id);

Check warning on line 929 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L929

Add a space between sentences. (SENTENCE_WHITESPACE) Suggestions: ` SwagPayPalPosWebhookRegisterService` Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US Category: TYPOGRAPHY
Raw output
guides/plugins/plugins/administration/using-data-handling.md:929:40: Add a space between sentences. (SENTENCE_WHITESPACE)
 Suggestions: ` SwagPayPalPosWebhookRegisterService`
 Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US
 Category: TYPOGRAPHY

if (!silent) {
return webhookPromise.catch(this.catchError.bind(this, 'swag-paypal-pos.messageWebhookRegisterError'));
}

return webhookPromise;
},

cloneProductVisibility() {
if (this.cloneSalesChannelId === null) {
return;
}

this.SwagPayPalPosSettingApiService.cloneProductVisibility(

Check warning on line 943 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L943

Add a space between sentences. (SENTENCE_WHITESPACE) Suggestions: ` SwagPayPalPosSettingApiService` Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US Category: TYPOGRAPHY
Raw output
guides/plugins/plugins/administration/using-data-handling.md:943:17: Add a space between sentences. (SENTENCE_WHITESPACE)
 Suggestions: ` SwagPayPalPosSettingApiService`
 Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US
 Category: TYPOGRAPHY
this.cloneSalesChannelId,
this.salesChannel.id,
).catch((errorResponse) => {
if (errorResponse.response.data && errorResponse.response.data.errors) {
this.createNotificationError({
message: this.$tc('swag-paypal-pos.messageCloneError'),
});
}
});
},

createNewSalesChannel() {
if (Context.api.languageId !== Context.api.systemLanguageId) {
Context.api.languageId = Context.api.systemLanguageId;
}

this.previousApiKey = null;
this.salesChannel = this.salesChannelRepository.create(Context.api);
this.salesChannel.typeId = PAYPAL_POS_SALES_CHANNEL_TYPE_ID;
this.salesChannel.name = this.$tc('swag-paypal-pos.wizard.salesChannelPrototypeName');
this.salesChannel.active = false;

this.salesChannel.extensions.paypalPosSalesChannel
= this.paypalPosSalesChannelRepository.create(Context.api);

Object.assign(
this.salesChannel.extensions.paypalPosSalesChannel,
{
mediaDomain: '',
apiKey: '',
imageDomain: '',
productStreamId: null,
syncPrices: true,
replace: 0,
},
);

this.salesChannelService.generateKey().then((response) => {
this.salesChannel.accessKey = response.accessKey;
}).catch(() => {
this.createNotificationError({
message: this.$tc('sw-sales-channel.detail.messageAPIError'),
});
});
},

loadSalesChannel() {
const salesChannelId = this.$route.params.id || this.salesChannel.id;
if (!salesChannelId) {
return new Promise((resolve) => { resolve(); });
}

this.isLoading = true;
return this.salesChannelRepository.get(salesChannelId, Shopware.Context.api, this.salesChannelCriteria)

Check warning on line 997 in guides/plugins/plugins/administration/using-data-handling.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/administration/using-data-handling.md#L997

Add a space between sentences. (SENTENCE_WHITESPACE) Suggestions: ` Context` Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US Category: TYPOGRAPHY
Raw output
guides/plugins/plugins/administration/using-data-handling.md:997:76: Add a space between sentences. (SENTENCE_WHITESPACE)
 Suggestions: ` Context`
 Rule: https://community.languagetool.org/rule/show/SENTENCE_WHITESPACE?lang=en-US
 Category: TYPOGRAPHY
.then((entity) => {
this.salesChannel = entity;
this.previousApiKey = entity.extensions.paypalPosSalesChannel.apiKey;
this.isLoading = false;
});
},

updateCloneSalesChannel(cloneSalesChannelId) {
this.cloneSalesChannelId = cloneSalesChannelId;
},

toggleLoading(state) {
this.isLoading = state;
},
},
});
```

## Next steps

As this is very similar to the DAL it might be interesting to learn more about that. For this, head over to the section about the [data handling](../framework/data-handling/) in PHP.
As this is very similar to the DAL it might be interesting to learn more about that. For this, head over to the section about the [data handling](../framework/data-handling/) in PHP.

0 comments on commit 9cdfe5c

Please sign in to comment.