Completed
Pull Request — master (#447)
by Sebastian
05:19
created

port.Formꞌ).createLeftDropShippingElements   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
1
/**
2
 * Shopware 4
3
 * Copyright © shopware AG
4
 *
5
 * According to our dual licensing model, this program can be used either
6
 * under the terms of the GNU Affero General Public License, version 3,
7
 * or under a proprietary license.
8
 *
9
 * The texts of the GNU Affero General Public License with an additional
10
 * permission and of our proprietary license can be found at and
11
 * in the LICENSE file you have received along with this program.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * "Shopware" is a registered trademark of shopware AG.
19
 * The licensing of the program under the AGPLv3 does not imply a
20
 * trademark license. Therefore any rights, title and interest in
21
 * our trademarks remain entirely with us.
22
 */
23
/**
24
 * Shopware SwagConnect Plugin
25
 *
26
 * @category Shopware
27
 * @package Shopware\Plugins\SwagConnect
28
 * @copyright Copyright (c) shopware AG (http://www.shopware.de)
29
 */
30
//{namespace name=backend/connect/view/main}
31
//{block name="backend/connect/view/config/import/form"}
32
Ext.define('Shopware.apps.Connect.view.config.import.Form', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
33
    extend: 'Ext.form.Panel',
34
    alias: 'widget.connect-config-import-form',
35
36
    border: false,
37
    layout: 'anchor',
38
    autoScroll: true,
39
    region: 'center',
40
    bodyPadding: 10,
41
42
    /**
43
     * Contains the field set defaults.
44
     */
45
    defaults: {
46
        labelWidth: 170,
47
        importSettingsLabelWidth: 190,
48
        anchor: '100%'
49
    },
50
51
    snippets: {
52
        save: '{s name=config/save}Save{/s}',
53
        cancel: '{s name=config/cancel}Cancel{/s}',
54
        importSettingsHeader: '{s name=config/import_settings_header}Import Einstellungen{/s}',
55
        createCategoriesAutomatically: '{s name=config/import/categories/create_automatically}Kategorien automatisch anlegen{/s}',
56
        activateProductsAutomatically: '{s name=config/import/products/activate_automatically}Produkte automatisch aktivieren{/s}',
57
        createUnitsAutomatically: '{s name=config/import/units/create_automatically}Einheiten automatisch anlegen{/s}',
58
        importPicturesLabel: '{s name=config/import/pictures_label}Load product images during first import{/s}',
59
        importPicturesHelp: '{s name=config/import/pictures_help}The import of images can slow down the import. If you want to import many products, you should not activate and import the pictures on the CronJob.{/s}',
60
        overwritePropertiesLabel: '{s name=config/import/overwrite_properties}Overwrite the following properties during import{/s}',
61
        overwritePropertiesHelp: '{s name=config/import/overwrite_properties_help}The fields selected here will automatically be overwritten when the source changes this store. You can define item-level exceptions.{/s}',
62
        overwriteProductName: '{s name=config/import/overwrite_product_name}Product name{/s}',
63
        overwriteProductPrice: '{s name=config/import/overwrite_product_price}Price{/s}',
64
        overwriteProductImages: '{s name=config/import/overwrite_product_images}Image{/s}',
65
        overwriteProductMainImage: '{s name=config/import/overwrite_product_main_image}Main image{/s}',
66
        overwriteProductShortDescription: '{s name=config/import/overwrite_product_short_description}Short description{/s}',
67
        overwriteProductLongDescription: '{s name=config/import/overwrite_product_long_description}Long description{/s}',
68
        overwriteProductAdditionalDescription: '{s name=config/import/overwrite_product_additional_description}Connect description{/s}',
69
        articleImagesLimitImportLabel: '{s name=config/import/pictures_limit_label}Number of products per image import pass{/s}',
70
        productImportSettingsTitle: '{s name=config/import/product_import_settings_title}Product{/s}',
71
        productImportImageSettingsTitle: '{s name=config/import/image_settings_title}Product images{/s}',
72
        overwritePropertiesHelptext: '{s name=config/import/overwrite_properties_helptext}Gebe an, welche Felder überschrieben werden sollen, wenn dein Lieferant sie ändert. Diese Einstellung kannst du auch pro Artikel treffen. Gehe dafür direkt in den Artikel und dann auf den Tab Connect.{/s}',
73
        updateOrderStatusDescription: '{s name=config/import/update_order_status_description}You can import the order status from orders with Connect-Products. This can override previously set status.{/s}',
74
        updateOrderStatusLabel: '{s name=config/import/update_order_status_label}Import Orderstatus:{/s}',
75
        updateOrderStatusHelpText: '{s name=config/import/update_order_status_help_text}The order status will be set to \"completly delivered\" if all Connect-Products are delivered. If some but not all Connect-Products are delivered the order status will be set to \"partially delivered\". In this cases the old order status will be overwritten.{/s}',
76
        updateOrderStatusTitle: '{s name=config/import/update_order_status_title}Order status{/s}',
77
        dropShippingHeader: '{s name=config/main/dropshipping}Dropshipping{/s}',
78
        detailPageHintLabel: '{s name=config/detail_page_dropshipping_hint}Zeige Dropshipping-Hinweis auf Artikel-Detailseite{/s}',
79
        separateShippingLabel: '{s name=config/separate_shipping_label}Versandkosten als separate Position im Warenkorb ausgeben{/s}',
80
        basketHintLabel: '{s name=config/basket_dropshipping_hint_label}Zeige Dropshipping-Hinweis im Warenkorb{/s}',
81
        showDropshippingHintBasketHelptext: '{s name=config/show_dropshipping_hint_basket_helptext}Ein Dropshipping-Hinweis und der Lieferantenname werden angezeigt{/s}',
82
        showDropshippingHintDetailsHelptext: '{s name=config/show_dropshipping_hint_details_helptext}Ein Dropshipping-Hinweis und der Lieferantenname werden angezeigt{/s}'
83
    },
84
85
    initComponent: function() {
86
        var me = this;
87
88
        me.items = me.createElements();
89
        me.dockedItems = [{
90
            xtype: 'toolbar',
91
            dock: 'bottom',
92
            ui: 'shopware-ui',
93
            cls: 'shopware-toolbar',
94
            items: me.getFormButtons()
95
        }];
96
97
        me.importConfigStore = Ext.create('Shopware.apps.Connect.store.config.Import').load({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
98
            callback: function() {
99
                me.populateForm();
100
            }
101
        });
102
103
        me.callParent(arguments);
104
    },
105
106
    /**
107
     * Returns form buttons, save and cancel
108
     * @returns Array
109
     */
110
    getFormButtons: function() {
111
        var me = this,
112
            buttons = ['->'];
113
114
        var saveButton = Ext.create('Ext.button.Button', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
115
            text: me.snippets.save,
116
            action:'save-import-config',
117
            cls:'primary'
118
        });
119
120
        var cancelButton = Ext.create('Ext.button.Button', {
121
            text: me.snippets.cancel,
122
            handler: function(btn) {
123
                btn.up('window').close();
124
            }
125
        });
126
127
        buttons.push(cancelButton);
128
        buttons.push(saveButton);
129
130
        return buttons;
131
    },
132
133
    /**
134
     * Creates the field set items
135
     * @return Array
136
     */
137
    createElements: function () {
138
        var me = this;
139
140
        var categoriesStore = Ext.create('Shopware.apps.Base.store.CategoryTree');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
141
        categoriesStore.load();
142
143
        var numStore = Ext.create('Ext.data.Store', {
144
            fields: ['value'],
145
            data : [
146
                { value: 5 },
147
                { value: 25 },
148
                { value: 50 },
149
                { value: 100 },
150
                { value: 150 }
151
            ]
152
        });
153
154
        me.imageLimitImportField = Ext.create('Ext.form.field.ComboBox', {
155
            name: 'articleImagesLimitImport',
156
            fieldLabel: me.snippets.articleImagesLimitImportLabel,
157
            labelWidth: me.defaults.labelWidth,
158
            editable: false,
159
            valueField: 'value',
160
            displayField: 'value',
161
            width: 250,
162
            store: numStore
163
        });
164
        var elements = [];
165
        if (window.defaultMarketplace == false && typeof(window.defaultMarketplace) !== 'undefined') {
166
            // extended import settings are available
167
            // only for SEM shops
168
            elements.push(me.getImportSettingsFieldset());
169
        }
170
171
        var productContainer = Ext.create('Ext.form.FieldSet', {
172
            flex: 1,
173
            title: me.snippets.productImportSettingsTitle,
174
            layout: 'vbox',
175
            items: [
176
                {
177
                    xtype: 'container',
178
                    margin: '0 0 20 0',
179
                    width: 600,
180
                    html: '<p>' + me.snippets.overwritePropertiesHelptext + '</p>'
181
                },
182
                {
183
                    xtype      : 'fieldcontainer',
184
                    fieldLabel : me.snippets.overwritePropertiesLabel,
185
                    defaultType: 'checkboxfield',
186
                    labelWidth: me.defaults.labelWidth,
187
                    items: [
188
                        {
189
                            boxLabel  : me.snippets.overwriteProductName,
190
                            name      : 'overwriteProductName',
191
                            inputValue: 1,
192
                            helpText: me.snippets.overwritePropertiesHelp,
193
                            uncheckedValue: 0
194
                        }, {
195
                            boxLabel  : me.snippets.overwriteProductPrice,
196
                            name      : 'overwriteProductPrice',
197
                            inputValue: 1,
198
                            uncheckedValue: 0
199
                        }, {
200
                            boxLabel  : me.snippets.overwriteProductImages,
201
                            name      : 'overwriteProductImage',
202
                            inputValue: 1,
203
                            uncheckedValue: 0
204
                        }, {
205
                            boxLabel  : me.snippets.overwriteProductMainImage,
206
                            name      : 'overwriteProductMainImage',
207
                            inputValue: 1,
208
                            uncheckedValue: 0
209
                        }, {
210
                            boxLabel  : me.snippets.overwriteProductShortDescription,
211
                            name      : 'overwriteProductShortDescription',
212
                            inputValue: 1,
213
                            uncheckedValue: 0
214
                        }, {
215
                            boxLabel  : me.snippets.overwriteProductLongDescription,
216
                            name      : 'overwriteProductLongDescription',
217
                            inputValue: 1,
218
                            uncheckedValue: 0
219
                        }, {
220
                            boxLabel  : me.snippets.overwriteProductAdditionalDescription,
221
                            name      : 'overwriteProductAdditionalDescription',
222
                            inputValue: 1,
223
                            uncheckedValue: 0
224
                        }
225
                    ]
226
                }
227
            ]
228
        });
229
230
        var imageContainer = Ext.create('Ext.form.FieldSet', {
231
            flex: 1,
232
            title: me.snippets.productImportImageSettingsTitle,
233
            layout: 'vbox',
234
            items: [
235
                {
236
                    xtype: 'container',
237
                    margin: '0 0 20 0',
238
                    width: 600,
239
                    html: '<p>' + me.snippets.importPicturesHelp + '</p>'
240
                },
241
                {
242
                    xtype      : 'fieldcontainer',
243
                    defaultType: 'checkboxfield',
244
                    labelWidth: me.defaults.labelWidth,
245
                    items: [
246
                        {
247
                            xtype: 'checkbox',
248
                            name: 'importImagesOnFirstImport',
249
                            fieldLabel: me.snippets.importPicturesLabel,
250
                            inputValue: 1,
251
                            uncheckedValue: 0,
252
                            labelWidth: me.defaults.labelWidth,
253
                            listeners:{
254
                                change: function(checkbox, newValue, oldValue, opts){
0 ignored issues
show
Unused Code introduced by
The parameter newValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter oldValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
255
                                    if (checkbox.getValue() === false) {
256
                                        Ext.Ajax.request({
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
257
                                            url: '{url controller=ConnectConfig action=checkCronPlugin}',
258
                                            method: 'GET',
259
                                            success: function (response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
260
                                                var data = Ext.JSON.decode(response.responseText);
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
261
                                                if (data.cronActivated !== true) {
262
                                                    checkbox.setValue(true);
263
                                                    Shopware.Notification.createGrowlMessage(
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
264
                                                        '{s name=connect/error}Error{/s}',
265
                                                        '{s name=connect/config/error/cron_not_activated}To deactivate this Setting you have to activate the Cron-Plugin{/s}'
266
                                                    );
267
                                                }
268
                                            },
269
                                            failure: function (response, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter response is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
270
                                                checkbox.setValue(true);
271
                                                Shopware.Notification.createGrowlMessage(
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
272
                                                    '{s name=connect/error}Error{/s}'
273
                                                );
274
                                            }
275
                                        });
276
                                    }
277
278
                                    me.enableImageImportLimit(checkbox);
279
                                },
280
                                beforeRender: function(checkbox, opts) {
0 ignored issues
show
Unused Code introduced by
The parameter opts is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
281
                                    me.enableImageImportLimit(checkbox);
282
                                }
283
                            }
284
                        }, me.imageLimitImportField
285
                    ]
286
                }
287
            ]
288
        });
289
290
        var orderContainer = Ext.create('Ext.form.FieldSet', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
291
            flex: 1,
292
            title: me.snippets.updateOrderStatusTitle,
293
            layout: 'vbox',
294
            items: [
295
                {
296
                    xtype: 'container',
297
                    margin: '0 0 20 0',
298
                    width: 600,
299
                    html: '<p>' + me.snippets.updateOrderStatusDescription + '</p>'
300
                },
301
                {
302
                    xtype      : 'fieldcontainer',
303
                    defaultType: 'checkboxfield',
304
                    labelWidth: me.defaults.labelWidth,
305
                    items: [
306
                        {
307
                            name: 'updateOrderStatus',
308
                            fieldLabel: me.snippets.updateOrderStatusLabel,
309
                            helpText: me.snippets.updateOrderStatusHelpText,
310
                            inputValue: 1,
311
                            uncheckedValue: 0
312
                        }
313
                    ]
314
                }
315
            ]
316
        });
317
318
        elements.push(productContainer, imageContainer, orderContainer, me.getDropShippingConfigFieldset());
319
320
        return elements;
321
    },
322
323
    /**
324
     * Returns Import settings field set
325
     *
326
     * @return Ext.form.FieldSet
327
     */
328
    getImportSettingsFieldset: function () {
329
        var me = this;
330
331
        var leftElements = Ext.create('Ext.container.Container', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
332
                columnWidth: 0.5,
333
                padding: '0 20 0 0',
334
                layout: 'anchor',
335
                border: false,
336
                items: [
337
                    {
338
                        xtype: 'checkbox',
339
                        name: 'createCategoriesAutomatically',
340
                        fieldLabel: me.snippets.createCategoriesAutomatically,
341
                        inputValue: 1,
342
                        uncheckedValue: 0,
343
                        labelWidth: me.defaults.importSettingsLabelWidth
344
                    }, {
345
                        xtype: 'checkbox',
346
                        name: 'activateProductsAutomatically',
347
                        fieldLabel: me.snippets.activateProductsAutomatically,
348
                        inputValue: 1,
349
                        uncheckedValue: 0,
350
                        labelWidth: me.defaults.importSettingsLabelWidth
351
                    }, {
352
                        xtype: 'checkbox',
353
                        name: 'createUnitsAutomatically',
354
                        fieldLabel: me.snippets.createUnitsAutomatically,
355
                        inputValue: 1,
356
                        uncheckedValue: 0,
357
                        labelWidth: me.defaults.importSettingsLabelWidth
358
                    }
359
                ]
360
            });
361
362
363
        return Ext.create('Ext.form.FieldSet', {
364
            layout: 'column',
365
            title: me.snippets.importSettingsHeader,
366
            defaultType: 'checkbox',
367
            defaults: me.defaults,
368
            items: [
369
                leftElements
370
            ]
371
        });
372
    },
373
374
    /**
375
     * Populate import config form
376
     */
377
    populateForm: function() {
378
        var me = this,
379
            record = me.importConfigStore.getAt(0);
380
381
        if (!record) {
382
            record = Ext.create('Shopware.apps.Connect.model.config.Import');
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
383
        }
384
        me.loadRecord(record);
385
    },
386
387
    /**
388
     * Enable / disable number of products which are proceed
389
     * by images cron at the same time.
390
     * It depends on import images on first import of products
391
     *
392
     * @param checkbox
393
     */
394
    enableImageImportLimit: function(checkbox) {
395
        var me = this;
396
397
        me.imageLimitImportField.setDisabled(checkbox.getValue());
398
    },
399
400
    /**
401
     * Creates dropshipping configuration field set
402
     * @return Ext.form.FieldSet
403
     */
404
    getDropShippingConfigFieldset: function () {
405
        var me = this,
406
            items = [],
407
            leftElements = me.createLeftDropShippingElements(),
408
            rightElements = me.createRightDropShippingElements();
409
410
        items.push(leftElements, rightElements);
411
412
        return Ext.create('Ext.form.FieldSet', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
413
            layout: 'column',
414
            title: me.snippets.dropShippingHeader,
415
            defaults: {
416
                labelWidth: 170,
417
                anchor: '100%'
418
            },
419
            items: items
420
        });
421
    },
422
423
    /**
424
     * Creates the field set items which are displayed in the left column of the drop shipping container
425
     * @return Ext.container.Container
426
     */
427
    createLeftDropShippingElements: function () {
428
        var me = this;
429
430
        return Ext.create('Ext.container.Container', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
431
            columnWidth: 0.5,
432
            padding: '0 20 0 0',
433
            layout: 'anchor',
434
            border: false,
435
            items: [
436
                {
437
                    xtype: 'checkbox',
438
                    name: 'detailShopInfo',
439
                    fieldLabel: me.snippets.detailPageHintLabel,
440
                    inputValue: 1,
441
                    uncheckedValue: 0,
442
                    labelWidth: me.defaults.labelWidth,
443
                    helpText: me.snippets.showDropshippingHintDetailsHelptext
444
                }, {
445
                    xtype: 'checkbox',
446
                    name: 'showShippingCostsSeparately',
447
                    fieldLabel: me.snippets.separateShippingLabel,
448
                    labelWidth: me.defaults.labelWidth,
449
                    inputValue: 1,
450
                    hidden : true,
451
                    uncheckedValue: 0
452
                }
453
            ]
454
        });
455
    },
456
457
    /**
458
     * Creates the field set items which are displayed in the right column of the drop shipping container
459
     * @return Ext.container.Container
460
     */
461
    createRightDropShippingElements: function () {
462
        var me = this;
463
464
        return Ext.create('Ext.container.Container', {
0 ignored issues
show
Bug introduced by
The variable Ext seems to be never declared. If this is a global, consider adding a /** global: Ext */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
465
            columnWidth: 0.5,
466
            layout: 'anchor',
467
            border: false,
468
            items: [
469
                {
470
                    xtype: 'checkbox',
471
                    name: 'checkoutShopInfo',
472
                    fieldLabel: me.snippets.basketHintLabel,
473
                    inputValue: 1,
474
                    uncheckedValue: 0,
475
                    labelWidth: me.defaults.labelWidth,
476
                    helpText: me.snippets.showDropshippingHintBasketHelptext
477
                }
478
            ]
479
        });
480
    }
481
});
482
//{/block}
483
484