Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customers API : Filter order collection by customer ID for performance cause #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,26 @@ public function customersAction()

$sections = explode('/', trim($this->getRequest()->getPathInfo(), '/'));
$email = $sections[3];

// Get a list of all orders for the given email address
// This is used to determine if a missing customer is a guest or if they really aren't a customer at all
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('customer_email', array('eq' => array($email)));
$orders = array();
if($orderCollection->getSize()) {
foreach($orderCollection as $order) {
$orders[] = Mage::helper('zendesk')->getOrderDetail($order);
}
}
$websiteId = Mage::app()->getWebsite()->getId();

// Try to load a corresponding customer object for the provided email address
$customer = Mage::helper('zendesk')->loadCustomer($email);

// if the admin site has a custom URL, use it
$urlModel = Mage::getModel('adminhtml/url')->setStore('admin');
$customer = Mage::helper('zendesk')->loadCustomer($email, $websiteId);

if($customer && $customer->getId()) {
// Get a list of all orders for the given customer ID
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('customer_id', array('eq' => array($customer->getId())));
$orders = array();

// if the admin site has a custom URL, use it
$urlModel = Mage::getModel('adminhtml/url')->setStore('admin');

if($orderCollection->getSize()) {
foreach($orderCollection as $order) {
$orders[] = Mage::helper('zendesk')->getOrderDetail($order);
}
}

$info = array(
'guest' => false,
'id' => $customer->getId(),
Expand All @@ -180,6 +181,17 @@ public function customersAction()
}

} else {
// Get a list of all orders for the given email address
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('customer_email', array('eq' => array($email)));
$orders = array();

if($orderCollection->getSize()) {
foreach($orderCollection as $order) {
$orders[] = Mage::helper('zendesk')->getOrderDetail($order);
}
}

if(count($orders) == 0) {
// The email address doesn't even correspond with a guest customer
$this->getResponse()
Expand Down