Jump to content
  • 0

How To Sort Products Based On Price


Jonathon

Question

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 :)

 
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

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)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...