Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9008725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:00:41+00:00 2026-06-16T02:00:41+00:00

I tried to sort the product list in magento by geolocation data with the

  • 0

I tried to sort the product list in magento by geolocation data with the help of the following article : https://developers.google.com/maps/articles/phpsqlsearch_v3?hl=hu-HU .

I overrided the Mage_Catalog_Block_Product_List in my module so that I can reach this line of code :

$this->_productCollection = $layer->getProductCollection();

Once I have the _productCollection object, I want to add the formula as a “virtual” attribute “distance” so that I can sort the query with it. Here’s what I have in mind :

$this->_productCollection = $layer->getProductCollection()
->addAttributeToSelect('distance','I insert my custom formula here')
->addAttributeToSort('distance','DESC');

I know the API’s not made to handle that sort of syntax but I think it could help people get the idea.

Here’s the formula I wanna add:

SELECT ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) *
cos( radians( lng ) – radians(-122) ) + sin( radians(37) ) * sin(
radians( lat ) ) ) ) AS distance

Any idea how to do it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:00:42+00:00Added an answer on June 16, 2026 at 2:00 am

    If lat and lng are attributes of your product, you can use addExpressionAttributeToSelect():

    $this->_productCollection
    ->addExpressionAttributeToSelect('distance', '(select ... {{lat}} ... {{lng}} ... )', array('lat'=>'lat', 'lng'=>'lng'));
    

    In the custom select query, lat and lng need to be enclosed in double brackets (as shown). Make sure your select statement is within parentheses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data with the following format: foo<tab>1.00<space>1.33<space>2.00<tab>3 Now I tried to sort
Tried following the instructions here: How to use Google app engine with my own
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
How to sort string names in array on ascending order . I tried sort
I tried to sort these number with Unix sort, but it doesn't seem to
I tried to search and found this: Sort an array by a child array's
The Google places ( google.maps.places.Autocomplete ) class that is available to use by linking
I have a list of names, that contain this: <td><%= product.date %></td> and it
I am using Magento 1.4.0.1. I am trying to get my product listing pages
I'm tring to sort an arraylist of String alphabetically, I tried everything, from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.