0

Actually we have two group of customers. Both are having ability to see different products. But in the product page at the reviews section, for both customers, for ratings they should be able to see the rating of both products compinely.

For example:

Main product sku is 'mainsku' -> it is for normal group of cutomers then Other product sku is 'mainsku_CGG' -> it is for special group of

In both products's rating. Customers should be able to the rating as combined and calculated percentage rating of both.

Means
mainsku->100% rating mainsku_CGG -> 80% rating

So in product page rating should be 90% (Average of two), and number of ratings also should be get added.

I don't know how to change the ratings collection here. Can anyone help here?

1 Answer 1

1

you can do it if you know the product ids of both

$reviews = Mage::getModel('review/review')->getResourceCollection()
    ->addStoreFilter(Mage::app()->getStore()->getId())
    ->addEntityFilter('product', $product_id)
    ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
    ->setDateOrder()
    ->addRateVotes();
    /**
     * Getting average of ratings/reviews
    */

    $avg = 0;
    $ratings = array();
    $reviewsss=array();
    if (count($reviews) > 0) 
    {
        $todalRevies=$reviews->getData();
        //$allreviews=array();
        foreach($todalRevies as $allreviews)
        {
            foreach ($reviews->getItems() as $review)
            {
                foreach( $review->getRatingVotes() as $vote )
                {
                    if($vote->getReviewId() ==$allreviews['review_id'])
                    {
                        $allreviews['rate']=$vote->getPercent()/20;
                    }
                    else 
                    {
                        $allreviews['rate']=0;
                    }

                    $ratings[] = $vote->getPercent();
                }

            }
            $reviewsss[]=$allreviews;
            $avg = array_sum($ratings)/count($ratings);
            $rate=$avg/20;
        }
    }

I hope this help you

3
  • But here, how to combine both product's rating?
    – SIBHI S
    Aug 11, 2015 at 6:48
  • Have to do the same for the second product and want to find the average?
    – SIBHI S
    Aug 11, 2015 at 6:49
  • yes you have to calculate for both and find the average Aug 11, 2015 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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