Jump to content
  • 0

How To Sort Products Based On Price


Question

Posted

What I want to do:

 

Sort products based on price. yes there can be multi prices per item but in my case the prices[0] for all products suites my needs for ordering.

 

What I have tried

function compareProducts($a, $B)
{
      return $a['pricing'][0]['price'] - $b['pricing'][0]['price'];
}

$packages = usort($packages, ' compareProducts');

 

But this is not chaning the order.  Or can I change this in the Controler, with a order by statement as this would be the correct place to change this.

 

Thanks :)

 

1 answer to this question

Recommended Posts

  • 0
Posted

Where are you trying to sort packages?

 

Packages on the order form are shown within their package group. Packages within a package group can be sorted in the admin interface under [Packages] -> [Groups], clicking a package group table row, and clicking+dragging the package table rows around relative to each other.

 

Sorting the packages by price may not be working because of your comparison function. It is best if the comparison function return an integer of 3 possible values: -1 ($a > $B), 0 ($a == $B), or 1 ($a < $B)

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...