Skip to content

Commit fc937ec

Browse files
committed
Merge branch 'release/3.0.0' of https://github.com/agnostack/magento_extension into release/3.0.0
2 parents 9dbabdf + 7270a84 commit fc937ec

File tree

2 files changed

+97
-97
lines changed

2 files changed

+97
-97
lines changed

src/app/code/community/Zendesk/Zendesk/Helper/Data.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ protected function formatPrice($price, $currency)
456456
protected function formatCustomer($order)
457457
{
458458
$isGuest = (bool)$order->getCustomerIsGuest();
459-
$id = $order->getCustomerId();
459+
$id = $order->getCustomerId(); // TODO: should this be customerId or entity id??
460460
$email = $order->getCustomerEmail();
461461
$customer = array();
462462

@@ -552,6 +552,7 @@ public function getOrderDetailBasic($order)
552552
$currency = $order->getOrderCurrencyCode();
553553
$shippingAddress = $order->getShippingAddress();
554554
$shippingWithTax = $order->getShippingInclTax();
555+
$shippingMethod = $order->getShippingMethod();
555556

556557
$orderInfo = array(
557558
'id' => $order->getIncrementId(),
@@ -610,14 +611,14 @@ public function getOrderDetailBasic($order)
610611
);
611612
}
612613

613-
if ($shippingWithTax) {
614+
if ($shippingWithTax && $shippingMethod) {
614615
$shippingTax = $order->getShippingTaxAmount();
615616
$shippingItem = array(
616617
'type' => 'custom_item',
617618
'id' => 'shipping--'.$order->getEntityId(),
618619
'product_id' => $order->getEntityId(),
619620
'name' => 'shipping--'.$order->getShippingDescription(),
620-
'sku' => $order->getShippingMethod(),
621+
'sku' => $shippingMethod,
621622
'quantity' => 1,
622623
'refunded' => 0,
623624
'meta' => array(
@@ -759,7 +760,7 @@ public function getCustomer($customer)
759760
return $info;
760761
}
761762

762-
public function getFilteredOrders($customerFilters, $generalFilters)
763+
public function getFilteredOrders($customerFilters, $genericFilters)
763764
{
764765
// Get a list of all orders for the given email address
765766
// This is used to determine if a missing customer is a guest or if they really aren't a customer at all
@@ -769,8 +770,8 @@ public function getFilteredOrders($customerFilters, $generalFilters)
769770
$orderCollection->addFieldToFilter('customer_'.$customerKey, $customerValue);
770771
}
771772

772-
foreach($generalFilters as $generalKey => $generalValue) {
773-
$orderCollection->addFieldToFilter($generalKey, $generalValue);
773+
foreach($genericFilters as $genericKey => $genericValue) {
774+
$orderCollection->addFieldToFilter($genericKey, $genericValue);
774775
}
775776

776777
$orders = array();

src/app/code/community/Zendesk/Zendesk/controllers/ApiController.php

Lines changed: 90 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,93 @@ public function finaliseAction()
403403

404404
#region V2
405405

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+
407493
public function searchOrdersAction()
408494
{
409495
if(!$this->_authorise()) {
@@ -424,22 +510,22 @@ public function searchOrdersAction()
424510
$customerKey = 'customer';
425511

426512
$filters = json_decode($req->getRawBody());
427-
$generalFilters = array();
513+
$genericFilters = array();
428514

429515
foreach($filters as $key => $val) {
430516
if($key == $productKey) {
431517
$productFilters = $val;
432518
} else if($key == $customerKey) {
433519
$customerFilters = $val;
434520
} else {
435-
$generalFilters[$key] = $val;
521+
$genericFilters[$key] = $val;
436522
}
437523
}
438524

439525
if($productFilters) {
440526
$orders = Mage::helper('zendesk')->getFilteredOrdersByProduct($customerFilters, $productFilters);
441527
} else {
442-
$orders = Mage::helper('zendesk')->getFilteredOrders($customerFilters, $generalFilters);
528+
$orders = Mage::helper('zendesk')->getFilteredOrders($customerFilters, $genericFilters);
443529
}
444530

445531
$this->getResponse()
@@ -534,92 +620,5 @@ public function notesAction()
534620
return $this;
535621
}
536622

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-
624623
#endregion V2
625624
}

0 commit comments

Comments
 (0)