Advertisement:

Author Topic: Résolved: Number of ads in drop-down menu  (Read 958 times)

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 705
  • wmods.tk
Re: Number of ads in drop-down menu
« Reply #15 on: November 10, 2018, 10:13:19 am »
OK, too bad.
The result is the same, whether I use Internet Explorer, Firefox or Edge.
I have cleared the caches and delete cookies, but it does not work.
I have the ad number and this is the main one.
Thanks again.

I will check if there's other solution. Works on Chrome.

Regards.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Number of ads in drop-down menu
« Reply #16 on: November 10, 2018, 10:25:53 am »
Try on ubuntu or windows. It should make a difference.
I implemented 4 levels of categories starting with space and -
The second space space and --
etc.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Number of ads in drop-down menu
« Reply #17 on: November 10, 2018, 10:30:27 am »
Patric, your solution for search results category count, works only on 2 levels of category.
 I'll adapt it.
It also generates unset offset warnings.
You should use isset instead of comparison with '' or null.
When I'll adapt the code I'll post it.

Thanks anyway for the idea. I didn't work on osclass for almost a year now:)

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 705
  • wmods.tk
Re: Number of ads in drop-down menu
« Reply #18 on: November 10, 2018, 11:04:40 am »
Patric, your solution for search results category count, works only on 2 levels of category.
 I'll adapt it.
It also generates unset offset warnings.
You should use isset instead of comparison with '' or null.
When I'll adapt the code I'll post it.

Thanks anyway for the idea. I didn't work on osclass for almost a year now:)

Ok. :) You're welcome.

Regards.

Gilou26

  • Jr. Member
  • **
  • Posts: 70
Re: Number of ads in drop-down menu
« Reply #19 on: November 10, 2018, 11:09:10 am »
Hello marius,
The ideal would be that it works with all browsers.
Thanks for your intervention.
Regards

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Number of ads in drop-down menu
« Reply #20 on: November 10, 2018, 11:09:49 am »
Solution below.
« Last Edit: November 12, 2018, 07:10:23 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Number of ads in drop-down menu
« Reply #21 on: November 10, 2018, 11:10:33 am »
Hello marius,
The ideal would be that it works with all browsers.
Thanks for your intervention.
Regards

the space - solution will work on all.
space -
spacespace --
space space space ---

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Number of ads in drop-down menu
« Reply #22 on: November 10, 2018, 11:19:22 am »
Patric.
osc_has_items() returns only the first 20 results..... Any ideea how to overcome this?

edit:
I found this but it's not ok because for every search you have to remake the search just to get the stats...
https://forums.osclass.org/general-help/all-search-resut-id/msg62295/#msg62295
« Last Edit: November 10, 2018, 02:59:35 pm by marius-ciclistu »

Gilou26

  • Jr. Member
  • **
  • Posts: 70
Re: Number of ads in drop-down menu
« Reply #23 on: November 10, 2018, 11:41:34 am »
Marius,
I have no problem with the number of ads. Patrick's solution works.
It's with style that it does not work (bold and italic)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Number of ads in drop-down menu
« Reply #24 on: November 10, 2018, 11:52:41 am »
In my case, on ubuntu and Opera and Chromium the bold works for example. In firefox it doesn't.

Regarding my discussion with Patric, it's about the rafine category in searchpage. Its solution works in main seachbar.

Gilou26

  • Jr. Member
  • **
  • Posts: 70
Re: Number of ads in drop-down menu
« Reply #25 on: November 10, 2018, 12:01:58 pm »
Yes it works with Chrome.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Number of ads in drop-down menu
« Reply #27 on: November 12, 2018, 01:32:00 am »
 SOLUTION for displaying search result categories stats (it includes part of Patric's solution):
Tested and updated.
1. add this to the end of bender's functions.php

Code: [Select]
function mc_get_search_categories_stats()
{
    $categoryItems = array();
    $getcategoriesStats = false;
   
    foreach(Params::getParamsAsArray() as $param => $value) {
    if (in_array($param, array('page', 'sOrder', 'iOrderType', 'sCategory', 'bPic'), true) === false) {
    $getcategoriesStats = true;
    break;
    }
    }
   
    if ($getcategoriesStats === true) {
        $actualSearch = osc_search();
        $conditions = (array) json_decode($actualSearch->toJson());
        $conditions['limit_init']        = 0;
        $conditions['results_per_page']  = 500;
        $conditions['aCategories'] = array();
        $categoryStatsSearch = new Search();
        $categoryStatsSearch->setJsonAlert($conditions);
        $categoryStatsSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.fk_i_category_id');
        $categoryStatsSearch->addField('COUNT('.DB_TABLE_PREFIX.'t_item.pk_i_id) as category_num_items_search');   
        $categoryStats = $categoryStatsSearch->doSearch(false, true);
        unset($categoryStatsSearch);
       
        foreach($categoryStats as $x){
            $categoryItems[$x['fk_i_category_id']] = $x['category_num_items_search'];
        }

        $categorySearch = new Category();
        foreach ($categorySearch->listAll() as $category){
            $categoryParent[$category['pk_i_id']] = $category['fk_i_parent_id'];
        }

        foreach($categoryItems as $catId => $nr){
            $id = $catId;
           
            while($id !== null) {
                $id = $categoryParent[$id];
               
                if($id !== null) {
                    if(isset($categoryItems[$id]) === false) {
                        $categoryItems[$id] = $nr;
                    } else {
                        $categoryItems[$id] += $nr;
                    }
                }
            }
        }
    }
   
    return $categoryItems;
}


2.  replace  bender_sidebar_category_search and bender_print_sidebar_category_search functions from the same file with

Code: [Select]
function bender_sidebar_category_search($catId = null)
{
    $aCategories = array();
    if($catId==null) {
        $aCategories[] = Category::newInstance()->findRootCategoriesEnabled();
    } else {
        // if parent category, only show parent categories
        $aCategories = Category::newInstance()->toRootTree($catId);
        end($aCategories);
        $cat = current($aCategories);
        // if is parent of some category
        $childCategories = Category::newInstance()->findSubcategoriesEnabled($cat['pk_i_id']);
        if(count($childCategories) > 0) {
            $aCategories[] = $childCategories;
        }
    }

    if(count($aCategories) == 0) {
        return "";
    }
   
    bender_print_sidebar_category_search($aCategories, $catId, 0, mc_get_search_categories_stats());
}

function bender_print_sidebar_category_search($aCategories, $current_category = null, $i = 0, $categoryItems = array())
{
    $class = '';
   
    if(!isset($aCategories[$i])) {
        return null;
    }

    if($i===0) {
        $class = 'class="category"';
    }

    $c   = $aCategories[$i];
    $i++;
    if(!isset($c['pk_i_id'])) {
        echo '<ul '.$class.'>';
        if($i==1) {
            echo '<li><a href="'.osc_esc_html(osc_update_search_url(array('sCategory'=>null, 'iPage'=>null))).'">'.__('All categories', 'bender')."</a></li>";
        }
        foreach($c as $key => $value) {
            $updateSearchUrl = array('sCategory'=> $value['pk_i_id'], 'iPage'=>null);
            if (osc_price_enabled_at_items() && !osc_item_category_price_enabled($value['pk_i_id'])) {
                $updateSearchUrl['sPriceMin'] = null;
                $updateSearchUrl['sPriceMax'] = null;
                $updateSearchUrl['currency'] = null;
            }
            ?>
            <li>
                <a id="cat_<?php echo osc_esc_html($value['pk_i_id']);?>" href="<?php echo osc_esc_html(osc_update_search_url($updateSearchUrl)); ?>">
                    <?php if(isset($current_category) && $current_category == $value['pk_i_id']){ echo '<strong>'.$value['s_name']. (($categoryItems === array()) ? ($value['i_num_items'] > ' ('.$value['i_num_items'].')' '') : (isset($categoryItems[$value['pk_i_id']]) ? ' ('.$categoryItems[$value['pk_i_id']].')' '')) .'</strong>'; }
                    else{ echo 
$value['s_name']. (($categoryItems === array()) ? ($value['i_num_items'] > ' ('.$value['i_num_items'].')' '') : (isset($categoryItems[$value['pk_i_id']]) ? ' ('.$categoryItems[$value['pk_i_id']].')' '')); } ?>

                </a>

            </li>
        <?php
        
}
        if(
$i==1) {
            echo 
"</ul>";
        } else {
            echo 
"</ul>";
        }
    } else { 
?>

        <ul <?php echo $class;?>>
            <?php if($i==1) { ?>
                <li><a href="<?php echo osc_esc_html(osc_update_search_url(array('sCategory'=>null'iPage'=>null))); ?>"><?php _e('All categories''bender'); ?></a></li>
            <?php }
            
            
$updateSearchUrl = array('sCategory'=> $c['pk_i_id'], 'iPage'=>null);
            if (
osc_price_enabled_at_items() && !osc_item_category_price_enabled($c['pk_i_id'])) {
                
$updateSearchUrl['sPriceMin'] = null;
                
$updateSearchUrl['sPriceMax'] = null;
                
$updateSearchUrl['currency'] = null;
            } 
?>

            <li>
                <a id="cat_<?php echo osc_esc_html($c['pk_i_id']);?>" href="<?php echo osc_esc_html(osc_update_search_url($updateSearchUrl)); ?>">
                    <?php if(isset($current_category) && $current_category == $c['pk_i_id']){ echo '<strong>'.$c['s_name']. (($categoryItems === array()) ? ($c['i_num_items'] > ' ('.$c['i_num_items'].')' '') : (isset($categoryItems[$c['pk_i_id']]) ? ' ('.$categoryItems[$c['pk_i_id']].')' '')) .'</strong>'; }
                    else{ echo 
$c['s_name']. (($categoryItems === array()) ? ($c['i_num_items'] > ' ('.$c['i_num_items'].')' '') : (isset($categoryItems[$c['pk_i_id']]) ? ' ('.$categoryItems[$c['pk_i_id']].')' '')); } ?>

                </a>
                <?php bender_print_sidebar_category_search($aCategories$current_category$i$categoryItems); ?>
            </li>
            <?php if($i==1) { ?>
            <?php ?>
        </ul>
    <?php
    
}

}


EDIT
But when the param bPic (seach only ads with picture is checked) => 2 group by statements and the results are wrong...
SOLUTION https://forums.osclass.org/development/get-number-of-itemscategory-from-search/msg165650/#msg165650
« Last Edit: November 18, 2018, 12:33:20 am by marius-ciclistu »

patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 705
  • wmods.tk
Re: Number of ads in drop-down menu
« Reply #28 on: November 17, 2018, 05:12:56 pm »
Sorry, I've been off the forum for a while... Does that code then fully work or you need help?
I must say that you did a great job, I provided a small part of the code but this is just WOW. ;)

Regards.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1618
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Number of ads in drop-down menu
« Reply #29 on: November 18, 2018, 12:31:31 am »
Problem solved. The only with picture field is ignored in category stats.