-
Notifications
You must be signed in to change notification settings - Fork 8
/
Bootstrap.php
2160 lines (1958 loc) · 79.4 KB
/
Bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/Components/Blisstribute/Domain/LoggerTrait.php';
require_once __DIR__ . '/Components/Blisstribute/Command/OrderExport.php';
require_once __DIR__ . '/Components/Blisstribute/Command/ArticleExport.php';
require_once __DIR__ . '/Components/Blisstribute/Article/Sync.php';
require_once __DIR__ . '/Components/Blisstribute/Order/Sync.php';
use \Shopware\CustomModels\Blisstribute\BlisstributeCoupon;
use \Shopware\CustomModels\Blisstribute\BlisstributeOrder;
use Doctrine\Common\Collections\ArrayCollection;
use Shopware\ExitBBlisstribute\Subscribers\ControllerSubscriber;
use Shopware\ExitBBlisstribute\Subscribers\ModelSubscriber;
use Shopware\ExitBBlisstribute\Subscribers\ServiceSubscriber;
use Shopware\Models\Shop\Shop;
/**
* exitb blisstribute plugin bootstrap
*
* @author Pixup Media GmbH
* @package Shopware\Plugins\Backend\ExitBBlisstribute
* @copyright Copyright (c) 2016
* @since 1.0.0
*/
class Shopware_Plugins_Backend_ExitBBlisstribute_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
use Shopware_Components_Blisstribute_Domain_LoggerTrait;
/**
* @return string
*
* @throws Exception
*/
public function getVersion()
{
$info = json_decode(file_get_contents(__DIR__ . '/plugin.json'), true);
if ($info) {
return $info['currentVersion'];
} else {
throw new Exception('The plugin has an invalid plugin definition file.');
}
}
/**
* @return string
*
* @throws Exception
*/
public function getLabel()
{
$info = json_decode(file_get_contents(__DIR__ . '/plugin.json'), true);
if ($info) {
return $info['label']['de'];
} else {
throw new Exception('The plugin has an invalid plugin definition file.');
}
}
/**
* @return string
*
* @throws Exception
*/
public function getSupplier()
{
$info = json_decode(file_get_contents(__DIR__ . '/plugin.json'), true);
if ($info) {
return $info['author'];
} else {
throw new Exception('The plugin has an invalid plugin definition file.');
}
}
/**
* @return string
*
* @throws Exception
*/
public function getDescription()
{
$info = file_get_contents(__DIR__ . '/info.txt');
if ($info) {
return $info;
} else {
throw new Exception('The plugin has an invalid plugin description file.');
}
}
/**
* @return string
*/
public function getSupport()
{
return '';
}
/**
* @return string
*
* @throws Exception
*/
public function getLink()
{
$info = json_decode(file_get_contents(__DIR__ . '/plugin.json'), true);
if ($info) {
return $info['link'];
} else {
throw new Exception('The plugin has an invalid plugin definition file.');
}
}
/**
* @return array
*/
public function getInfo()
{
return [
'version' => $this->getVersion(),
'label' => $this->getLabel(),
'author' => $this->getSupplier(),
'supplier' => $this->getSupplier(),
'description' => $this->getDescription(),
'support' => $this->getSupport(),
'link' => $this->getLink(),
];
}
/**
* {@inheritdoc}
*/
public function enable()
{
$this->logInfo('plugin enabled');
$this->subscribeEvents();
$result = $this->installDefaultTableValues();
$this->createAttributeCollection();
return $result;
}
/**
* {@inheritdoc}
*/
public function disable()
{
$this->logInfo('plugin disabled');
return $this->deleteDefaultTableValues();
}
/**
* @return array
*/
public function install()
{
// check the current sw version
if (!$this->assertMinimumVersion('5.2')) {
return [
'success' => false,
'message' => 'Das Plugin benötigt mindestens Shopware 5.2.'
];
}
// check needed plugins
if (!$this->assertRequiredPluginsPresent(['Cron'])) {
return [
'success' => false,
'message' => 'Bitte installieren und aktivieren Sie das Shopware Cron-Plugin.'
];
}
$this->logDebug('register cron jobs');
$this->registerCronJobs();
$this->logDebug('subscribe events');
$this->subscribeEvents();
$this->logDebug('creating menu items');
$this->createMenuItems();
$this->logDebug('install plugin scheme');
$this->installPluginSchema();
$this->logDebug('creating config');
$this->createConfig();
$this->logDebug('creating config translations');
$this->createConfigTranslations();
try {
$this->createAttributeCollection();
$this->createOrderStateCollection();
} catch (Exception $e) {
return [
'success' => false,
'message' => $e->getMessage()
];
}
return ['success' => true, 'invalidateCache' => ['backend', 'proxy', 'config']];
}
/**
* @inheritdoc
*/
public function update($version)
{
$this->createAttributeCollection();
$form = $this->Form();
if (version_compare($version, '0.10.3', '<')) {
$form->setElement(
'checkbox',
'blisstribute-article-sync-sync-last-stock',
[
'label' => 'Abverkauf synchronisieren',
'description' => 'Wenn aktiviert, wird das Abverkaufs-Flag (LastStock) am Artikel synchronisiert.',
'value' => 1
]
);
$form->setElement(
'checkbox',
'blisstribute-article-sync-sync-sale-price',
[
'label' => 'Werbemittelpreise synchronisieren',
'description' => 'Wenn aktiviert, werden übertragene Preise von Blisstribute synchronisiert.',
'value' => 1
]
);
}
if (version_compare($version, '0.11.2', '<')) {
$form->setElement(
'text',
'blisstribute-hold-order-address-pattern',
[
'label' => 'Sperrbegriffe für Adresse',
'description' => 'Wenn gesetzt, werden Bestellungen deren Adresse auf dieses Pattern zutrifft, mit Kommentar und angehalten übertragen.',
'value' => '',
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
}
if (version_compare($version, '0.11.4', '<')) {
$form->setElement(
'number',
'blisstribute-hold-order-cart-amount',
[
'label' => 'Warenwert für Bestell-Halt',
'description' => 'Wenn gesetzt, werden Bestellungen deren Warenwert den angegebenen Wertes überschreiten oder gleichen, mit Kommentar und angehalten übertragen. Zum deaktivieren "0" angeben.',
'value' => 0.00,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
}
if (version_compare($version, '0.12.7', '<')) {
$form->setElement(
'select',
'blisstribute-order-sync-external-customer-number',
[
'label' => 'Externe Kundennummer',
'description' => 'Definiert, welches Feld für die externe Kundennummer im VHS verwendet werden soll.',
'store' => [
[1, 'E-Mail'],
[2, 'Kundennummer']
],
'value' => 1
]
);
}
if (version_compare($version, '0.14.2', '<')) {
$form->setElement(
'checkbox',
'blisstribute-show-sync-widget',
[
'label' => 'Nicht synchr. Bestellungen Widget anzeigen',
'description' => 'Wenn aktiviert, wird auf der Backend-Startseite ein Widget angezeigt, welches die nicht synchronisierten Bestellungen auflistet.',
'value' => 1
]
);
}
if (version_compare($version, '0.14.7', '<')) {
$form->setElement(
'checkbox',
'blisstribute-transfer-b2b-net',
[
'label' => 'B2B-Bestellungen Netto übertragen',
'description' => 'Wenn aktiviert, werden B2B Bestellungen (Bestellzeilen) Netto an Blisstribute übertragen.',
'value' => 0
]
);
$form->setElement(
'checkbox',
'blisstribute-article-sync-manufacturer-article-number',
[
'label' => 'Hersteller-Art.Nr als Identifikation synchronisieren',
'description' => 'Wenn aktiviert, wird die Hersteller-Artikel-Nr als Produkt-Identifikation synchronisiert. Sollte nicht aktiviert werden, wenn Artikel mit Lieferanten synchronisiert werden.',
'value' => 0
]
);
}
if (version_compare($version, '0.14.19', '<')) {
$form->setElement(
'number',
'blisstribute-discount-difference-watermark',
[
'label' => 'Schwellwert für Hinweis auf Rabattabweichung',
'description' => 'Schwellwert für Hinweis auf Rabattabweichung in Euro',
'value' => 0.10
]
);
$form->setElement(
'text',
'blisstribute-error-email-receiver',
[
'label' => 'Empfänger Email für Fehlerhinweise',
'description' => 'Empfänger Email für Fehlerhinweise'
]
);
/*
* Email Template
* Name: sBLISSORDERREJECTED
* Parameter: {$orderNumber}
*/
}
if (version_compare($version, '0.15.0', '<')) {
$form->setElement(
'text',
'blisstribute-alternative-phone-number-order-attribute',
[
'label' => 'Alternative Kunden-Telefonnummer',
'description' => 'Order-Attribut (Freitextfeld) für Kunden-Telefonnummer'
]
);
}
if (version_compare($version, '0.15.3', '<')) {
$form->setElement(
'text',
'blisstribute-article-mapping-base-price',
array(
'label' => 'HAP Verknüpfung',
'description' => '',
'value' => ''
)
);
}
if (version_compare($version, '0.15.6', '<')) {
$form->setElement(
'text',
'blisstribute-disable-address-splitting',
[
'label' => 'Deaktiviert die automatische Adressanpassung',
'description' => 'Wenn aktiviert, werden Adressdaten nicht durch einen Validator verändert. ',
'maxLength' => 3,
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
}
if (version_compare($version, '0.16.1', '<')) {
$pluginConfig = Shopware()->Container()->get('plugins')->Backend()->ExitBBlisstribute()->Config();
// Migrate the SOAP Host to REST Host, if it's set.
$soapHostElement = $form->getElement('blisstribute-soap-host');
$soapHost = $pluginConfig->get('blisstribute-soap-host');
$restHost = '';
if (trim($soapHost) != '') {
$restHost = str_replace('soap', 'rest', $soapHost);
}
// Add REST Host.
$form->setElement(
'text',
'blisstribute-rest-host',
[
'label' => 'REST Host',
'description' => 'REST-Hostname für den Verbindungsaufbau zum Blisstribute-System',
'maxLength' => 255,
'value' => $restHost
]
);
// Change SOAP Host label to "SOAP Host" for clarity.
$soapHostElement->setLabel('SOAP Host');
}
if (version_compare($version, '0.16.3', '<')) {
// Migrate the SOAP Host to REST Host, if it's set.
// $pluginConfig->get('blisstribute-article-sync-enabled')
// Add option to disable article sync.
$form->setElement(
'checkbox',
'blisstribute-article-sync-enabled',
[
'label' => 'Artikel synchronisieren',
'description' => 'Wenn deaktiviert werden keine Artikel zwischen diesem Shop und Blisstribute synchronisiert.',
'value' => 1,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
// Add option to always send vatRate = 0.
$form->setElement(
'checkbox',
'blisstribute-order-include-vatrate',
[
'label' => 'Steuersatz übertragen',
'description' => 'Wenn deaktiviert wird der Steuersatz bei Bestellungen nicht übertragen und im Blisstribute ermittelt.',
'value' => 1,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
$form->setElement(
'text',
'blisstribute-order-lock-mapping',
array(
'label' => 'Bestellsperre Verknüpfung',
'description' => '',
'value' => '',
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
)
);
$form->setElement(
'text',
'blisstribute-order-hold-mapping',
array(
'label' => 'Bestellhalt Verknüpfung',
'description' => '',
'value' => '',
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
)
);
$form->setElement(
'text',
'blisstribute-article-stock-mapping',
array(
'label' => 'Artikelbestand Verknüpfung',
'description' => '',
'value' => ''
)
);
$this->get('db')->query(
"INSERT INTO s_premium_dispatch_attributes (blisstribute_shipment_code, dispatchID, blisstribute_shipment_is_priority)
SELECT
CASE mapping_class_name
WHEN 'Dhl' THEN 'DHL'
WHEN 'Dhlexpress' THEN 'DHLEXPRESS'
WHEN 'Dpd' THEN 'DPD'
WHEN 'Dpde12' THEN 'DPDE12'
WHEN 'Dpde18' THEN 'DPDE18'
WHEN 'Dpds12' THEN 'DPDS12'
WHEN 'Dtpg' THEN 'DTPG'
WHEN 'Dtpm' THEN 'DTPM'
WHEN 'Fba' THEN 'FBA'
WHEN 'Fedex' THEN 'FEDEX'
WHEN 'Gls' THEN 'GLS'
WHEN 'Gww' THEN 'GWW'
WHEN 'Hermes' THEN 'HERMES'
WHEN 'Lettershipment' THEN 'LSH'
WHEN 'Pat' THEN 'PAT'
WHEN 'Patexpress' THEN 'PATEXPRESS'
WHEN 'Selfcollector' THEN 'SEL'
WHEN 'Sevensenders' THEN '7SENDERS'
WHEN 'Skr' THEN 'SKR'
END AS ext_blisstribute_shipment_code, s_premium_dispatch_id, 0 AS blisstribute_shipment_is_priority
FROM s_plugin_blisstribute_shipment temp
ON DUPLICATE KEY UPDATE
s_premium_dispatch_attributes.blisstribute_shipment_code = values(s_premium_dispatch_attributes.blisstribute_shipment_code), blisstribute_shipment_is_priority=0"
);
$this->get('db')->query("DROP TABLE IF EXISTS s_plugin_blisstribute_shipment");
}
if (version_compare($version, '1.2.2', '<')) {
$form->setElement(
'text',
'blisstribute-b2b-blacklist-pattern',
[
'label' => 'Blacklist für Firmennamen (B2B Ermittlung, Kommasepatiert)',
'description' => 'Wird dieser Wert als Firmenname angegeben, wird dies nicht als B2B Bestellung gewertet. Es handelt sich NICHT um einen regulärgen Ausdruck.',
'maxLength' => 255,
'value' => 'x,*,/,-',
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
$form->setElement(
'checkbox',
'blisstribute-b2b-force',
[
'label' => 'B2B Shop',
'description' => 'Wenn aktiviert, werden alle Bestellung aus dem aktuellen Shop als B2B übertragen.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
}
if (version_compare($version, '1.3.0', '<')) {
$form->setElement(
'checkbox',
'blisstribute-exclude-price-transfer',
[
'label' => 'Artikelpreisübertragung dieses Shops unterbinden',
'description' => 'Wenn aktiviert, werden die Preise dieses Subshops nicht zu Blisstribute übermittelt.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
$form->setElement(
'checkbox',
'blisstribute-exclude-advertising-medium-from-shop-price',
[
'label' => 'Werbemittel aus dem Shoppreis ausschliessen',
'description' => 'Wenn aktiviert, werden die Preise dieses Subshops ohne Werbemittelcode übertragen.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
$form->setElement(
'checkbox',
'blisstribute-transfer-shop-price-net',
[
'label' => 'Artikel-Shop-Preise Netto übertragen',
'description' => 'Wenn aktiviert, werden die Preise dieses Subshops als Netto-Preise übertragen.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
$form->setElement(
'checkbox',
'blisstribute-transfer-scale-prices',
[
'label' => 'Artikel-Shop-Staffel-Preise übertragen',
'description' => 'Wenn aktiviert, werden die Staffelpreise dieses Subshops übertragen.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
}
if (version_compare($version, '1.3.4', '<')) {
$form->setElement(
'checkbox',
'blisstribute-b2c-force',
[
'label' => 'B2C Shop',
'description' => 'Wenn aktiviert, werden alle Bestellung aus dem aktuellen Shop als B2C übertragen.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
}
if (version_compare($version, '1.3.15', '<')) {
$this->get('db')->query("ALTER TABLE s_plugin_blisstribute_payment ADD COLUMN payment_type_code varchar(255)");
}
if (version_compare($version, '1.3.16', '<')) {
$form->setElement(
'number',
'blisstribute-order-hold-limit',
[
'label' => 'Bestellung ab Bestellwert X anhalten',
'description' => 'Wenn der Bestellwert das konfigurierte Limit übertrifft, dann wird die Bestellung im Blisstribute angehalten.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP,
]
);
}
if (version_compare($version, '1.3.17', '<')) {
$form->setElement(
'checkbox',
'blisstribute-order-hold-if-whole-order-is-payed-with-voucher',
[
'label' => 'Bestellung anhalten, wenn kompletter Rechnungsbetrage von einem Gutschein gedeckt wird',
'description' => 'Wenn aktiviert, werden alle Bestellungen, die komplett von einem oder mehreren Gutscheinen bezahlt wurden, im Blisstribute angehalten.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP,
]
);
}
if (version_compare($version, '1.3.18', '<')) {
$form->setElement(
'text',
'blisstribute-order-hold-comma-separated-article-numbers',
[
'label' => 'Bestellung anhalten, wenn Bestellung nur aus konfigurierten Artikelnummern besteht',
'description' => 'Wenn konfiguriert, wird überprüft, ob die Bestellung ausschließlich aus den kommagetrennten Artikelnummern besteht und wenn ja, wird die Bestellung im Blisstribute angehalten.',
'value' => '',
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP,
]
);
}
if (version_compare($version, '1.3.20', '<')) {
$form->setElement(
'checkbox',
'blisstribute-add-shopware-internal-comment-to-order-remark',
[
'label' => 'Interner Kommentar in das Bemerkungsfeld der Bestellung schreiben',
'description' => 'Wenn diese Option aktiviert ist, wird der interne Kommentar von Shopware an den Anfang des Bemerkungsfeldes der Bestellung geschrieben.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP,
]
);
}
if (version_compare($version, '1.3.22', '<')) {
$form->setElement(
'checkbox',
'blisstribute-article-sync-check-for-change-date',
[
'label' => 'Artikel-Änderungsdatum auswerten',
'description' => 'Wenn aktivert, wird vor der Synchronisation das Modifizierungsdatum der Artikel ausgewertet.',
'value' => 0,
'scope' => Shopware\Models\Config\Element::SCOPE_SHOP
]
);
}
if (version_compare($version, '1.3.27', '<')) {
$form->setElement(
'text',
'blisstribute-article-number-mapping',
array(
'label' => 'Artikelnummer Verknüpfung',
'description' => '',
'value' => ''
)
);
}
if (version_compare($version, '1.3.30', '<')) {
$form->setElement(
'text',
'blisstribute-article-comment-mapping',
array(
'label' => 'Verknüpfung Artikel-Kommentar',
'description' => '',
'value' => ''
)
);
}
if (version_compare($version, '1.4.2', '<')) {
$form->setElement(
'checkbox',
'blisstribute-disable-payment-status-check',
array(
'label' => 'SW-Zahl-Status ignorieren',
'description' => '',
'value' => 0
)
);
}
if (version_compare($version, '1.4.4', '<')) {
$form->setElement(
'checkbox',
'blisstribute-force-product-serial-number',
array(
'label' => 'Artikel-Seriennummer erzwingen',
'description' => '',
'value' => 0
)
);
}
if (version_compare($version, '1.4.7', '<')) {
$form->setElement(
'checkbox',
'blisstribute-product-evaluate-price-customergroup',
array(
'label' => 'Kundengruppen-Regeln auf VK-Preise anwenden',
'description' => '',
'value' => 0
)
);
}
if (version_compare($version, '1.4.12', '<')) {
$form->setElement(
'checkbox',
'blisstribute-force-delivery-time-zero-with-no-stock',
array(
'label' => 'Lieferzeit bei 0-Bestand zurücksetzen',
'description' => '',
'value' => 0
)
);
}
return ['success' => true, 'invalidateCache' => ['backend', 'proxy', 'config']];
}
/**
* @return array
*/
public function uninstall()
{
return ['success' => true, 'invalidateCache' => ['backend', 'proxy', 'config']];
}
/**
* @return bool
*/
public function secureUninstall()
{
return true;
}
/**
* add new states
*
* @return void
*/
private function createOrderStateCollection()
{
$sql = "INSERT IGNORE INTO `s_core_states` (`id`, `description`, `position`, `group`, `mail`)
VALUES (60, 'Retoure offen', 101, 'state', 0),
(61, 'Retoure abgeschlossen', 102, 'state', 0),
(62, 'Retoure teilweise abgeschlossen', 103, 'state', 0)";
$this->get('db')->query($sql);
}
/**
* @return void
*/
private function createAttributeCollection()
{
/** @var Shopware\Bundle\AttributeBundle\Service\CrudService $crud */
$crud = $this->get('shopware_attribute.crud_service');
$crud->update('s_articles_attributes', 'blisstribute_supplier_code', 'combobox', [
'displayInBackend' => true,
'label' => 'VHS - Lieferantencode',
'custom' => 1
]);
$crud->update('s_articles_attributes', 'blisstribute_vhs_number', 'string', [
'displayInBackend' => true,
'label' => 'VHS - VHS-Artikel-Nummer',
'custom' => 1
]);
$crud->update('s_articles_attributes', 'blisstribute_supplier_stock', 'integer', [
'displayInBackend' => true,
'label' => 'VHS - Lieferantenbestand',
'custom' => 1
]);
$crud->update('s_articles_attributes', 'blisstribute_customs_tariff_number', 'string', [
'displayInBackend' => true,
'label' => 'VHS - Zolltarifnummer',
'custom' => 1
]);
$crud->update('s_articles_attributes', 'blisstribute_country_of_origin', 'string', [
'displayInBackend' => true,
'label' => 'VHS - Herkunftsland (ISO Alpha 2)',
'custom' => 1
]);
$crud->update('s_articles_attributes', 'blisstribute_article_shipment_code', 'string', [
'displayInBackend' => true,
'label' => 'VHS - Statische Versandart',
'supportText' => 'Wenn angegeben, wird dieser Code bei einer Bestellung für diese Bestellzeile übergeben.',
'custom' => 1
]);
$crud->update('s_articles_attributes', 'blisstribute_article_advertising_medium_code', 'string', [
'displayInBackend' => true,
'label' => 'VHS - Statischer Werbemittelcode',
'custom' => 1,
'supportText' => 'Wenn angegeben, wird dieser Code bei einer Bestellung für diese Bestellzeile übergeben.',
]);
$crud->update('s_categories_attributes', 'blisstribute_category_advertising_medium_code', 'string', [
'displayInBackend' => true,
'label' => 'VHS - Statischer Werbemittelcode',
'custom' => 1,
'supportText' => 'Wenn angegeben, wird dieser Code bei einer Bestellung für Bestellzeilen aus dieser Kategorie oder einer Subkategorie übergeben.',
]);
$crud->update('s_order_details_attributes', 'blisstribute_quantity_canceled', 'integer');
$crud->update('s_order_details_attributes', 'blisstribute_quantity_returned', 'integer');
$crud->update('s_order_details_attributes', 'blisstribute_quantity_shipped', 'integer');
$crud->update('s_order_details_attributes', 'blisstribute_date_changed', 'date');
$crud->update('s_order_basket_attributes', 'blisstribute_swag_promotion_is_free_good', 'string');
$crud->update('s_order_basket_attributes', 'blisstribute_swag_is_free_good_by_promotion_id', 'string');
$crud->update('s_premium_dispatch_attributes', 'blisstribute_shipment_code', 'string', [
'custom' => 1,
'displayInBackend' => true,
'label' => 'VHS - Shipment Code',
'supportText' => 'Der Shipment Code für diese Bestellung.',
]);
$crud->update('s_premium_dispatch_attributes', 'blisstribute_shipment_is_priority', 'boolean', [
'custom' => 1,
'displayInBackend' => true,
'label' => 'VHS - Priorisierter Versand'
]);
$this->get('db')->query(
"INSERT IGNORE INTO `s_core_engine_elements` (`groupID`, `type`, `label`, `required`, `position`, " .
"`name`, `variantable`, `translatable`) VALUES (7, 'text', 'VHS Nummer', 0, 101, " .
"'blisstributeVhsNumber', 0, 0), (7, 'number', 'Bestand Lieferant', 0, 102, " .
"'blisstributeSupplierStock', 0, 0)"
);
$metaDataCache = Shopware()->Models()->getConfiguration()->getMetadataCacheImpl();
$metaDataCache->deleteAll();
Shopware()->Models()->generateAttributeModels(['s_articles_attributes', 's_categories_attributes', 's_order_details_attributes', 's_order_basket_attributes', 's_premium_dispatch_attributes']);
}
/**
* add attribute to article
*
* @param Enlight_Event_EventArgs $args
*/
public function postDispatchBackendArticle(Enlight_Event_EventArgs $args)
{
$view = $args->getSubject()->View();
$view->addTemplateDir($this->Path() . 'Views/');
if ($args->getRequest()->getActionName() === 'load') {
$view->extendsTemplate('backend/attributes_article/model/attribute.js');
}
}
/**
* add event listener for blisstribute module
*
* @return void
*/
private function subscribeEvents()
{
$this->subscribeEvent('Shopware_Console_Add_Command', 'onAddConsoleCommand');
$this->subscribeEvent('Enlight_Controller_Front_StartDispatch', 'startDispatch');
$this->subscribeEvent('Shopware_CronJob_BlisstributeOrderSyncCron', 'onRunBlisstributeOrderSyncCron');
$this->subscribeEvent('Shopware_CronJob_BlisstributeArticleSyncCron', 'onRunBlisstributeArticleSyncCron');
$this->subscribeEvent('Shopware_CronJob_BlisstributeEasyCouponMappingCron', 'onRunBlisstributeEasyCouponMappingCron');
$this->subscribeEvent('Shopware_CronJob_BlisstributeOrderMappingCron', 'onRunBlisstributeOrderMappingCron');
$this->subscribeEvent('Shopware_CronJob_BlisstributeArticleMappingCron', 'onRunBlisstributeArticleMappingCron');
}
/**
* Blisstribute Order Sync CronJob
*
* @param \Shopware_Components_Cron_CronJob $job
*/
public function onRunBlisstributeOrderSyncCron(\Shopware_Components_Cron_CronJob $job)
{
if(is_null($job)) return;
try {
$container = Shopware()->Container();
$shop = $container->get('models')->getRepository(Shop::class)->getActiveDefault();
$config = $container->get('shopware.plugin.cached_config_reader')->getByPluginName('ExitBBlisstribute', $shop);
$controller = new \Shopware_Components_Blisstribute_Order_Sync(new Enlight_Config($config));
$controller->processBatchOrderSync();
} catch (\Exception $ex) {
$this->_log("exception while syncing orders " . $ex->getMessage());
return;
}
}
/**
* Blisstribute Article Sync CronJob
*
* @param \Shopware_Components_Cron_CronJob $job
*/
public function onRunBlisstributeArticleSyncCron(\Shopware_Components_Cron_CronJob $job)
{
if(is_null($job)) return;
$container = Shopware()->Container();
$shop = $container->get('models')->getRepository(Shop::class)->getActiveDefault();
$config = $container->get('shopware.plugin.cached_config_reader')->getByPluginName('ExitBBlisstribute', $shop);
$pluginConfig = new Enlight_Config($config);
// If the user disabled article synchronization, stop here.
if ($pluginConfig->get('blisstribute-article-sync-check-for-change-date')) {
$this->logDebug('onRunBlisstributeArticleSyncCron::repair trigger sync flag started');
$sql = "UPDATE s_plugin_blisstribute_articles a INNER JOIN s_articles b ON a.s_article_id = b.id SET a.trigger_sync = 1 WHERE a.last_cron_at < b.changetime AND trigger_sync = 0";
$this->get('db')->query($sql);
$this->logDebug('onRunBlisstributeArticleSyncCron::repair trigger sync flag done');
}
// If the user disabled article synchronization, stop here.
if (!$pluginConfig->get('blisstribute-article-sync-enabled')) {
$this->_log(date('r') . ' - BLISSTRIBUTE article sync is disabled' . PHP_EOL);
return;
}
try {
$controller = new \Shopware_Components_Blisstribute_Article_Sync($pluginConfig);
$controller->processBatchArticleSync();
} catch (\Exception $ex) {
$this->_log("exception while syncing articles " . $ex->getMessage());
return;
}
}
/**
* EasyCoupon Wertgutscheine
*
* @param \Shopware_Components_Cron_CronJob $job
*/
public function onRunBlisstributeEasyCouponMappingCron(\Shopware_Components_Cron_CronJob $job)
{
if(is_null($job)) return;
try {
$plugin = Shopware()->Models()->getRepository('Shopware\Models\Plugin\Plugin')->findOneBy([
'name' => 'NetiEasyCoupon',
'active' => true
]);
if (!$plugin) {
return;
}
$modelManager = Shopware()->Container()->get('models');
$sqlUnmappedVouchers = "SELECT voucher.id AS id FROM s_emarketing_vouchers voucher
LEFT JOIN s_plugin_blisstribute_coupon coupon ON coupon.s_voucher_id = voucher.id
LEFT JOIN s_emarketing_vouchers_attributes attributes ON attributes.voucherID = voucher.id
WHERE coupon.id IS NULL AND attributes.neti_easy_coupon = 1";
$unmappedVouchers = Shopware()->Container()->get('db')->fetchAll($sqlUnmappedVouchers);
$idArray = [];
foreach ($unmappedVouchers as $voucher) {
$idArray[] = $voucher['id'];
}
$vouchers = $modelManager->getRepository('\Shopware\Models\Voucher\Voucher')->findById($idArray);
/** @var \Shopware\Models\Voucher\Voucher $voucher */
foreach ($vouchers as $voucher) {
$blisstributeCoupon = new BlisstributeCoupon();
$blisstributeCoupon->setVoucher($voucher)->setIsMoneyVoucher(true);
$modelManager->persist($blisstributeCoupon);
}
$modelManager->flush();
} catch (\Exception $ex) {
$this->_log("exception while syncing easy coupon " . $ex->getMessage());
return;
}
}
/**
* Import all orders that might have been added using pure sql
*
* @param \Shopware_Components_Cron_CronJob $job
*/
public function onRunBlisstributeOrderMappingCron(\Shopware_Components_Cron_CronJob $job)
{
if(is_null($job)) return;
try {
$this->logDebug('onRunBlisstributeOrderMappingCron::start');
$this->logDebug('onRunBlisstributeOrderMappingCron::cleaning obsolete referenced orders');
$sql = "DELETE FROM s_plugin_blisstribute_orders WHERE s_order_id NOT IN (SELECT id FROM s_order)";
$this->get('db')->query($sql);
$this->logDebug('onRunBlisstributeOrderMappingCron::cleaning obsolete referenced orders done');
$this->logDebug('onRunBlisstributeOrderMappingCron::creating new order references');
$sql = "SELECT id FROM s_order WHERE id NOT IN (SELECT s_order_id FROM s_plugin_blisstribute_orders) AND ordernumber != '0'";
$modelManager = Shopware()->Container()->get('models');
$orders = Shopware()->Container()->get('db')->fetchAll($sql);
$date = new \DateTime();
foreach ($orders as $order) {
$blisstributeOrder = new BlisstributeOrder();
$blisstributeOrder->setTries(0);
$blisstributeOrder->setOrder($modelManager->getRepository('\Shopware\Models\Order\Order')->find($order['id']));
$blisstributeOrder->setCreatedAt($date);
$blisstributeOrder->setModifiedAt($date);