News:

Support the VirtueMart project and become a member

Main Menu

Sort products based on how many sold

Started by Kuubs, May 12, 2020, 11:16:20 AM

Previous topic - Next topic

Kuubs

Hello,

I am trying to display a couple of products on my category page, including all the subcategory products, and then show only the 12 most sold products. But I don't know how to sort by amount sold. Can someone help me out?

This is the code i use to get all the products including sub categories:


$productModel = VmModel::getModel('Product');
foreach($this->category->children as $child){
$productsChildren = array();
$productsChildren[$child->category_name]['products'] = $productModel->getProductListing(false, false, true, true, false, true, $child->virtuemart_category_id, false, 0);
$productModel->addImages($productsChildren[$child->category_name]['products']);

}


How do I amke sure to only get the most sold?

jenkinhill

I'd use the VirtueMart Products module using the Best Sales display option.  If you want to bake it yourself look at the code used there.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Kuubs

Quote from: jenkinhill on May 12, 2020, 13:03:47 PM
I'd use the VirtueMart Products module using the Best Sales display option.  If you want to bake it yourself look at the code used there.

That was indeed my thought as well, but unfortunately it does not display products from child categories as well. So I need to make it my own I guess.

I checked the code but I cannot seem to find it, can you point out where its located?