-
Notifications
You must be signed in to change notification settings - Fork 25
/
tmp.diff
1587 lines (1513 loc) · 59.6 KB
/
tmp.diff
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
diff --git a/client/javascript/EcomBuyableSelectField.js b/client/javascript/EcomBuyableSelectField.js
index 25c1cb86..44fa2432 100644
--- a/client/javascript/EcomBuyableSelectField.js
+++ b/client/javascript/EcomBuyableSelectField.js
@@ -38,6 +38,12 @@ const EcomBuyableSelectField = {
this.url_segment = s
},
+ joinWithSlash: (...strings) =>
+ strings
+ .map(str => (str.endsWith('/') ? str : `${str}/`))
+ .join('')
+ .slice(0, -1),
+
/**
* the class that is being added when we are searching...
* @var String
@@ -192,11 +198,11 @@ const EcomBuyableSelectField = {
EcomBuyableSelectField.requestTerm = request.term
window.jQuery.ajax({
type: 'POST',
- url:
- window.jQuery('base').attr('href') +
- '/' +
- EcomBuyableSelectField.url_segment +
- '/json/',
+ url: EcomBuyableSelectField.joinWithSlash(
+ window.jQuery('base').attr('href'),
+ EcomBuyableSelectField.url_segment,
+ 'json'
+ ),
dataType: 'json',
data: {
term: request.term,
diff --git a/client/javascript/EcomCart.js b/client/javascript/EcomCart.js
index 355fdc01..eb7e679a 100644
--- a/client/javascript/EcomCart.js
+++ b/client/javascript/EcomCart.js
@@ -58,6 +58,12 @@ var EcomCart = {
this.debug = b
},
+ joinWithSlash: (...strings) =>
+ strings
+ .map(str => (str.endsWith('/') ? str : `${str}/`))
+ .join('')
+ .slice(0, -1),
+
/**
* selector to identify input field for selecting country.
*/
@@ -709,16 +715,15 @@ var EcomCart = {
* @return String
*/
createUrl: function (method, variable) {
- var url =
- window.jQuery('base').attr('href') +
- '/' +
- EcomCart.shoppingCartURLSegment +
- '/'
+ var url = EcomCart.joinWithSlash(
+ window.jQuery('base').attr('href'),
+ EcomCart.shoppingCartURLSegment
+ )
if (method) {
- url += method + '/'
+ EcomCart.joinWithSlash(url, method)
}
if (variable) {
- url += variable + '/'
+ EcomCart.joinWithSlash(url, variable)
}
return url
},
diff --git a/client/javascript/UTMReferralPointer.js b/client/javascript/UTMReferralPointer.js
new file mode 100644
index 00000000..bbd26dbb
--- /dev/null
+++ b/client/javascript/UTMReferralPointer.js
@@ -0,0 +1,86 @@
+const getVarsToExpect = [
+ 'utm_source',
+ 'utm_medium',
+ 'utm_campaign',
+ 'utm_term',
+ 'utm_content',
+ 'fbclid',
+ 'gad',
+ 'gclid',
+ 'gclsrc',
+ 'twclid'
+]
+function getUTMParameters () {
+ // console.log('getting params from url')
+ const params = new URLSearchParams(window.location.search)
+ const utmParams = {}
+ getVarsToExpect.forEach(param => {
+ if (params.has(param)) {
+ utmParams[param] = params.get(param)
+ }
+ })
+ return utmParams
+}
+
+function saveToLocalStorage (data) {
+ for (const key in data) {
+ localStorage.setItem(key, data[key])
+ }
+}
+
+function getUTMDataFromLocalStorage () {
+ // console.log('getting data from local storage')
+ const utmData = {}
+ getVarsToExpect.forEach(param => {
+ const value = localStorage.getItem(param)
+ if (value) {
+ utmData[param] = value
+ }
+ })
+ return utmData
+}
+
+function clearLocalStorage () {
+ // console.log('clearing local storage')
+ getVarsToExpect.forEach(param => {
+ localStorage.removeItem(param)
+ })
+}
+
+function sendUTMDataToServer (utmData) {
+ // console.log('sending to server')
+ const baseTag = document.querySelector('base')
+ let baseHref = baseTag ? baseTag.getAttribute('href') : null
+
+ if (baseHref) {
+ // Remove trailing slash if it exists
+ baseHref = baseHref.endsWith('/') ? baseHref.slice(0, -1) : baseHref
+ const queryParams = new URLSearchParams(utmData).toString()
+ const url = `${baseHref}/shoppingcart/addreferral?${queryParams}`
+
+ fetch(url)
+ .then(response => response.text())
+ .then(data => {
+ // console.log(data)
+ if (parseInt(data) > 0) {
+ clearLocalStorage()
+ }
+ })
+ .catch(error => console.error('Error:', error))
+ }
+}
+
+const searchParams = window.location.search
+const itemsToCheck = getVarsToExpect
+
+// Main execution
+let utmParams = getUTMParameters()
+if (Object.keys(utmParams).length > 0) {
+ saveToLocalStorage(utmParams)
+} else {
+ utmParams = getUTMDataFromLocalStorage()
+}
+
+if (Object.keys(utmParams).length > 0) {
+ sendUTMDataToServer(utmParams)
+}
diff --git a/src/Api/ShoppingCart.php b/src/Api/ShoppingCart.php
index 2d4660bc..793529ed 100644
--- a/src/Api/ShoppingCart.php
+++ b/src/Api/ShoppingCart.php
@@ -4,6 +4,7 @@ namespace Sunnysideup\Ecommerce\Api;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
+use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extensible;
@@ -27,6 +28,7 @@ use Sunnysideup\Ecommerce\Model\Order;
use Sunnysideup\Ecommerce\Model\OrderItem;
use Sunnysideup\Ecommerce\Model\OrderModifier;
use Sunnysideup\Ecommerce\Model\Process\OrderStep;
+use Sunnysideup\Ecommerce\Model\Process\Referral;
use Sunnysideup\Ecommerce\Tasks\EcommerceTaskCartCleanup;
/*
@@ -1162,6 +1164,19 @@ class ShoppingCart
$this->messages[] = ['Message' => $message, 'Type' => $status];
}
+ public function addReferral($params): int
+ {
+ if(count($params)) {
+ $order = $this->currentOrder();
+ if($order && $order->exists()) {
+ if(Referral::add_referral($order, $params)) {
+ return $order->ID;
+ }
+ }
+ }
+ return -2;
+ }
+
// UI MESSAGE HANDLING
/**
@@ -1173,18 +1188,12 @@ class ShoppingCart
{
$sessionVariableName = $this->sessionVariableName('Messages');
$messages = [];
- $curr = Controller::curr();
- if ($curr) {
- $request = $curr->getRequest();
- if ($request) {
- $session = $request->getSession();
- if ($session) {
- //get old messages
- $messages = unserialize((string) $session->get($sessionVariableName));
- //clear old messages
- $session->clear($sessionVariableName);
- }
- }
+ $session = $this->getSession();
+ if ($session) {
+ //get old messages
+ $messages = unserialize((string) $session->get($sessionVariableName));
+ //clear old messages
+ $session->clear($sessionVariableName);
}
//set to form????
@@ -1195,6 +1204,18 @@ class ShoppingCart
return $this->messages;
}
+ protected function getSession(): ?Session
+ {
+ $curr = Controller::curr();
+ if ($curr) {
+ $request = $curr->getRequest();
+ if ($request) {
+ return $request->getSession();
+ }
+ }
+ return null;
+ }
+
/**
* This method is used to return data after an ajax call was made.
* When a asynchronious request is made to the shopping cart (ajax),
@@ -1217,10 +1238,10 @@ class ShoppingCart
}
// recalculate... this is often a change so well worth it.
- $this->currentOrder();
- if($this->order) {
+ $order = $this->currentOrder();
+ if($order) {
//todo- why would there not be an order?
- $this->order->calculateOrderAttributes($recalculate = true);
+ $order->calculateOrderAttributes($recalculate = true);
}
//TODO: handle passing back multiple messages
diff --git a/src/Cms/SalesAdminProcess.php b/src/Cms/SalesAdminProcess.php
index 7534d99b..3f6f2791 100644
--- a/src/Cms/SalesAdminProcess.php
+++ b/src/Cms/SalesAdminProcess.php
@@ -6,6 +6,7 @@ use SilverStripe\Admin\ModelAdmin;
use SilverStripe\View\Requirements;
use Sunnysideup\Ecommerce\Model\Process\OrderFeedback;
use Sunnysideup\Ecommerce\Model\Process\OrderProcessQueue;
+use Sunnysideup\Ecommerce\Model\Process\Referral;
use Sunnysideup\Ecommerce\Traits\EcommerceModelAdminTrait;
/**
@@ -43,8 +44,9 @@ class SalesAdminProcess extends ModelAdmin
* @var array
*/
private static $managed_models = [
- OrderProcessQueue::class,
+ Referral::class,
OrderFeedback::class,
+ OrderProcessQueue::class,
];
/**
diff --git a/src/Control/ShoppingCartController.php b/src/Control/ShoppingCartController.php
index 52d28565..9ba9de05 100644
--- a/src/Control/ShoppingCartController.php
+++ b/src/Control/ShoppingCartController.php
@@ -77,6 +77,7 @@ class ShoppingCartController extends Controller
'json',
'index',
'additem',
+ 'addreferral',
'removeitem',
'removeallitem',
'removeallitemandedit',
@@ -313,10 +314,9 @@ class ShoppingCartController extends Controller
*/
public function additem(HTTPRequest $request)
{
- /** Buya*/
$buyable = $this->buyable();
if ($buyable) {
- $this->cart->addBuyable($buyable, $this->quantity(), $this->parameters());
+ $this->cart->addBuyable($buyable, $this->quantity(), $this->parameters(true));
return $this->cart->setMessageAndReturn();
}
@@ -324,6 +324,20 @@ class ShoppingCartController extends Controller
return $this->goToErrorPage();
}
+ /**
+ * Adds item to cart via controller action; one by default.
+ *
+ * @return mixed - if the request is AJAX, it returns JSON - CartResponse::ReturnCartData();
+ * If it is not AJAX it redirects back to requesting page
+ */
+ public function addreferral(HTTPRequest $request)
+ {
+ if($this->cart) {
+ return $this->cart->addReferral($this->parameters(true));
+ }
+ return -1;
+ }
+
/**
* Sets the exact passed quantity.
* Note: If no ?quantity=x is specified in URL, then quantity will be set to 1.
@@ -335,7 +349,7 @@ class ShoppingCartController extends Controller
{
$buyable = $this->buyable();
if ($buyable) {
- $this->cart->setQuantity($buyable, $this->quantity(), $this->parameters());
+ $this->cart->setQuantity($buyable, $this->quantity(), $this->parameters(true));
return $this->cart->setMessageAndReturn();
}
@@ -353,7 +367,7 @@ class ShoppingCartController extends Controller
{
$buyable = $this->buyable();
if ($buyable) {
- $this->cart->decrementBuyable($buyable, $this->quantity(), $this->parameters());
+ $this->cart->decrementBuyable($buyable, $this->quantity(), $this->parameters(true));
return $this->cart->setMessageAndReturn();
}
@@ -371,7 +385,7 @@ class ShoppingCartController extends Controller
{
$buyable = $this->buyable();
if ($buyable) {
- $this->cart->deleteBuyable($buyable, $this->parameters());
+ $this->cart->deleteBuyable($buyable, $this->parameters(true));
//added this because cart was not updating correctly
// $order = $this->cart->CurrentOrder();
// $order->calculateOrderAttributes($recalculate = true);
@@ -394,7 +408,7 @@ class ShoppingCartController extends Controller
$buyable = $this->buyable();
if ($buyable) {
$link = $buyable->Link();
- $this->cart->deleteBuyable($buyable, $this->parameters());
+ $this->cart->deleteBuyable($buyable, $this->parameters(true));
$this->redirect($link);
} else {
$this->redirectBack();
@@ -781,19 +795,17 @@ class ShoppingCartController extends Controller
{
parent::init();
$action = $this->request->param('Action');
- if (! isset($_GET['cached'])) {
- if ($action && (in_array($action, $this->methodsRequiringSecurityID, true))) {
- $savedSecurityID = $this->getRequest()->getSession()->get('SecurityID');
+ if ($action && (in_array($action, $this->methodsRequiringSecurityID, true))) {
+ $savedSecurityID = $this->getRequest()->getSession()->get('SecurityID');
+ if ($savedSecurityID) {
+ if (! isset($_GET['SecurityID'])) {
+ $_GET['SecurityID'] = '';
+ }
if ($savedSecurityID) {
- if (! isset($_GET['SecurityID'])) {
- $_GET['SecurityID'] = '';
- }
- if ($savedSecurityID) {
- if ($_GET['SecurityID'] !== $savedSecurityID) {
- $this->httpError(400, "Security token doesn't match, possible CSRF attack.");
- }
- //all OK!
+ if ($_GET['SecurityID'] !== $savedSecurityID) {
+ $this->httpError(400, "Security token doesn't match, possible CSRF attack.");
}
+ //all OK!
}
}
}
@@ -888,9 +900,10 @@ class ShoppingCartController extends Controller
*
* @return array
*/
- protected function parameters(?string $getpost = 'GET')
+ protected function parameters(?bool $getVars = true)
{
- return 'GET' === $getpost ? $this->getRequest()->getVars() : $_POST;
+ // TODO: postvars do not seem to work!!!
+ return $getVars ? $this->getRequest()->getVars() : $this->getRequest()->postVars();
}
protected function goToErrorPage()
diff --git a/src/Email/OrderEmail.php b/src/Email/OrderEmail.php
index 85bdc49b..b1c06952 100644
--- a/src/Email/OrderEmail.php
+++ b/src/Email/OrderEmail.php
@@ -143,13 +143,13 @@ abstract class OrderEmail extends Email
/**
*
*/
- public function sendInner(?bool $returnBodyOnly = false): ?string
+ protected function sendInner(?bool $returnBodyOnly = false): ?string
{
- if (! $this->order) {
+ if (!$this->order) {
user_error('Must set the order (OrderEmail::setOrder()) before the message is sent (OrderEmail::send()).', E_USER_NOTICE);
}
$this->fixupSubject();
- if (! $this->hasBeenSent() || ($this->resend)) {
+ if (!$this->hasBeenSent() || ($this->resend)) {
if (EcommerceConfig::get(OEmailrderEmail::class, 'copy_to_admin_for_all_emails') && ($this->getTo() !== self::get_from_email())) {
$memberEmail = self::get_from_email();
if ($memberEmail) {
@@ -166,7 +166,6 @@ abstract class OrderEmail extends Email
if ($returnBodyOnly) {
return (string) $this->getHtmlBody();
}
-
if (EcommerceConfig::get(OrderEmail::class, 'send_all_emails_plain')) {
parent::sendPlain();
} else {
@@ -197,7 +196,7 @@ abstract class OrderEmail extends Email
protected function fixupSubject()
{
- if (! $this->getSubject()) {
+ if (!$this->getSubject()) {
$this->setSubject(self::get_subject());
}
$this->setSubject(str_replace('[OrderNumber]', $this->order->ID, (string) $this->getSubject()));
@@ -257,7 +256,7 @@ abstract class OrderEmail extends Email
$plainOnly = (bool) $plainOnly;
parent::render($plainOnly);
//moves CSS to inline CSS in email.
- if (! $plainOnly) {
+ if (!$plainOnly) {
$html = (string) ($this->getHtmlBody() ?: '');
$this->setBody($html);
}
@@ -293,9 +292,9 @@ abstract class OrderEmail extends Email
$sendAllEmailsTo = Config::inst()->get(Email::class, 'send_all_emails_to');
if ($sendAllEmailsTo) {
$orderEmailRecord->To .=
- _t('OrderEmail.ACTUALLY_SENT_TO', ' | actually sent to: ')
- . $sendAllEmailsTo
- . _t('OrderEmail.CONFIG_EXPLANATION', ' - (Email::send_all_emails_to)');
+ _t('OrderEmail.ACTUALLY_SENT_TO', ' | actually sent to: ')
+ . $sendAllEmailsTo
+ . _t('OrderEmail.CONFIG_EXPLANATION', ' - (Email::send_all_emails_to)');
}
$orderEmailRecord->write();
diff --git a/src/Forms/Fields/EcommerceCMSButtonField.php b/src/Forms/Fields/EcommerceCMSButtonField.php
index 20187ad7..af491d54 100644
--- a/src/Forms/Fields/EcommerceCMSButtonField.php
+++ b/src/Forms/Fields/EcommerceCMSButtonField.php
@@ -14,7 +14,7 @@ class EcommerceCMSButtonField extends LiteralField
* @param mixed $link (string|ViewableData|FormField)
* @param bool $newWindow
*/
- public function __construct($name, $link, string $title, ?bool $newWindow = false)
+ public function __construct(string $name, string $link, string $title, ?bool $newWindow = false)
{
$target = '';
if ($newWindow) {
diff --git a/src/Forms/Gridfield/GridFieldExportSalesButton.php b/src/Forms/Gridfield/GridFieldExportSalesButton.php
index e1e5f756..42a73720 100644
--- a/src/Forms/Gridfield/GridFieldExportSalesButton.php
+++ b/src/Forms/Gridfield/GridFieldExportSalesButton.php
@@ -97,8 +97,7 @@ class GridFieldExportSalesButton extends GridFieldExportButton implements GridFi
'exportsales',
null
);
- $button->setAttribute('data-icon', 'download-csv');
- $button->addExtraClass('no-ajax action_export');
+ $button->addExtraClass('action btn btn-secondary no-ajax font-icon-down-circled action_export');
$button->setForm($gridField->getForm());
return [
diff --git a/src/Forms/Gridfield/GridFieldPrintAllInvoicesButton.php b/src/Forms/Gridfield/GridFieldPrintAllInvoicesButton.php
index 86353e3c..f14c2d52 100644
--- a/src/Forms/Gridfield/GridFieldPrintAllInvoicesButton.php
+++ b/src/Forms/Gridfield/GridFieldPrintAllInvoicesButton.php
@@ -54,8 +54,7 @@ class GridFieldPrintAllInvoicesButton implements GridField_HTMLProvider, GridFie
'printallinvoices',
null
);
- $button->setAttribute('data-icon', 'grid_print');
- $button->addExtraClass('no-ajax action_print_all_invoices');
+ $button->addExtraClass('action_print_all_invoices action btn btn-secondary no-ajax font-icon-down-circled action_export');
$button->setForm($gridField->getForm());
return [
diff --git a/src/Forms/Gridfield/GridFieldPrintAllPackingSlipsButton.php b/src/Forms/Gridfield/GridFieldPrintAllPackingSlipsButton.php
index 4a1c83f5..3bddf4c2 100644
--- a/src/Forms/Gridfield/GridFieldPrintAllPackingSlipsButton.php
+++ b/src/Forms/Gridfield/GridFieldPrintAllPackingSlipsButton.php
@@ -54,8 +54,7 @@ class GridFieldPrintAllPackingSlipsButton implements GridField_HTMLProvider, Gri
'printallpackingslips',
null
);
- $button->setAttribute('data-icon', 'grid_print');
- $button->addExtraClass('no-ajax action_print_all_packing_slips');
+ $button->addExtraClass('action_print_all_packing_slips action btn btn-secondary no-ajax font-icon-down-circled action_export');
$button->setForm($gridField->getForm());
return [
diff --git a/src/Forms/Gridfield/GridFieldPrintInvoiceButton.php b/src/Forms/Gridfield/GridFieldPrintInvoiceButton.php
index 2bff4008..7b0d29c2 100644
--- a/src/Forms/Gridfield/GridFieldPrintInvoiceButton.php
+++ b/src/Forms/Gridfield/GridFieldPrintInvoiceButton.php
@@ -81,9 +81,8 @@ class GridFieldPrintInvoiceButton implements GridField_ColumnProvider, GridField
'printinvoice',
['RecordID' => $record->ID]
)
- ->addExtraClass('gridfield-button-printinvoice')
+ ->addExtraClass('gridfield-button-printinvoice action btn btn-secondary no-ajax font-icon-down-circled action_export ')
->setAttribute('title', _t('GridAction.PRINT_INVOICE', 'Invoice'))
- ->setAttribute('data-icon', 'grid_print')
->setAttribute('onclick', $onclickStatement)
->setDescription(_t('GridAction.PRINT_INVOICE_DESCRIPTION', 'Print Invoice'))
->Field()
@@ -127,7 +126,9 @@ class GridFieldPrintInvoiceButton implements GridField_ColumnProvider, GridField
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ('printinvoice' === $actionName) {
- $item = $gridField->getList()->byID($arguments['RecordID']);
+ /** @var DataList $list */
+ $list = $gridField->getList();
+ $item = $list->byID($arguments['RecordID']);
if (! $item) {
return;
}
diff --git a/src/Forms/Gridfield/GridFieldPrintPackingSlipButton.php b/src/Forms/Gridfield/GridFieldPrintPackingSlipButton.php
index 174234a8..f09dec5b 100644
--- a/src/Forms/Gridfield/GridFieldPrintPackingSlipButton.php
+++ b/src/Forms/Gridfield/GridFieldPrintPackingSlipButton.php
@@ -82,7 +82,6 @@ class GridFieldPrintPackingSlipButton implements GridField_ColumnProvider, GridF
)
->addExtraClass('gridfield-button-printpackingslip')
->setAttribute('title', _t('GridPacking Slip.PRINT_PACKING_SLIP', 'Packing Slip'))
- ->setAttribute('data-icon', 'download-csv')
->setAttribute('onclick', $onclickStatement)
->setDescription(_t('GridPacking Slip.PRINT_PACKING_SLIP_DESCRIPTION', 'Print Packing Slip'))
->Field()
diff --git a/src/Model/Config/EcommerceDBConfig.php b/src/Model/Config/EcommerceDBConfig.php
index 9b92d807..3df498c9 100644
--- a/src/Model/Config/EcommerceDBConfig.php
+++ b/src/Model/Config/EcommerceDBConfig.php
@@ -739,7 +739,7 @@ class EcommerceDBConfig extends DataObject implements EditableEcommerceObject
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
- new GridFieldPaginator(10),
+ new GridFieldPaginator(200),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm()
diff --git a/src/Model/Extensions/ErrorPageExtension.php b/src/Model/Extensions/ErrorPageExtension.php
index 008a14b4..d2a33857 100644
--- a/src/Model/Extensions/ErrorPageExtension.php
+++ b/src/Model/Extensions/ErrorPageExtension.php
@@ -26,8 +26,10 @@ class ErrorPageExtension extends Extension
{
$product = $this->urlToProduct($request);
if ($product) {
+ $getVars = $request->getVars();
+ $dest = $product->Link() . '?' . http_build_query($getVars);
+
$response = new HTTPResponse();
- $dest = $product->Link();
$response->redirect(Director::absoluteURL($dest), '302');
throw new HTTPResponse_Exception($response);
diff --git a/src/Model/Order.php b/src/Model/Order.php
index 7616326f..07c9764e 100644
--- a/src/Model/Order.php
+++ b/src/Model/Order.php
@@ -572,7 +572,7 @@ class Order extends DataObject implements EditableEcommerceObject
if ($modifiers->exists()) {
foreach ($modifiers as $modifier) {
if ($modifier->ShowForm()) {
- if (! isset($formsDone[$modifier->ClassName])) {
+ if (!isset($formsDone[$modifier->ClassName])) {
$formsDone[$modifier->ClassName] = true;
$form = $modifier->getModifierForm($optionalController, $optionalValidator);
if ($form) {
@@ -807,7 +807,7 @@ class Order extends DataObject implements EditableEcommerceObject
// we had to add the updateCMSFields hook.
$this->extend('updateCMSFieldsBefore', $fields);
$currentMember = Security::getCurrentUser();
- if (! $this->exists() || ! $this->StatusID) {
+ if (!$this->exists() || !$this->StatusID) {
$firstStep = DataObject::get_one(OrderStep::class);
$this->StatusID = $firstStep->ID;
$this->write();
@@ -825,7 +825,7 @@ class Order extends DataObject implements EditableEcommerceObject
//and only tryToFinaliseOrder if this is true....
// if ($_SERVER['REQUEST_URI'] === $this->CMSEditLink() || $_SERVER['REQUEST_URI'] === $this->CMSEditLink('edit')) {
$this->tryToFinaliseOrder();
- // }
+ // }
} else {
$this->init(true);
$this->calculateOrderAttributes(true);
@@ -1286,9 +1286,9 @@ class Order extends DataObject implements EditableEcommerceObject
if ($this->IsSubmitted()) {
user_error('Can not init an order that has been submitted', E_USER_NOTICE);
} elseif ($this->StatusID || $recalculate || self::get_needs_recalculating($this->ID)) {
- if (! $this->StatusID) {
+ if (!$this->StatusID) {
$createdOrderStatus = DataObject::get_one(OrderStep::class);
- if (! $createdOrderStatus) {
+ if (!$createdOrderStatus) {
user_error('No ordersteps have been created', E_USER_WARNING);
}
@@ -1313,18 +1313,18 @@ class Order extends DataObject implements EditableEcommerceObject
$modifiersToAdd = EcommerceConfig::get(Order::class, 'modifiers');
if (is_array($modifiersToAdd) && [] !== $modifiersToAdd) {
foreach ($modifiersToAdd as $numericKey => $className) {
- if (! in_array($className, $createdModifiersClassNames, true)) {
+ if (!in_array($className, $createdModifiersClassNames, true)) {
if (class_exists($className)) {
$modifier = new $className();
//only add the ones that should be added automatically
- if (! $modifier->DoNotAddAutomatically()) {
+ if (!$modifier->DoNotAddAutomatically()) {
if (is_a($modifier, OrderModifier::class)) {
$modifier->OrderID = $this->ID;
$modifier->Sort = $numericKey;
//init method includes a WRITE
$modifier->init();
//IMPORTANT - add as has_many relationship (Attributes can be a modifier OR an OrderItem)
- if(! $this->exists()) {
+ if(!$this->exists()) {
$this->write();
}
$this->Attributes()->add($modifier);
@@ -1388,7 +1388,7 @@ class Order extends DataObject implements EditableEcommerceObject
$myQueueObject = $queueObjectSingleton->getQueueObject($this);
if ($myQueueObject) {
if ($fromOrderQueue) {
- if (! $myQueueObject->InProcess) {
+ if (!$myQueueObject->InProcess) {
return;
}
} else {
@@ -1551,7 +1551,7 @@ class Order extends DataObject implements EditableEcommerceObject
$step = OrderStep::get_by_id($this->StatusID);
}
- if (! $step) {
+ if (!$step) {
$step = DataObject::get_one(
OrderStep::class,
null,
@@ -1559,11 +1559,11 @@ class Order extends DataObject implements EditableEcommerceObject
);
}
- if (! $step) {
+ if (!$step) {
$step = OrderStepCreated::create();
}
- if (! $step) {
+ if (!$step) {
user_error('You need an order step in your Database.');
}
@@ -1588,7 +1588,7 @@ class Order extends DataObject implements EditableEcommerceObject
$obj = $this->MyStep();
if ($obj->HideStepFromCustomer) {
$obj = OrderStep::get()->where('"OrderStep"."Sort" < ' . $obj->Sort . ' AND "HideStepFromCustomer" = 0')->Last();
- if (! $obj) {
+ if (!$obj) {
$obj = DataObject::get_one(OrderStep::class);
}
}
@@ -1621,7 +1621,7 @@ class Order extends DataObject implements EditableEcommerceObject
*/
public function IsInCart()
{
- return ! (bool) $this->IsSubmitted();
+ return !(bool) $this->IsSubmitted();
}
/**
@@ -1631,7 +1631,7 @@ class Order extends DataObject implements EditableEcommerceObject
*/
public function IsPastCart()
{
- return ! (bool) $this->IsInCart();
+ return !(bool) $this->IsInCart();
}
/**
@@ -1782,7 +1782,7 @@ class Order extends DataObject implements EditableEcommerceObject
public function IsAdminCancelled()
{
if ($this->IsCancelled()) {
- if (! $this->IsCustomerCancelled()) {
+ if (!$this->IsCustomerCancelled()) {
$admin = Member::get_by_id($this->CancelledByID);
if ($admin) {
if ($admin->IsShopAdmin()) {
@@ -1833,18 +1833,18 @@ class Order extends DataObject implements EditableEcommerceObject
} else {
$member = Security::getCurrentUser();
if ($member && $member->exists()) {
- if (! $member->IsShopAdmin()) {
+ if (!$member->IsShopAdmin()) {
$this->MemberID = $member->ID;
$this->write();
}
}
}
- if (! ($member && $member->exists())) {
+ if (!($member && $member->exists())) {
$member = $this->Member();
}
- if (! ($member && $member->exists())) {
+ if (!($member && $member->exists())) {
$member = new Member();
}
@@ -1866,7 +1866,7 @@ class Order extends DataObject implements EditableEcommerceObject
*/
public function CreateOrReturnExistingAddress($className = BillingAddress::class, $alternativeMethodName = '')
{
- if (! $this->exists()) {
+ if (!$this->exists()) {
$this->write();
}
$methodNames = [
@@ -1889,7 +1889,7 @@ class Order extends DataObject implements EditableEcommerceObject
$address = $this->{$methodName}();
}
- if (! $address) {
+ if (!$address) {
$address = new $className();
$member = $this->CreateOrReturnExistingMember();
if ($member && $member->exists()) {
@@ -1898,7 +1898,7 @@ class Order extends DataObject implements EditableEcommerceObject
}
if ($address) {
- if (! $address->exists()) {
+ if (!$address->exists()) {
$address->write();
}
@@ -1908,7 +1908,7 @@ class Order extends DataObject implements EditableEcommerceObject
}
if ($this->{$variableName} !== $address->ID) {
- if (! $this->IsSubmitted()) {
+ if (!$this->IsSubmitted()) {
$this->{$variableName} = $address->ID;
$this->write();
}
@@ -1983,7 +1983,7 @@ class Order extends DataObject implements EditableEcommerceObject
if ($this->IsSubmitted()) {
user_error('Can not set the currency after the order has been submitted', E_USER_NOTICE);
} else {
- if (! is_a($newCurrency, EcommerceConfigClassNames::getName(EcommerceCurrency::class))) {
+ if (!is_a($newCurrency, EcommerceConfigClassNames::getName(EcommerceCurrency::class))) {
$newCurrency = EcommerceCurrency::default_currency();
}
@@ -2094,11 +2094,11 @@ class Order extends DataObject implements EditableEcommerceObject
*/
public function getOrderAttributesByType($types)
{
- if (! is_array($types) && is_string($types)) {
+ if (!is_array($types) && is_string($types)) {
$types = [$types];
}
- if (! is_array($types)) {
+ if (!is_array($types)) {
user_error('wrong parameter (types) provided in Order::getOrderAttributesByTypes');
}
@@ -2133,7 +2133,7 @@ class Order extends DataObject implements EditableEcommerceObject
*/
public function Items($filterOrClassName = '')
{
- if (! $this->exists()) {
+ if (!$this->exists()) {
$this->write();
}
@@ -2236,7 +2236,7 @@ class Order extends DataObject implements EditableEcommerceObject
$modifiers = $this->Modifiers();
if ($modifiers->exists()) {
foreach ($modifiers as $modifier) {
- if (! $modifier->IsRemoved()) { //we just double-check this...
+ if (!$modifier->IsRemoved()) { //we just double-check this...
if (is_array($excluded) && in_array($modifier->ClassName, $excluded, true)) {
if ($stopAtExcludedModifier) {
break;
@@ -2322,10 +2322,10 @@ class Order extends DataObject implements EditableEcommerceObject
*/
public function canView($member = null)
{
- if ($this->overrideCanView && ! $this->IsArchived()) {
+ if ($this->overrideCanView && !$this->IsArchived()) {
return true;
}
- if (! $this->exists()) {
+ if (!$this->exists()) {
return true;
}
@@ -2423,7 +2423,7 @@ class Order extends DataObject implements EditableEcommerceObject
*/
public function LessSecureSessionID($size = 7, $start = null)
{
- if (! $start || $start < 0 || $start > (32 - $size)) {
+ if (!$start || $start < 0 || $start > (32 - $size)) {
$start = 0;
}
@@ -2518,7 +2518,7 @@ class Order extends DataObject implements EditableEcommerceObject
$submitErrors = $this->SubmitErrors();
- return ! ($submitErrors && $submitErrors->count());
+ return !($submitErrors && $submitErrors->count());
}
/**
@@ -2616,7 +2616,7 @@ class Order extends DataObject implements EditableEcommerceObject
$logs = $this->OrderStatusLogs();
if ($logs) {
foreach ($logs as $log) {
- if (! $log->InternalUseOnly) {
+ if (!$log->InternalUseOnly) {
$customerViewableOrderStatusLogs->push($log);
}
}
@@ -2644,7 +2644,7 @@ class Order extends DataObject implements EditableEcommerceObject
$email = $this->BillingAddress()->Email;
}
- if (! $email) {
+ if (!$email) {
if ($this->MemberID && $this->Member()) {
$email = $this->Member()->Email;
}
@@ -2680,7 +2680,7 @@ class Order extends DataObject implements EditableEcommerceObject
public function getEmailLink()
{
- if (! isset($_REQUEST['print'])) {
+ if (!isset($_REQUEST['print'])) {
if ($this->IsSubmitted()) {
$step = $this->MyStep();
@@ -2708,7 +2708,7 @@ class Order extends DataObject implements EditableEcommerceObject
public function getPrintLink()
{
- if (! isset($_REQUEST['print'])) {
+ if (!isset($_REQUEST['print'])) {
if ($this->IsSubmitted()) {
return Director::AbsoluteURL(OrderConfirmationPage::get_order_link($this->ID)) . '?print=1';
}
@@ -2747,7 +2747,7 @@ class Order extends DataObject implements EditableEcommerceObject
//important to recalculate! - recalculate = true
if ($this->IsSubmitted(true)) {
//add session ID if not added yet...
- if (! $this->SessionID) {
+ if (!$this->SessionID) {
$this->write();
}
@@ -2900,7 +2900,7 @@ class Order extends DataObject implements EditableEcommerceObject
if ($includeName) {
$by = _t('Order.BY', 'by');
- if (! $name) {
+ if (!$name) {
if ($this->BillingAddressID) {
$billingAddress = $this->BillingAddress();
if ($billingAddress && $billingAddress->exists()) {
@@ -2909,13 +2909,13 @@ class Order extends DataObject implements EditableEcommerceObject
}
}
- if (! $name) {
+ if (!$name) {
if ($this->MemberID) {
$member = $this->Member();
if ($member && $member->exists()) {
$memberName = $member->getName();
if ($memberName) {
- if (! trim((string) $memberName)) {
+ if (!trim((string) $memberName)) {
$memberName = _t('Order.ANONYMOUS', 'anonymous');
}
@@ -3034,7 +3034,7 @@ class Order extends DataObject implements EditableEcommerceObject
if ($items->exists()) {
foreach ($items as $item) {
if (is_a($item, $type)) {
- if(! empty($item->HasPhysicalDispatch)) {
+ if(!empty($item->HasPhysicalDispatch)) {
return true;
}
}
@@ -3309,7 +3309,7 @@ class Order extends DataObject implements EditableEcommerceObject
if ((EcommerceConfig::get(OrderAddress::class, 'use_shipping_address_for_main_region_and_country') && $countryCodes['Shipping'])
||
- (! $countryCodes['Billing'] && $countryCodes['Shipping'])
+ (!$countryCodes['Billing'] && $countryCodes['Shipping'])
) {
$code = $countryCodes['Shipping'];
} elseif ($countryCodes['Billing']) {
@@ -3459,7 +3459,7 @@ class Order extends DataObject implements EditableEcommerceObject
{
$currency = $this->CurrencyUsed();
if ($currency && $currency->exists()) {
- return ! $currency->IsDefault();
+ return !$currency->IsDefault();
}
return false;
@@ -3471,7 +3471,7 @@ class Order extends DataObject implements EditableEcommerceObject
*/
public function EnsureCorrectExchangeRate()
{
- if (! $this->IsSubmitted()) {
+ if (!$this->IsSubmitted()) {
$oldExchangeRate = $this->ExchangeRate;
$currency = $this->CurrencyUsed();
if ($currency && $currency->exists()) {
@@ -3635,7 +3635,7 @@ class Order extends DataObject implements EditableEcommerceObject
}
if ($withDetail) {
- if (! $this->HideStepFromCustomer) {
+ if (!$this->HideStepFromCustomer) {
$str .= ' (' . $this->MyStep()->Name . ')';
}
}
@@ -3675,7 +3675,7 @@ class Order extends DataObject implements EditableEcommerceObject
CartPage::class,
['ClassName' => CartPage::class]
);
- if (! $page) {
+ if (!$page) {
$page = DataObject::get_one(CheckoutPage::class);
}
}
@@ -3882,15 +3882,15 @@ class Order extends DataObject implements EditableEcommerceObject
protected function onBeforeWrite()
{
parent::onBeforeWrite();
- if (! $this->getCanHaveShippingAddress()) {
+ if (!$this->getCanHaveShippingAddress()) {
$this->UseShippingAddress = false;
}
- if (! $this->CurrencyUsedID) {
+ if (!$this->CurrencyUsedID) {
$this->CurrencyUsedID = EcommerceCurrency::default_currency_id();
}
- if (! $this->SessionID) {
+ if (!$this->SessionID) {
$generator = Injector::inst()->create(RandomGenerator::class);
$token = $generator->randomToken('sha1');
$this->SessionID = substr((string) $token, 0, 32);
@@ -3905,11 +3905,11 @@ class Order extends DataObject implements EditableEcommerceObject