VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: JLinker on June 01, 2015, 00:12:41 AM

Title: get product ratings from product id
Post by: JLinker on June 01, 2015, 00:12:41 AM
Hi,

I'm in VM 3.0.8, trying to pull a list of reviews by providing the product id.
The only function I've found which could do this is the following one.
File administrator/components/com_virtuemart/models/ratings.php line 174, there is the following function:

function getRatingByProduct($product_id,$onlyPublished=true){
    $q = 'SELECT * FROM `#__virtuemart_ratings` WHERE `virtuemart_product_id` = "'.(int)$product_id.'" ';
if($onlyPublished){
$q .= 'AND `published`="1" ';
}
$db = JFactory::getDBO();
$db->setQuery($q);
return $db->loadObject();
    }


The problem is that it returns only one record, because of $db->loadObject();
Shouldn't it return a $db->loadObjectList()?

If it's a bug, has the issue already been addressed?
Thanks a lot


Title: Re: get product ratings from product id
Post by: JLinker on June 11, 2015, 10:36:25 AM
hem hem...?!?
Title: Re: get product ratings from product id
Post by: PRO on June 11, 2015, 16:00:12 PM
do you want ratings? or reviews?

They are different

you want the text reviews right?

also: where are you trying to display them?
Title: Re: get product ratings from product id
Post by: Milbo on June 11, 2015, 22:19:43 PM
I think you missed just getReviewsByProduct

$ratingModel = VmModel::getModel('Ratings');
$productrating = $ratingModel->getReviewsByProduct($product->virtuemart_product_id);

I just notice it is missing the publish param