PluginProbe
MailerLite – WooCommerce integration / 3.1.21
MailerLite – WooCommerce integration v3.1.21
3.1.27 3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 All 148 releases
woo-mailerlite / admin / assets / js / components / Views / Settings.js

Settings.js in MailerLite – WooCommerce integration 3.1.21, at admin/assets/js/components/Views/Settings.js

520 lines 26.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import CustomSelect from '../Forms/CustomSelect.js';
2 import SyncFields from '../Forms/SyncFields.js';
3 import eventBus from '../eventBus.js';
4 import ApiMixin from '../Api/ApiMixin.js';
5 import {loadStart, loadEnd} from "../Plugins/Loader.js";
6
7 const template = `
8 <div v-if="syncInProgress || asyncSyncInProgress" class="woo-ml-sync-loading-container" data-testid="sync-in-progress">
9 <strong>Sync in progress...</strong>
10 <p>This will continue as long as you stay on this page.
11 You can always come back, and it will start again.</p>
12 <div class="woo-ml-sync-progress-bar"></div>
13 </div>
14 <form method="post" id="updateSettingsForm">
15 <div class="settings-block">
16 <div class="settings-block-fixed">
17
18 <h2 class="settings-block-header">Synchronization settings</h2>
19 <div class="form-group-ml vertical">
20 <label for="wooMlSubGroup" class="settings-label mb-3-ml">Subscriber group</label>
21 <label class="input-mailerlite mb-2-ml" style="display: flex;">
22 <custom-select
23 id="wooMlSubGroup"
24 name="subscriber-group"
25 :options="groups"
26 v-model="selectedGroup"
27 modelValue="selectedGroup"
28 :selectedGroup="selectedGroup"
29 placeholder="Select group"
30 ></custom-select>
31 <button @click="createGroup" id="createGroupModal" type="button" class="btn-secondary-ml" style="margin-left: 0.5rem; white-space: nowrap;">Create group</button>
32 </label>
33 <label class="settings-label-small">Subscribers from WooCommerce will join this MailerLite
34 subscriber group. </label>
35 </div>
36
37 <div class="form-group-ml vertical">
38 <label for="wooMlSubGroup" class="settings-label flex-ml align-items-center-ml mb-3-ml">Ignore products list
39 <div class="tooltip-ml">
40 <span class="tooltiptext-ml">This field lists products that are configured to be ignored in MailerLite e-commerce automation. To add or remove a product from this list, go to the WordPress product list and click "Quick Edit" on the relevant item.</span>
41 </div>
42 </label>
43 <label v-if="ignoredProducts.length !== 0" class="input-mailerlite" style="cursor: default;">
44 <div multiple name="ignore_product_list"
45 style="min-height: 26px; padding-left: 8px; display: flex; flex-direction: row; overflow: hidden; flex-wrap: wrap; padding: 4px; padding-top: 0; border: 1px solid #d1d5db; border-radius: 0.25rem;">
46 <span v-for="(item, index) in ignoredProducts" :key="index" style="background-color: #e5e7eb; padding: 2px 5px; border-radius: 2px; font-size: 13px; margin-right: 4px; margin-top: 4px;">{{ item }}</span>
47 </div>
48 </label>
49 <a v-else :href="productsUrl">
50 <button type="button" class="btn btn-secondary-ml flex-start-ml">Go to your products</button>
51 </a>
52 </div>
53 <div class="form-group-ml vertical">
54 <label for="wooMlSubGroup" class="settings-label flex-ml align-items-center-ml mb-3-ml">Add language
55 field
56 <div class="tooltip-ml">
57 <span class="tooltiptext-ml">Collect subscriber languages in a hidden field stored in MailerLite.</span>
58 </div>
59 </label>
60 <div class="checkbox-text-ml">
61 <input type="checkbox"
62 class="woo-ml-form-checkbox" v-model="settings.languageField"
63 name="additional_sub_fields"
64 value="yes"
65 id="language_field_checkbox"
66 />
67 <label for="language_field_checkbox" class="settings-label-medium">Collect subscriber language data.</label>
68 </div>
69 </div>
70 <div class="form-group-ml vertical">
71 <label for="sync_fields" class="settings-label flex-ml align-items-center-ml mb-3-ml">
72 Synced fields
73 <div class="tooltip-ml">
74 <span class="tooltiptext-ml">Select which fields you would like to sync. Please note that Email and Name fields are mandatory.</span>
75 </div>
76 </label>
77 <label class="input-mailerlite" data-testid="settings-sync-fields">
78 <sync-fields
79 id="sync_fields"
80 multiple="multiple"
81 data-placeholder="Click to select fields you want to sync"
82 style="width: 100%;"
83 :options="syncFields"
84 v-model="selectedSyncFields"
85 />
86 </label>
87 </div>
88 <div class="form-group-ml vertical">
89 <label for="wooMlSubGroup" class="settings-label flex-ml align-items-center-ml mb-3-ml">Synchronize
90 store
91 <div class="tooltip-ml">
92 <span class="tooltiptext-ml">Synchronize categories, products and customer data that hasn't been submitted to MailerLite.</span>
93 </div>
94 </label>
95 <p v-if="!accountConnected" class="description">
96 Plugin not connected to MailerLite yet.
97 </p>
98 <button @click.prevent="resetSync" v-if="!totalUntrackedResources && !syncInProgress" type="button" class="btn btn-secondary-ml flex-start-ml"
99 data-woo-ml-reset-resources-sync="true" ref="resetSyncBtn"><span class="woo-ml-button-text">Reset synchronized resources</span>
100 </button>
101 <button @click.prevent="startSync" v-if="totalUntrackedResources && !syncInProgress" type="button" class="btn btn-secondary-ml flex-start-ml"
102 data-woo-ml-reset-resources-sync="true" ref="startSync" data-testid="sync-untracked-resources-btn"><span class="woo-ml-button-text">Synchronize {{ totalUntrackedResources }} untracked resources</span>
103 </button>
104 </div>
105 </div>
106 </div>
107
108 <div class="settings-block">
109 <div class="settings-block-fixed">
110 <h2 class="settings-block-header">Checkout settings</h2>
111 <div class="form-group-ml vertical">
112 <label for="wooMlSubGroup" class="settings-label mb-3-ml">Subscribe on checkout</label>
113 <div class="checkbox-text-ml">
114 <input type="checkbox"
115 class="woo-ml-form-checkbox" v-model="settings.subscribeOnCheckout"
116 name="checkout"
117 value="yes"
118 id="subscribe_checkout_checkbox"
119 data-testid="subscribe-checkout-checkbox"
120 />
121 <label for="subscribe_checkout_checkbox" class="settings-label-medium">Enable list subscription via checkout page.</label>
122 </div>
123 </div>
124 <div class="checkout-settings-group" :style="{ display: !settings.subscribeOnCheckout ? 'none' : 'block' }">
125 <div class="form-group-ml vertical">
126 <label for="wooMlSubGroup" class="settings-label mb-3-ml"> Resubscribe</label>
127 <div class="checkbox-text-ml">
128 <input type="checkbox"
129 class="woo-ml-form-checkbox" v-model="settings.resubscribe"
130 name="resubscribe"
131 value="yes"
132 id="resubscribe_checkbox"
133 />
134 <label for="resubscribe_checkbox" class="settings-label-medium"> Allow unsubscribers to rejoin the email list if they
135 resubscribe via the checkout page.</label>
136 </div>
137 </div>
138 <div class="form-group-ml vertical">
139 <label for="wooMlSubGroup" class="settings-label mb-3-ml">Subscribe checkbox position</label>
140 <label class="input-mailerlite">
141 <select
142 class="woo-ml-native-select"
143 name="checkout_position"
144 :disabled="!settings.subscribeOnCheckout"
145 v-model="settings.selectedCheckoutPosition"
146 >
147 <option
148 v-for="(checkoutPosition, key) in checkoutPositions"
149 :key="key"
150 :value="key"
151 >
152 {{ checkoutPosition }}
153 </option>
154 </select>
155 </label>
156 </div>
157 <div class="form-group-ml vertical">
158 <label for="wooMlSubGroup" class="settings-label mb-3-ml">Pre-select subscribe checkbox</label>
159 <div class="checkbox-text-ml">
160 <input type="checkbox"
161 class="woo-ml-form-checkbox" v-model="settings.checkoutPreselect"
162 name="checkout_preselect"
163 value="yes"
164 id="preselect_subscribe_checkbox"
165 :disabled="!settings.subscribeOnCheckout"
166 />
167 <label for="preselect_subscribe_checkbox" class="settings-label-medium">Pre-select the signup checkbox by default.</label>
168 </div>
169 </div>
170 <div class="form-group-ml vertical">
171 <label for="wooMlSubGroup" class="settings-label mb-3-ml">Hide subscribe checkbox</label>
172 <div class="checkbox-text-ml">
173 <input type="checkbox"
174 class="woo-ml-form-checkbox" v-model="settings.checkoutHidden"
175 name="checkout_hide"
176 value="yes"
177 id="hide_subscriber_checkbox"
178 :disabled="!settings.subscribeOnCheckout"
179 />
180 <label for="hide_subscriber_checkbox" class="settings-label-medium">Check to hide the checkbox. All customers will be
181 subscribed automatically.</label>
182 </div>
183 </div>
184 <div class="form-group-ml vertical">
185 <label for="wooMlSubGroup" class="settings-label mb-3-ml">Subscribe checkbox label</label>
186 <label class="input-mailerlite">
187 <input type="text"
188 class="woo-ml-form-checkbox text-input flex-start-ml mb-3-ml"
189 v-model="settings.checkoutLabel"
190 name="checkout_label"
191 placeholder="I.e. I want to receive your newsletter."
192 :disabled="!settings.subscribeOnCheckout"
193 />
194 </label>
195 <label class="settings-label-small">This text will be displayed next to the signup
196 checkbox. </label>
197 </div>
198 <div class="form-group-ml vertical">
199 <label for="wooMlSubGroup" class="settings-label flex-ml align-items-center-ml mb-3-ml">Add subscribers after checkout
200 <div class="tooltip-ml">
201 <span class="tooltiptext-ml">Only customers that have completed the checkout process will be added to your MailerLite account as subscribers. Enabling this option disables abandoned cart functionality.</span>
202 </div>
203 </label>
204 <div class="checkbox-text-ml">
205 <input type="checkbox"
206 class="woo-ml-form-checkbox" v-model="settings.syncAfterCheckout"
207 name="disable_checkout_sync"
208 value="yes"
209 id="synchronize_after_checkout_checkbox"
210 :disabled="!settings.subscribeOnCheckout"
211 />
212 <label for="synchronize_after_checkout_checkbox" class="settings-label-medium">Add subscribers to your MailerLite account after the checkout process has been completed.</label>
213 </div>
214 <div class="woo-ml-alert-warning-small" :style="{ display: !settings.subscribeOnCheckout ? 'flex' : 'none' }"> align-items: center;">
215 <svg width="12" height="12" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10,0 C15.5228475,0 20,4.4771525 20,10 C20,15.5228475 15.5228475,20 10,20 C4.4771525,20 0,15.5228475 0,10 C0,4.4771525 4.4771525,0 10,0 Z M10,2 C5.581722,2 2,5.581722 2,10 C2,14.418278 5.581722,18 10,18 C14.418278,18 18,14.418278 18,10 C18,5.581722 14.418278,2 10,2 Z M10,12 C10.5522847,12 11,12.4477153 11,13 C11,13.5522847 10.5522847,14 10,14 C9.44771525,14 9,13.5522847 9,13 C9,12.4477153 9.44771525,12 10,12 Z M10,5 C10.5522847,5 11,5.44771525 11,6 L11,10 C11,10.5522847 10.5522847,11 10,11 C9.44771525,11 9,10.5522847 9,10 L9,6 C9,5.44771525 9.44771525,5 10,5 Z" fill-rule="nonzero"></path></svg>
216 Enabling this option disables abandoned cart functionality.</div>
217 </div>
218 </div>
219 </div>
220 </div>
221
222 <div class="settings-block">
223 <div class="settings-block-fixed">
224 <h2 class="settings-block-header">General settings</h2>
225 <div class="form-group-ml vertical">
226 <label for="wooMlSubGroup" class="settings-label flex-ml align-items-center-ml mb-3-ml">Double opt-in
227 <div class="tooltip-ml">
228 <span class="tooltiptext-ml">Changing this setting will automatically update your double opt-in setting for your MailerLite account.</span>
229 </div>
230 </label>
231 <div class="checkbox-text-ml">
232 <input type="checkbox"
233 class="woo-ml-form-checkbox" v-model="settings.doubleOptIn"
234 name="double_optin"
235 value="yes"
236 id="double_optin_checkbox"
237 />
238 <label for="double_optin_checkbox" class="settings-label-medium">Check to enforce email confirmation before being added
239 to your list.</label>
240 </div>
241 </div>
242 <div class="form-group-ml vertical">
243 <label for="wooMlSubGroup" class="settings-label mb-3-ml"> MailerLite pop-ups</label>
244 <div class="checkbox-text-ml">
245 <input type="checkbox"
246 class="woo-ml-form-checkbox" v-model="settings.popUps"
247 name="popups"
248 value="yes"
249 id="mailerlite_popups_checkbox"
250 />
251 <label for="mailerlite_popups_checkbox" class="settings-label-medium">Enable MailerLite pop-up forms. <a href="https://www.mailerlite.com/features/popups" target="_blank">Learn more.</a></label>
252 </div>
253 </div>
254 <div class="form-group-ml vertical">
255 <label for="wooMlSubGroup" class="settings-label mb-3-ml">Auto updates</label>
256 <div class="checkbox-text-ml">
257 <input type="checkbox"
258 class="woo-ml-form-checkbox" v-model="settings.autoUpdatePlugin"
259 name="auto_update_plugin"
260 value="yes"
261 id="autoupdate_plugin_checkbox"
262 />
263 <label for="autoupdate_plugin_checkbox" class="settings-label-medium">Receive automatic plugin updates.</label>
264 </div>
265 </div>
266 </div>
267 </div>
268
269 <div style="display: flex; justify-content: flex-end; margin-top: 2rem;">
270 <button @click.prevent="updateSettings" :class="{ 'woo-ml-button-loading': isLoading }" :disabled="isLoading" type="submit" class="btn-primary-ml" style="margin-top: 2rem;" id="updateSettingsBtn" data-testid="update-settings-btn"><span class="woo-ml-button-text">Save changes</span></button>
271 </div>
272 <div class="settings-block">
273 <div class="woo-ml-wizard card-between">
274 <div class="flex-start-ml">
275 <h2 class="settings-block-header" style="margin-top:0; margin-bottom: 8px;">Debug logs</h2>
276 <label class="settings-label-medium">This is an advanced troubleshooting method which gives a deeper insight and helps our support team to identify problems.</label>
277 <div class="mt-6-ml">
278 <button type="button" @click.prevent="openDebugLog" ref="openDebugLog" class="btn-secondary-ml mr-2-ml"><span class="woo-ml-button-text">Open debug logs</span></button>
279 <button v-if="platform == 1" type="button" id="enableDebugMode" ref="enableDebugMode" @click.prevent="enableDebugMode" :class="debugMode ? 'btn-danger-ml' : 'btn-primary-ml'"><span class="woo-ml-button-text">{{debugMode ? 'Disable debug mode' : 'Enable debug mode'}}</span></button>
280 </div>
281 </div>
282
283
284 </div>
285 <div class="woo-ml-wizard card-between">
286 <div>
287 <h2 class="settings-block-header" style="margin-top:0; margin-bottom: 8px;">Reset integration</h2>
288 <label class="settings-label-medium">Once you click on the "Reset integration" button this action will reset
289 all integration configurations and the process can not be reverted.</label>
290 </div>
291 <button type="button" ref="resetIntegration" @click.prevent="resetIntegration" class="btn-danger-ml"><span class="woo-ml-button-text">Reset integration</span></button>
292 </div>
293 </div>
294 </form>
295 `;
296
297 const Settings = {
298 components: {
299 CustomSelect,
300 SyncFields
301 },
302 template,
303 mixins: [ApiMixin],
304 props: {
305 group: {
306 type: Object,
307 required: false
308 },
309 fields: {
310 type: Array,
311 required: false
312 },
313 },
314 data() {
315 return {
316 ignoredProducts: woo_mailerlite_admin_data.ignoredProducts,
317 productsUrl: woo_mailerlite_admin_data.productsUrl,
318 groups: [
319 {
320 value: 1,
321 text: 'Group 1'
322 },
323 {
324 value: 2,
325 text: 'Group 2'
326 },
327 {
328 value: 3,
329 text: 'Group 3'
330 },
331 ],
332 selectedGroup: woo_mailerlite_admin_data.selectedGroup ?? null,
333 syncFields: [
334 {
335 value: 'name',
336 text: 'Name',
337 default: true
338 },
339 {
340 value: 'email',
341 text: 'Email',
342 default: true
343 },
344 {
345 value: 'company',
346 text: 'Company'
347 },
348 {
349 value: 'city',
350 text: 'City'
351 },
352 {
353 value: 'zip',
354 text: 'ZIP'
355 },
356 {
357 value: 'state',
358 text: 'State'
359 },
360 {
361 value: 'country',
362 text: 'Country'
363 },
364 {
365 value: 'phone',
366 text: 'Phone'
367 },
368 ],
369 accountConnected: true,
370 totalTrackedResources: 0,
371 totalUntrackedResources: woo_mailerlite_admin_data.sync.totalUntrackedResources ?? 0,
372 syncInProgress: woo_mailerlite_admin_data.sync.syncInProgress,
373 lastCustomerSync: 1,
374 newMLSync: 0,
375 settings: {
376 languageField: false,
377 subscribeOnCheckout: false,
378 resubscribe: false,
379 selectedCheckoutPosition: woo_mailerlite_admin_data.selectedCheckoutPosition ?? 'checkout_billing',
380 checkoutPreselect: false,
381 checkoutHidden: false,
382 syncAfterCheckout: false,
383 checkoutLabel: 'Yes, I want to receive your newsletter.',
384 doubleOptIn: false,
385 popUps: false,
386 autoUpdatePlugin: false,
387 },
388 debugMode: woo_mailerlite_admin_data?.debugMode ?? false,
389 platform: woo_mailerlite_admin_data?.account?.platform === 'rewrite' ? 1 : 2,
390 checkoutPositions: {
391 'checkout_billing' :'After billing details',
392 'checkout_billing_email' : 'After billing email address',
393 'checkout_shipping' :'After shipping details',
394 'checkout_after_customer_details' :'After customer details',
395 'review_order_before_submit' : 'Before submit button',
396 },
397 isLoading: false,
398 selectedSyncFields: [],
399 asyncSyncInProgress: woo_mailerlite_admin_data.asyncSync,
400 }
401 },
402 mounted() {
403 eventBus.on('sync-completed', (sync) => {
404 this.syncInProgress = false
405 this.totalUntrackedResources = 0
406 });
407 eventBus.on('reset-completed', (untracked) => {
408 this.totalUntrackedResources = untracked
409 });
410
411 eventBus.on('reset-integration', (untracked) => {
412 this.resetPlugin()
413 });
414
415 },
416 created() {
417 if (woo_mailerlite_admin_data && woo_mailerlite_admin_data.settings) {
418 this.settings = {
419 ...this.settings,
420 ...woo_mailerlite_admin_data.settings,
421 };
422 }
423 const defaultValues = this.syncFields
424 .filter((opt) => opt.default)
425 .map((opt) => opt.value);
426 this.selectedSyncFields = [...new Set([...this.selectedSyncFields, ...defaultValues])];
427 this.selectedSyncFields = [...new Set([...this.selectedSyncFields, ...woo_mailerlite_admin_data.syncFields ?? []])];
428
429 if (this.fields) {
430 this.selectedSyncFields = [...new Set([...this.selectedSyncFields, ...this.fields])];
431 }
432 if (this.group) {
433 this.selectedGroup = this.group;
434 }
435 },
436 computed: {
437 syncMessage() {
438 const count = this.totalUntrackedResources;
439 return count === 1
440 ? `Synchronize ${count} untracked resource`
441 : `Synchronize ${count} untracked resources`;
442 },
443 syncFieldsComputed() {
444
445 return this.fields.length ? this.fields : (woo_mailerlite_admin_data.syncFields ?? []) ?? [];
446 },
447 },
448 methods: {
449 async updateSettings() {
450 this.isLoading = true
451
452 try {
453 this.settings.group = this.selectedGroup;
454 this.syncFields = this.selectedSyncFields;
455
456 this.settings.syncFields = this.syncFields
457 const data = await this.saveSettings(this.settings);
458
459 this.isLoading = false
460 if (data.success) {
461 eventBus.emit('alert-event', { success: data.message ?? "" });
462 } else {
463 eventBus.emit('alert-event', { error: data.message ?? "" });
464 }
465 } catch (err) {
466 this.isLoading = false
467 let error = 'An error occurred'
468 if (err.match('401 - Unauthorized')) {
469 error = 'Please reset the plugin and setup again!'
470 }
471 eventBus.emit('alert-event', { error: error });
472 }
473 },
474 async resetSync() {
475 loadStart(this.$refs.resetSyncBtn)
476 const resetData = await this.resetResources()
477 loadEnd(this.$refs.resetSyncBtn)
478 eventBus.emit('reset-completed', resetData.data?.totalUntrackedResources ?? 0 );
479 },
480 syncResources() {
481 this.syncResources()
482 },
483 openDebugLog() {
484 eventBus.emit('show-debug-modal', this.$refs.openDebugLog);
485 },
486 async resetIntegration() {
487 eventBus.emit('show-reset-modal', this.$refs.resetIntegration);
488 },
489 async resetPlugin() {
490 // reset-integration
491 loadStart(this.$refs.resetIntegration)
492 const response = await this.resetIntegrationSettings();
493 if (response.success) {
494 loadEnd(this.$refs.resetIntegration)
495 window.location.reload()
496 eventBus.emit('wizard-step-event', 0)
497 }
498 },
499 createGroup() {
500 eventBus.emit('show-create-group-modal', this.selectedGroup)
501 },
502 startSync() {
503 this.syncInProgress = true
504 eventBus.emit('start-sync')
505 },
506 async downgradePlugin() {
507 await this.downgrade()
508 },
509
510 async enableDebugMode() {
511 loadStart(this.$refs.enableDebugMode)
512 const response = await this.debugModeEnable()
513 this.debugMode = response
514 loadEnd(this.$refs.enableDebugMode)
515 }
516 }
517 };
518
519 export default Settings;
520