1

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?

<?php 
    $_items = $this->getReviewsCollection()->getItems();
    foreach ($_items as $_review): ?>
    <div itemscope itemtype="http://schema.org/Review">
        <ul>
          <li>
            <?php
                    $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>
          </li>
        </ul>
    </div>
<?php endforeach; ?>

1 Answer 1

1

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

$customerIds = Mage::getResourceModel('review/review_collection')
    ->getColumnValues('customer_id');
$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 that you have read and understand our privacy policy and code of conduct.

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