Skip to content

Commit

Permalink
Merge branch 'next-18082/create-action-to-set-afiliate-and-campaign-c…
Browse files Browse the repository at this point in the history
…ode-of-customer-and-order' into 'trunk'

NEXT-18082 - Create action to set an affiliate and campaign code to customer and order

See merge request shopware/6/product/platform!6927
  • Loading branch information
taltholtmann committed Dec 15, 2021
2 parents de7d7ec + 6912384 commit e6ef84c
Show file tree
Hide file tree
Showing 20 changed files with 1,071 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Add an affiliate and campaign code action
issue: NEXT-18082
flag: FEATURE_NEXT_17973
---
# Core
* Added `Shopware/Core/Content/Flow/Dispatching/Action/AddCustomerAffiliateAndCampaignCodeAction` class to handle add affiliate and campaign code to Customer action.
* Added `Shopware/Core/Content/Flow/Dispatching/Action/AddOrderAffiliateAndCampaignCodeAction` class to handle add affiliate and campaign code to Order action.
___
# Administration
* Added component `sw-flow-affiliate-and-campaign-code-modal` to show a modal that allows adding affiliate and campaign code for customer/order.
* Added `getAffiliateAndCampaignCodeDescription` function at `src/module/sw-flow/component/sw-flow-sequence-action/index.js` to get affiliate and campaign code description.
* Added `ADD_CUSTOMER_AFFILIATE_AND_CAMPAIGN_CODE` and `ADD_ORDER_AFFILIATE_AND_CAMPAIGN_CODE` into action list at `src/module/sw-flow/constant/flow.constant.js`.
* Added adding affiliate and campaign code action icon and title at `src/module/sw-flow/service/flow-builder.service.js`.
* Added `convertEntityName` function at `src/module/sw-flow/service/flow-builder.service.js`.
* Deprecated `convertEntityName` function at `src/module/sw-flow/component/modals/sw-flow-tag-modal/index.js` and `src/module/sw-flow/component/modals/sw-flow-set-entity-custom-field-modal/index.js`.
* Added watcher `entity` at `src/module/sw-flow/component/modals/sw-flow-set-entity-custom-field-modal/index.js`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import template from './sw-flow-affiliate-and-campaign-code-modal.html.twig';

const { Component, Mixin, Service } = Shopware;
const { ShopwareError } = Shopware.Classes;
const { mapState } = Component.getComponentHelper();

Component.register('sw-flow-affiliate-and-campaign-code-modal', {
template,

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

props: {
sequence: {
type: Object,
required: true,
},
},

data() {
return {
entityError: null,
entity: null,
affiliateCode: {
value: null,
upsert: false,
},
campaignCode: {
value: null,
upsert: false,
},
};
},

computed: {
entityOptions() {
const options = [];
if (!this.triggerEvent) {
return [];
}

Object.entries(this.triggerEvent.data).forEach(([key, value]) => {
if (value.type !== 'entity') {
return;
}

options.push({
label: Service('flowBuilderService').convertEntityName(key),
value: key,
});
});

return options;
},

...mapState('swFlowState', ['triggerEvent']),
},

watch: {
entity(value) {
if (value && this.entityError) {
this.entityError = null;
}
},
},

created() {
this.createdComponent();
},

methods: {
createdComponent() {
if (this.entityOptions.length) {
this.entity = this.entityOptions[0].value;
}

if (!this.sequence.config) {
return;
}

this.entity = this.sequence.config.entity;
this.affiliateCode = { ...this.sequence.config.affiliateCode };
this.campaignCode = { ...this.sequence.config.campaignCode };
},

fieldError(field) {
if (!field || !field.length) {
return new ShopwareError({
code: 'c1051bb4-d103-4f74-8988-acbcafc7fdc3',
});
}

return null;
},

onSave() {
this.entityError = this.fieldError(this.entity);
if (this.entityError) {
return;
}

const config = {
entity: this.entity,
affiliateCode: this.affiliateCode,
campaignCode: this.campaignCode,
};

const sequence = {
...this.sequence,
config,
};

this.$emit('process-finish', sequence);
this.onClose();
},

onClose() {
this.$emit('modal-close');
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{% block sw_flow_affiliate_and_campaign_code_modal %}
<sw-modal
class="sw-flow-affiliate-and-campaign-code-modal"
:title="$tc('sw-flow.modals.affiliateAndCampaignCode.title')"
@modal-close="onClose"
>
{% block sw_flow_affiliate_and_campaign_code_modal_content %}
<div class="sw-flow-affiliate-and-campaign-code-modal__content">
{% block sw_flow_affiliate_and_campaign_code_modal_entity %}
<sw-single-select
v-model="entity"
class="sw-flow-affiliate-and-campaign-code-modal__entity"
required
show-clearable-button
:label="$tc('sw-flow.modals.affiliateAndCampaignCode.labelEntity')"
:placeholder="$tc('sw-flow.modals.affiliateAndCampaignCode.placeholderEntity')"
:error="entityError"
:options="entityOptions"
/>
{% endblock %}

<sw-container
columns="4fr 1fr"
gap="30px"
>
{% block sw_flow_affiliate_and_campaign_code_modal_affiliate_code %}
<sw-text-field
v-model="affiliateCode.value"
class="sw-flow-affiliate-and-campaign-code-modal__affiliate-code"
:label="$tc('sw-flow.modals.affiliateAndCampaignCode.labelAffiliateCode')"
:placeholder="$tc('sw-flow.modals.affiliateAndCampaignCode.placeholderAffiliateCode')"
/>
{% endblock %}

{% block sw_flow_affiliate_and_campaign_code_modal_affiliate_code_overwrite %}
<sw-switch-field
v-model="affiliateCode.upsert"
class="sw-flow-affiliate-and-campaign-code-modal__affiliate-code-overwrite"
:label="$tc('sw-flow.modals.affiliateAndCampaignCode.overwrite')"
/>
{% endblock %}
</sw-container>

<sw-container
columns="4fr 1fr"
gap="30px"
>
{% block sw_flow_affiliate_and_campaign_code_modal_campaign_code %}
<sw-text-field
v-model="campaignCode.value"
class="sw-flow-affiliate-and-campaign-code-modal__campaign-code"
:label="$tc('sw-flow.modals.affiliateAndCampaignCode.labelCampaignCode')"
:placeholder="$tc('sw-flow.modals.affiliateAndCampaignCode.placeholderCampaignCode')"
/>
{% endblock %}

{% block sw_flow_affiliate_and_campaign_code_modal_campaign_code_overwrite %}
<sw-switch-field
v-model="campaignCode.upsert"
class="sw-flow-affiliate-and-campaign-code-modal__campaign-code-overwrite"
:label="$tc('sw-flow.modals.affiliateAndCampaignCode.overwrite')"
/>
{% endblock %}
</sw-container>
</div>
{% endblock %}

<template #modal-footer>
{% block sw_flow_affiliate_and_campaign_code_modal_footer_cancel_button %}
<sw-button
class="sw-flow-affiliate-and-campaign-code-modal__cancel-button"
size="small"
@click="onClose"
>
{{ $tc('global.default.cancel') }}
</sw-button>
{% endblock %}

{% block sw_flow_affiliate_and_campaign_code_modal_footer_save_button %}
<sw-button
class="sw-flow-affiliate-and-campaign-code-modal__save-button"
variant="primary"
size="small"
@click="onSave"
>
{{ sequence.id ? $tc('sw-flow.modals.buttonSaveAction') : $tc('sw-flow.modals.buttonAddAction') }}
</sw-button>
{% endblock %}
</template>
</sw-modal>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import template from './sw-flow-set-entity-custom-field-modal.html.twig';
import './sw-flow-set-entity-custom-field-modal.scss';

const { Component, Mixin } = Shopware;
const { Component, Mixin, Service } = Shopware;
const { Criteria } = Shopware.Data;
const { mapState } = Component.getComponentHelper();
const { ShopwareError } = Shopware.Classes;
Expand Down Expand Up @@ -113,6 +113,12 @@ Component.register('sw-flow-set-entity-custom-field-modal', {
},

watch: {
entity(value) {
if (value && this.entityError) {
this.entityError = null;
}
},

renderedFieldConfig(value) {
if (value.customFieldType === 'colorpicker' && !this.renderedFieldConfig.zIndex) {
this.renderedFieldConfig = {
Expand Down Expand Up @@ -274,7 +280,7 @@ Component.register('sw-flow-set-entity-custom-field-modal', {
}

options.push({
label: this.convertEntityName(key),
label: Service('flowBuilderService').convertEntityName(key),
value: key,
});
});
Expand All @@ -286,6 +292,9 @@ Component.register('sw-flow-set-entity-custom-field-modal', {
this.entityOptions = options;
},

/**
* @major-deprecated tag:v6.5.0 - will be removed, use convertEntityName method of flowBuilderService instead
*/
convertEntityName(camelCaseText) {
if (!camelCaseText) return '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Component.register('sw-flow-tag-modal', {
}

options.push({
label: this.convertEntityName(key),
label: this.flowBuilderService.convertEntityName(key),
value: key,
});
});
Expand Down Expand Up @@ -192,6 +192,9 @@ Component.register('sw-flow-tag-modal', {
this.$emit('modal-close');
},

/**
* @major-deprecated tag:v6.5.0 - will be removed, use convertEntityName method of flowBuilderService instead
*/
convertEntityName(camelCaseText) {
if (!camelCaseText) return '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ Component.register('sw-flow-sequence-action', {
// eslint-disable-next-line max-len
actionDescription[ACTION.SET_CUSTOMER_GROUP_CUSTOM_FIELD] = (config) => this.getCustomFieldDescription(config);
actionDescription[ACTION.SET_ORDER_CUSTOM_FIELD] = (config) => this.getCustomFieldDescription(config);
actionDescription[ACTION.ADD_CUSTOMER_AFFILIATE_AND_CAMPAIGN_CODE] =
(config) => this.getAffiliateAndCampaignCodeDescription(config);
actionDescription[ACTION.ADD_ORDER_AFFILIATE_AND_CAMPAIGN_CODE] =
(config) => this.getAffiliateAndCampaignCodeDescription(config);
}

return actionDescription;
Expand Down Expand Up @@ -452,5 +456,25 @@ Component.register('sw-flow-sequence-action', {
customFieldOption: config.optionLabel,
})}`;
},

getAffiliateAndCampaignCodeDescription(config) {
let description = this.$tc('sw-flow.actions.labelTo', 0, {
entity: config.entity,
});

if (config.affiliateCode.upsert || config.affiliateCode.value != null) {
description = `${description}<br>${this.$tc('sw-flow.actions.labelAffiliateCode', 0, {
affiliateCode: config.affiliateCode.value ? config.affiliateCode.value : 'null',
})}`;
}

if (config.campaignCode.upsert || config.campaignCode.value != null) {
description = `${description}<br>${this.$tc('sw-flow.actions.labelCampaignCode', 0, {
campaignCode: config.campaignCode.value ? config.campaignCode.value : 'null',
})}`;
}

return description;
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const ACTION = Object.freeze({
SET_CUSTOMER_GROUP_CUSTOM_FIELD: 'action.set.customer.group.custom.field',
CHANGE_CUSTOMER_GROUP: 'action.change.customer.group',
CHANGE_CUSTOMER_STATUS: 'action.change.customer.status',
ADD_CUSTOMER_AFFILIATE_AND_CAMPAIGN_CODE: 'action.add.customer.affiliate.and.campaign.code',
ADD_ORDER_AFFILIATE_AND_CAMPAIGN_CODE: 'action.add.order.affiliate.and.campaign.code',
});

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import './component/modals/sw-flow-event-change-confirm-modal';
import './component/modals/sw-flow-change-customer-group-modal';
import './component/modals/sw-flow-change-customer-status-modal';
import './component/modals/sw-flow-set-entity-custom-field-modal';
import './component/modals/sw-flow-affiliate-and-campaign-code-modal';

import './service/flow-builder.service';
import './acl';
Expand Down
Loading

0 comments on commit e6ef84c

Please sign in to comment.