Jump to content

Pagination does not work after upgrade to 6.5.0


Claudia

Recommended Posts

Lines 1785 - 1864

 public function searchCatalogue($search_data = null, $page = 1, $per_page = 10, $search_mode = 'elastic')
    {
        $per_page = (!is_numeric($per_page) || $per_page < 1) ? 10 : $per_page;
$GLOBALS['debug']->debugMessage('At '.__METHOD__.', line ('.__LINE__.'), $page is '.$page.' and $per_page is '.$per_page);

   if (strtolower($page) != 'all') {
            $page = (is_numeric($page)) ? $page : 1;
            $limit = sprintf('LIMIT %d OFFSET %d', (int)$per_page, $per_page*($page-1));
        } else {
            $limit = 'LIMIT 100';
        }
        $GLOBALS['debug']->debugMessage('At '.__METHOD__.', line ('.__LINE__.'), $page is '.$page.' and $per_page is '.$per_page);
        $original_search_data = $search_data;

        /*    Allow plugins to add to conditions and joins or change the search_data
            Where conditions may be added to the $where variable and must be self contained (e.g. no AND prefix or suffix) since they will be ANDed together below
            $where[] = "I.price > 100";
            Joins may be added to the $joins variable - keep in mind the need for unique table aliases as appropriate
            $joins[] = "`plugin_myPlugin` as P ON P.`product_id`=I.`product_id` AND P.`my_field`='some_value'";
            The only guaranteed table alias is I for CubeCart_inventory
            G for CubeCart_pricing_group
            CI for CubeCart_category_index
            C for CubeCart_category
        */
        if($search_mode == 'elastic') {
            if($GLOBALS['config']->get('config', 'elasticsearch')=='1') {
                $es = new ElasticsearchHandler;
                $es->query($search_data, false);
                $result = $es->search($page, $per_page);
                $pids = array();
            
                if($result) {
                    foreach($result["hits"]["hits"] as $hit) {
                        array_push($pids, $hit['_id']);
                    }
                }
                $this->_category_count  = $result["hits"]["total"]["value"];
                if(!empty($pids)) {
                    $this->_category_products = $GLOBALS['db']->select('CubeCart_inventory', false, array('product_id' => $pids));
                    $this->_sort_by_relevance = true;
                } else {
                    $this->_elasticsearch = false;
                    return $this->searchCatalogue($original_search_data, 1, $per_page, 'fulltext');  
                }
            } else {
                return $this->searchCatalogue($original_search_data, 1, $per_page, 'fulltext');
            }
            
        } else {
            $where = array();
            $joins = array();
            foreach ($GLOBALS['hooks']->load('class.catalogue.pre_search') as $hook) {
                include $hook;
            }

            $sale_mode = $GLOBALS['config']->get('config', 'catalogue_sale_mode');

            if ($sale_mode == 2) {
                $sale_percentage = $GLOBALS['config']->get('config', 'catalogue_sale_percentage');
            }
            $user = (array)$GLOBALS['user']->get();
            $group_id = 'WHERE group_id = 0';
            if (($memberships = $GLOBALS['user']->getMemberships()) !== false) {
                $group_id = 'WHERE ';
                foreach ($memberships as $membership) {
                    $group_id .= 'group_id = '.$membership['group_id'].' OR ';
                }
                $group_id = substr($group_id, 0, -4);
            }

            if (strtolower($page) != 'all') {
                $page = (is_numeric($page)) ? $page : 1;
                $limit = sprintf('LIMIT %d OFFSET %d', (int)$per_page, $per_page*($page-1));
            } else {
                $limit = 'LIMIT 100';
            }
            
            // Presence of a join is similar to presence of a search keyword
            if (!empty($joins) || is_array($search_data)) {

Link to comment
Share on other sites

There is rogue code at your lines 1809-1833 (and maybe one other line). The new code to use ElasticSearch does not belong here. It belongs, in fact, directly after the last line you posted above.

Your line 1833 (one of the rogue lines of code) starts an else block of code. Therefore, there is probably a closing parenthesis further down the script that ends this block of code. That closing parenthesis would also be a line of rogue code.

I recommend making a careful comparison of the searchCatalogue() function from your installation with what is posted here:

https://github.com/cubecart/v6/blob/v6.5-master/classes/catalogue.class.php

 

Link to comment
Share on other sites

In the database table CubeCart_history, each row records when that specific version of CubeCart (6.4.9, for example) was checked for any necessary changes to be made to the database structure. The Setup procedure will look in /setup/db/upgrade/ for files that are numbered higher than the last version recorded in the database.

Ultimately, the CubeCart code that is running the setup (6.5.1, for example) will record in the database Cubecart_history table when that check was made to make the database "married" to the version of CubeCart. This insertion of the record will happen even though there are no files in the setup folder named 6.5.0 or 6.5.1.

But if CubeCart 6.5.1 sees the last record refers to 6.5.0 (if that is the last version under which you ran setup), CubeCart should display a banner in admin saying something to the effect, "Your are running 651, but the database is at 650. Do you want to run setup?"

Because the code base was "manually" upgraded from 650 to 651, one needs to manually insert a new record showing the version and the Unix Epoch Time so that CubeCart won't complain anymore.

Note that when manually upgrading a store in this manner, one needs to be aware of any files in /setup/db/upgrade/ and /setup/scripts/upgrade/ that contains changes to the database structure or content.

The Unix Epoch Time is the number of seconds that has elapsed since midnight, the morning of Jan 1, 1970 UTC, and is used everywhere in the world.

 

Link to comment
Share on other sites

Not to shoot a dead horse but, I was checking out my search (searched "dog") and noticed that the same thing as above happened in the search.  I got stuck on page 1 even if I clicked page 3 - for example.  I upgraded to 6.5.1 and the same thing. I tried to check with Foundation but its pagination isn't the same as mine so I really couldn't. I compared files and all look ok. I like the layout of the search as it is and have no plans to use Elasticsearch. Any ideas?

https://www.cambargainstore.com

search for dogs

Link to comment
Share on other sites

That issue in the Github I mentioned earlier... #3066.

In /classes/catalogue.class.php:
Near lines 1847, 1850, 2009, 2044, and 2105
The statement (in part) makes a call to:

... searchCatalogue($original_search_data, 1, ...

Replace the 1 with $page

 

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
Reply to this topic...

×   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.

×
×
  • Create New...