@@ -403,7 +403,93 @@ public function finaliseAction()
403
403
404
404
#region V2
405
405
406
- // TODO: rename to searchOrdersAction?
406
+ public function customerAction ()
407
+ {
408
+ if (!$ this ->_authorise ()) {
409
+ return $ this ;
410
+ }
411
+
412
+ $ sections = explode ('/ ' , trim ($ this ->getRequest ()->getPathInfo (), '/ ' ));
413
+ $ customerId = $ sections [3 ];
414
+
415
+ $ customer = Mage::getModel ('customer/customer ' )->load ($ customerId );
416
+
417
+ if (!$ customer ->getEntityId ()) {
418
+ $ this ->getResponse ()
419
+ ->setBody (json_encode (null ))
420
+ ->setHttpResponseCode (200 )
421
+ ->setHeader ('Content-type ' , 'application/json ' , true );
422
+ return $ this ;
423
+ }
424
+
425
+ $ customerData = Mage::helper ('zendesk ' )->getCustomer ($ customer );
426
+
427
+ $ this ->getResponse ()
428
+ ->setBody (json_encode ($ customerData ))
429
+ ->setHttpResponseCode (200 )
430
+ ->setHeader ('Content-type ' , 'application/json ' , true );
431
+ return $ this ;
432
+ }
433
+
434
+ public function searchCustomersAction ()
435
+ {
436
+ if (!$ this ->_authorise ()) {
437
+ return $ this ;
438
+ }
439
+
440
+ $ req = $ this ->getRequest ();
441
+ $ isPost = $ req ->isPost ();
442
+
443
+ if (!$ isPost ) {
444
+ $ this ->getResponse ()
445
+ ->setHttpResponseCode (405 )
446
+ ->setHeader ('Content-type ' , 'application/json ' , true );
447
+ return $ this ;
448
+ }
449
+
450
+ $ customerKey = 'customer ' ;
451
+
452
+ $ filters = json_decode ($ req ->getRawBody ());
453
+ $ genericFilters = array ();
454
+
455
+ foreach ($ filters as $ key => $ val ) {
456
+ if ($ key == $ customerKey ) {
457
+ $ customerFilters = $ val ;
458
+ } else {
459
+ $ genericFilters [$ key ] = $ val ;
460
+ }
461
+ }
462
+
463
+ $ customerCollection = Mage::getModel ('customer/customer ' )->getCollection ();
464
+
465
+ // TODO does this bring back guest cutsomers
466
+ foreach ($ customerFilters as $ customerKey => $ customerValue ) {
467
+ $ customerCollection ->addFieldToFilter ($ customerKey , $ customerValue );
468
+ }
469
+
470
+ foreach ($ genericFilters as $ genericKey => $ genericValue ) {
471
+ $ customerCollection ->addFieldToFilter ($ genericKey , $ genericValue );
472
+ }
473
+
474
+ $ customerCollection ->load ();
475
+
476
+ $ urlModel = Mage::getModel ('adminhtml/url ' )->setStore ('admin ' );
477
+
478
+ $ customers = array ();
479
+
480
+ foreach ($ customerCollection as $ customer ) {
481
+ $ id = $ customer ->getId ();
482
+ $ customerDetails = Mage::getModel ('customer/customer ' )->load ($ id );
483
+ $ customers [] = Mage::helper ('zendesk ' )->getCustomer ($ customerDetails );
484
+ }
485
+
486
+ $ this ->getResponse ()
487
+ ->setBody (json_encode ($ customers ))
488
+ ->setHttpResponseCode (200 )
489
+ ->setHeader ('Content-type ' , 'application/json ' , true );
490
+ return $ this ;
491
+ }
492
+
407
493
public function searchOrdersAction ()
408
494
{
409
495
if (!$ this ->_authorise ()) {
@@ -424,22 +510,22 @@ public function searchOrdersAction()
424
510
$ customerKey = 'customer ' ;
425
511
426
512
$ filters = json_decode ($ req ->getRawBody ());
427
- $ generalFilters = array ();
513
+ $ genericFilters = array ();
428
514
429
515
foreach ($ filters as $ key => $ val ) {
430
516
if ($ key == $ productKey ) {
431
517
$ productFilters = $ val ;
432
518
} else if ($ key == $ customerKey ) {
433
519
$ customerFilters = $ val ;
434
520
} else {
435
- $ generalFilters [$ key ] = $ val ;
521
+ $ genericFilters [$ key ] = $ val ;
436
522
}
437
523
}
438
524
439
525
if ($ productFilters ) {
440
526
$ orders = Mage::helper ('zendesk ' )->getFilteredOrdersByProduct ($ customerFilters , $ productFilters );
441
527
} else {
442
- $ orders = Mage::helper ('zendesk ' )->getFilteredOrders ($ customerFilters , $ generalFilters );
528
+ $ orders = Mage::helper ('zendesk ' )->getFilteredOrders ($ customerFilters , $ genericFilters );
443
529
}
444
530
445
531
$ this ->getResponse ()
@@ -534,92 +620,5 @@ public function notesAction()
534
620
return $ this ;
535
621
}
536
622
537
- public function customerAction ()
538
- {
539
- if (!$ this ->_authorise ()) {
540
- return $ this ;
541
- }
542
-
543
- $ sections = explode ('/ ' , trim ($ this ->getRequest ()->getPathInfo (), '/ ' ));
544
- $ customerId = $ sections [3 ];
545
-
546
- $ customer = Mage::getModel ('customer/customer ' )->load ($ customerId );
547
-
548
- if (!$ customer ->getEntityId ()) {
549
- $ this ->getResponse ()
550
- ->setBody (json_encode (null ))
551
- ->setHttpResponseCode (200 )
552
- ->setHeader ('Content-type ' , 'application/json ' , true );
553
- return $ this ;
554
- }
555
-
556
- $ customerData = Mage::helper ('zendesk ' )->getCustomer ($ customer );
557
-
558
- $ this ->getResponse ()
559
- ->setBody (json_encode ($ customerData ))
560
- ->setHttpResponseCode (200 )
561
- ->setHeader ('Content-type ' , 'application/json ' , true );
562
- return $ this ;
563
- }
564
-
565
- public function searchCustomersAction ()
566
- {
567
- if (!$ this ->_authorise ()) {
568
- return $ this ;
569
- }
570
-
571
- $ req = $ this ->getRequest ();
572
- $ isPost = $ req ->isPost ();
573
-
574
- if (!$ isPost ) {
575
- $ this ->getResponse ()
576
- ->setHttpResponseCode (405 )
577
- ->setHeader ('Content-type ' , 'application/json ' , true );
578
- return $ this ;
579
- }
580
-
581
- $ customerKey = 'customer ' ;
582
-
583
- $ filters = json_decode ($ req ->getRawBody ());
584
- $ generalFilters = array ();
585
-
586
- foreach ($ filters as $ key => $ val ) {
587
- if ($ key == $ customerKey ) {
588
- $ customerFilters = $ val ;
589
- } else {
590
- $ generalFilters [$ key ] = $ val ;
591
- }
592
- }
593
-
594
- $ customerCollection = Mage::getModel ('customer/customer ' )->getCollection ();
595
-
596
- // TODO does this bring back guest cutsomers
597
- foreach ($ customerFilters as $ customerKey => $ customerValue ) {
598
- $ customerCollection ->addFieldToFilter ($ customerKey , $ customerValue );
599
- }
600
-
601
- foreach ($ generalFilters as $ generalKey => $ generalValue ) {
602
- $ customerCollection ->addFieldToFilter ($ generalKey , $ generalValue );
603
- }
604
-
605
- $ customerCollection ->load ();
606
-
607
- $ urlModel = Mage::getModel ('adminhtml/url ' )->setStore ('admin ' );
608
-
609
- $ customers = array ();
610
-
611
- foreach ($ customerCollection as $ customer ) {
612
- $ id = $ customer ->getId ();
613
- $ customerDetails = Mage::getModel ('customer/customer ' )->load ($ id );
614
- $ customers [] = Mage::helper ('zendesk ' )->getCustomer ($ customerDetails );
615
- }
616
-
617
- $ this ->getResponse ()
618
- ->setBody (json_encode ($ customers ))
619
- ->setHttpResponseCode (200 )
620
- ->setHeader ('Content-type ' , 'application/json ' , true );
621
- return $ this ;
622
- }
623
-
624
623
#endregion V2
625
624
}
0 commit comments