Page 1 of 1

Router giving wrong URLs on VM4.2

PostPosted: Tue Aug 29, 2023 2:10 pm
by admin
Hello, there is a bug in latest VM versions starting at about 4.0.8 to the very latest 4.2.23 where the category links are using wrong URLs with /resultsX,Y suffix when the page is first visited with a clean session (or no cookies). The main problem with category URLs is SEO - as google bot might index wrong URLs with the result suffix.

A simple fix to router.php is :

find this code:
Code: Select all
if ( $limitstart>0 ) {
               //For the urls leading to the paginated pages
               // using general limit if $limit is not set
               if ($limit === null) $limit= vmrouterHelper::$limit ;
               $segments[] = self::lang('results') .','. ($limitstart+1).'-'.($limitstart+$limit);
               if(vmrouterHelper::$debug) vmdebug('category case $limitstart>0 my limitstart, limit ',$limitstart,$limit);
            } else if (!empty($limit) /*$limit !== null*/ && $limit != vmrouterHelper::$limit ) {
               //for the urls of the list where the user sets the pagination size/limit
               $segments[] = self::lang('results') .',1-'.$limit ;
               if(vmrouterHelper::$debug) vmdebug('category case !empty($limit) my limitstart, limit ',$limitstart,$limit);
            } else if(!empty($query['search']) or !empty($query['keyword'])){
               $segments[] = self::lang('results') .',1-'.vmrouterHelper::$limit ;
               if(vmrouterHelper::$debug) vmdebug('category case last my limitstart, limit ',$limitstart,$limit);
            }
            }


and change it to:
Code: Select all
$default_limit = VmConfig::get('pagseq_1', 0);
            
            if (strpos($default_limit, ',') !== false) {
               $xa = explode(',', $default_limit);
               foreach ($xa as $l) {
                  $test = (int)$l;
                  if (!empty($test)) {
                     $default_limit = (int)$test;
                     break;
                  }
               }
            }
            elseif (is_int($default_limit)) {
               $default_limit = (int)$default_limit;
            }
            
            if (($limit !== $default_limit) || ($limitstart > 1))
            {   
            
            
            
            
         
            if ( $limitstart>0 ) {
               //For the urls leading to the paginated pages
               // using general limit if $limit is not set
               if ($limit === null) $limit= vmrouterHelper::$limit ;
               $segments[] = self::lang('results') .','. ($limitstart+1).'-'.($limitstart+$limit);
               if(vmrouterHelper::$debug) vmdebug('category case $limitstart>0 my limitstart, limit ',$limitstart,$limit);
            } else if (!empty($limit) /*$limit !== null*/ && $limit != vmrouterHelper::$limit ) {
               //for the urls of the list where the user sets the pagination size/limit
               $segments[] = self::lang('results') .',1-'.$limit ;
               if(vmrouterHelper::$debug) vmdebug('category case !empty($limit) my limitstart, limit ',$limitstart,$limit);
            } else if(!empty($query['search']) or !empty($query['keyword'])){
               $segments[] = self::lang('results') .',1-'.vmrouterHelper::$limit ;
               if(vmrouterHelper::$debug) vmdebug('category case last my limitstart, limit ',$limitstart,$limit);
            }
            }
            



This patch expects tht you use only one type of pagination per standard "product per rows" within Virtuemart configuration. (i.e. the patch might not work if some categories got product limit of 12 products while others got 24 products per virtuemart's configuration of products per row)

Best Regards, Stan