Hi all,
I have a content type "Store" that has a field with geographical lat/long. Then I have a view that is showing the Stores sorted by the distance from the current User position (from the most near to the most far).
What I'm trying to achieve is to take the 10 most near Stores, and then shows randomly only 2 of them.
Basically I want to have a block that shows only 2 Stores randomly, but doing the random only among the 10 most near Stores from user's current position.
Is there a way to do it? I tryed everything but no luck.
Thanks in advance!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drupaljunior created an issue. See original summary.

drupaljunior’s picture

Any solution for this?

Nikhilesh Gupta’s picture

Assigned: Unassigned » Nikhilesh Gupta
Nikhilesh Gupta’s picture

@drupaljunior

After achieving the 10 most near Stores, perform the following actions:

1) In the view block for pager select "Display a specified number of items" and specify the items as 2.

2) Next in the sort criteria select "Global: Random" asc/desc.

By this your block can get randomly 2 stores from 10.

drupaljunior’s picture

Hi Nikhilesh,

To achieve the "10 most near Stores" what I'm doing is:
- Sort Criteria --> Ascending by distance
- Display a specified number of items" = 10

Now how can I make your suggestions described at points 1) and 2) applied on top without overriding the conditions for "10 most near Stores"?

Many Thanks in advance.

Nikhilesh Gupta’s picture

This can achieved by passing the output of view as input to another view. You have created a view to get "10 most near stores". Now use this as the input of another view, in that new view you should use sort random and items as 2.

drupaljunior’s picture

Hi Nikhilesh,

Your explanation is clear from a Query point of view. I simply don't know where to click in view editor.

"This can achieved by passing the output of view as input to another view." - how can I do it?
"Now use this as the input of another view" - how can I do it?

Thanks.

Nikhilesh Gupta’s picture

You cannot do this with your view editor. Programatically get the first view by "views_get_view('machine_name')" to a variable, then pass the filters to it. Following is a sample approch

Ex : $view = views_get_view('machine_name');
$view->display['default']->display_options['filters']['field_pay_geolocation_distance']['value']['latitude'] = $latitude_details['latitude'];
$view->set_display('block');
$view->is_cacheable = FALSE;
$view->execute();

drupaljunior’s picture

Where to put this kind of code?

MustangGB’s picture

Status: Active » Closed (outdated)

Closing this as outdated to tidy up a bit around here. If you're still having problems with the latest release please create a new issue.