Osclass Support Forums

Osclass plugin support => Business Profile Plugin => Topic started by: Cephas on October 24, 2022, 02:54:01 AM

Title: Random ordering of business profiles
Post by: Cephas on October 24, 2022, 02:54:01 AM
Hello,

The business profiles on my home page show the latest business profile first. How can I order them randomly?
Title: Re: Random ordering of business profiles
Post by: MB Themes on October 24, 2022, 02:58:36 PM
Go to model/ModelBPR.php and search for "public function getSellers"

You have different order methods here, like:
Code: [Select]
$this->dao->orderby('uv.i_items DESC');
$this->dao->orderby('b.pk_i_id DESC');
Title: Re: Random ordering of business profiles
Post by: Ivan Kataev on October 26, 2022, 10:57:31 AM

What needs to be changed here?
Quote

// GET ALL SELLERS
public function getSellers($enabled = -1, $verified = -1, $type = -1, $limit = array(), $pattern = '', $city = '', $category = '', $order = 'RANDOM', $ids = array()) {
  $this->dao->select('b.*');
  $this->dao->from($this->getTable_bp() . ' as b');

  if($enabled <> -1) {
    $this->dao->where('b.b_enabled', $enabled);
  }

  if($verified <> -1) {
    $this->dao->where('b.b_verified', $verified);
  }

  if($type <> -1) {
    $this->dao->where('b.i_type', $type);
  }

  if($order == 'RANDOM' && is_array($ids) && !empty($ids)) {
    $ids = implode(',', $ids);
    $this->dao->where('b.pk_i_id in (' . $ids . ')');
  }

  if($order == 'NEW') {
    $this->dao->orderby('b.pk_i_id DESC');
  }

  if($order == 'ITEMS') {
    $this->dao->join($this->getTable_user() . ' as uv', '(b.fk_i_user_id = uv.pk_i_id)', 'INNER');
    $this->dao->orderby('uv.i_items DESC');
  }

 
Title: Re: Random ordering of business profiles
Post by: MB Themes on October 26, 2022, 11:06:53 AM
Change
Code: [Select]
    $this->dao->orderby('b.pk_i_id DESC');

To whatever you need.
Title: Re: Random ordering of business profiles
Post by: Ivan Kataev on October 26, 2022, 11:39:38 AM
Strange, the changes are not showing up.
Title: Re: Random ordering of business profiles
Post by: Hugo on October 26, 2022, 01:54:48 PM
Have you cleared the cache and CDN?
Title: Re: Random ordering of business profiles
Post by: Ivan Kataev on October 27, 2022, 01:07:17 PM
Have you cleared the cache and CDN?
Yes.
Title: Re: Random ordering of business profiles
Post by: Brandso on October 27, 2022, 07:10:38 PM
Strange, the changes are not showing up.


Thanks for asking this question and Thanks to MB Themes for showing the path.
Even I was thinking this for a while but forgot to ask this question here.
So, if you are using Epsilon theme you can try the following as I am not sure if it works with any other themes.


Replace this code
Code: [Select]
    $this->dao->orderby('b.pk_i_id DESC');


With this code
Code: [Select]
    $this->dao->orderby('rand()','b.pk_i_id');
Title: Re: Random ordering of business profiles
Post by: Ivan Kataev on October 28, 2022, 06:37:38 AM
Strange, the changes are not showing up.


Thanks for asking this question and Thanks to MB Themes for showing the path.
Even I was thinking this for a while but forgot to ask this question here.
So, if you are using Epsilon theme you can try the following as I am not sure if it works with any other themes.


Replace this code
Code: [Select]
    $this->dao->orderby('b.pk_i_id DESC');


With this code
Code: [Select]
    $this->dao->orderby('rand()','b.pk_i_id');

This also works in Delta. But only in the widget on the main page. On the company page sorting from old to new.
Title: Re: Random ordering of business profiles
Post by: MB Themes on October 28, 2022, 01:40:32 PM
One function in model holds multiple scenarios of plugin.
There are multiple orderby functions based on type
Title: Re: Random ordering of business profiles
Post by: Brandso on October 28, 2022, 07:36:11 PM
Strange, the changes are not showing up.


Thanks for asking this question and Thanks to MB Themes for showing the path.
Even I was thinking this for a while but forgot to ask this question here.
So, if you are using Epsilon theme you can try the following as I am not sure if it works with any other themes.


Replace this code
Code: [Select]
    $this->dao->orderby('b.pk_i_id DESC');


With this code
Code: [Select]
    $this->dao->orderby('rand()','b.pk_i_id');

This also works in Delta. But only in the widget on the main page. On the company page sorting from old to new.

Hi,
What I did is just created a new function

Just Below

Code: [Select]
if($order == 'NEW') {
    $this->dao->orderby('rand()','b.pk_i_id');
  }

I created

Code: [Select]
if($order == '') {
    $this->dao->orderby('rand()','b.pk_i_id');
  }

In the above code I just removed NEW and kept 'Apostrophe'

It worked for me. But its good that the developers of this plugin confirm if its correct because I am not sure if this will affect the plugins functionality anyhow.
Title: Re: Random ordering of business profiles
Post by: MB Themes on October 30, 2022, 11:46:12 AM
It looks good.
It only can affect ordering in front/backoffice.
You can always see current ordering by reviewing SQL queries
Title: Re: Random ordering of business profiles
Post by: Ivan Kataev on October 31, 2022, 10:35:28 AM
Strange, the changes are not showing up.


Thanks for asking this question and Thanks to MB Themes for showing the path.
Even I was thinking this for a while but forgot to ask this question here.
So, if you are using Epsilon theme you can try the following as I am not sure if it works with any other themes.


Replace this code
Code: [Select]
    $this->dao->orderby('b.pk_i_id DESC');


With this code
Code: [Select]
    $this->dao->orderby('rand()','b.pk_i_id');

This also works in Delta. But only in the widget on the main page. On the company page sorting from old to new.

Hi,
What I did is just created a new function

Just Below

Code: [Select]
if($order == 'NEW') {
    $this->dao->orderby('rand()','b.pk_i_id');
  }

I created

Code: [Select]
if($order == '') {
    $this->dao->orderby('rand()','b.pk_i_id');
  }

In the above code I just removed NEW and kept 'Apostrophe'

It worked for me. But its good that the developers of this plugin confirm if its correct because I am not sure if this will affect the plugins functionality anyhow.

Thanks! This is what you need!
Title: Re: Random ordering of business profiles
Post by: Hugo on April 17, 2023, 06:08:59 PM
Hi,

I would also like to change the order (randomize) of the companies on the "/companies" page.

However i can't find the file where you made the above mentioned changes in the code.

Could someone inform me in which file this needs to be changed?
Title: Re: Random ordering of business profiles
Post by: MB Themes on April 17, 2023, 07:06:53 PM
Its model/ModelBPR.php, there is general function for profiles search
Title: Re: Random ordering of business profiles
Post by: lbsib on May 03, 2023, 09:39:29 PM
For sorting on mainpage (main.php) use this code (example from Epsilon):

Code: [Select]
<div class="business-box">
              <?php echo bpr_companies_block(eps_param('company_home_count'), 'RANDOM'); ?>

it is usually set to 'NEW'

So it's better for update-ability of BPR Plugin if edited in a child theme.