In the product page i have a list of all reviews made by customers and I'm showing customer username, avatar and date with each review. The solution I'm using will result in a performance bottleneck. How can the code be improved?

    $_items = $this->getReviewsCollection()->getItems();
    foreach ($_items as $_review): ?>
    <div itemscope itemtype="http://schema.org/Review">
                    $customer_id = $_review->getCustomerId();
                    $customer_data = Mage::getModel('customer/customer')->load($customer_id);
                    $avatarURL = "customer" . $customer_data->getMedmaAvatar();
                    $username = $customer_data->getUsername();
                    $shortdate = $this->formatDate($_review->getCreatedAt(),'short');
            <div>content blablabla</div>
<?php endforeach; ?>

1 Answer 1


I think the easiest would be to get all customers and load them:

$customerIds = Mage::getResourceModel('review/review_collection')
$customerCollection = Mage::getResourceModel('customer/customer_collection')
    ->addAttributeToFilter('entity_id', array('in' => $customerIds));
$customer_data = $customerCollection->getItemById($_review->getCustomerId());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.