VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: woogygun on August 15, 2012, 09:34:19 AM

Title: Featured Products Fixed Sort Order
Post by: woogygun on August 15, 2012, 09:34:19 AM
Hi there

Is it possible to edit the php of the featured products layout so that the products sort by a fixed order and remain that way, instead of everytime the page refreshes the featured items shuffling themselves around.

I'd like to sort by SKU. for example 001,002,003,004

and it must stay that way.
Title: Re: Featured Products Fixed Sort Order
Post by: cmb on October 09, 2012, 01:43:08 AM
Apparently the ordering for the Featured Products is set at line 406 of the \administrator\components\com_virtuemart\models\product.php file. You could override that file and then modify the code by replacing
$orderBy = 'ORDER BY RAND()';
with another $orderBy statement that includes a reference to the product_sku column of the <database-prefix>_virtuemart_products database table.

VirtueMart 2.0.12
Title: Re: Featured Products Fixed Sort Order
Post by: stemithy on March 20, 2013, 21:40:19 PM
Here's my solution:

I used the product URL field placing numbers 1 - 9 on the featured products I wanted to sort.  You could use any product specific field
I know it's a hack, but it's simple stable and only requires overriding a view:

Override the default_products.php view.  Just after "foreach ($this->products as $type => $productList ) {" (line 7)  Add this:

foreach ($productList as $psort) {
$pnew[$psort->product_url-1] = $psort;
}
ksort($pnew);

Then change
"foreach ( $productList as $product )" (line 26) 
-to-
"foreach ($pnew as $product ) {"

Hope this helps
Title: Re: Featured Products Fixed Sort Order
Post by: design609 on September 17, 2014, 12:54:19 PM
@stemithy
Thanks! worked for me.