News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Sub Category Level Pagination with Limited Sub Categories per page

Started by yuewupostbox, September 10, 2013, 19:41:21 PM

Previous topic - Next topic

yuewupostbox

Hello there,

My VM version is 2.0.22a.

I search around this forum and looking for a Sub Category Level Pagination with Limited Sub Categories per page feature.

I found 2 post here but no one replied them.

I have checked & modified the code and added the Pagination to the sub category page, i can see the Pagination is displaying a correct result,

let say i have 6 categories in the parent catagory, and limited to 5 CATs per page, the Pagination result is 1-5 CATs, TOTAL 6 CATs,

and also the next/prev button is show 1 & 2 pages for clicking,

but the categories display isn't limited to 5 per page (actually display 6) which i have set from Joomla system setting.

i looked at the "exeSortSearchListQuery" function in vmmodel.php,

and tried some simple echo and counting the array total to find out the root cause.

Product is using loadResultArray to query & category is using loadObjectList to query,

i find out the loadResultArray can be limited to 5 products in 1 query,

but loadObjectList queried all the categories.

I think i am going a wrong way to modify the system code, and would like to see if anyone can give me some advise to succeed this,

Please help & thanks all! :)

yuewupostbox

Hello All,

I am glad to tell that i have succeed for at least 5 sub categories per page with Pagination & page navigation, here is my sharing below and hope someone find this useful, thanks! ;)


1# Add Subcategory Pagination

FILE: <root>/components/com_virtuemart/views/category/tmpl/default.php

LINE Location: Optional, put where you want to display

CODE:

<div class="orderby-displaynumber">
   <div class="width70 floatleft">
      <?php echo $this->orderByList['orderby']; ?>
      <?php echo $this->orderByList['manufacturer']; ?>
   </div>
   <div class="width30 floatright display-number"><?php echo $this->vmPagination2->getResultsCounter ();?><br/><?php echo $this->vmPagination2->getLimitBox ($this->category->limit_list_step); ?></div>
   <div class="vm-pagination">
      <?php echo $this->vmPagination2->getPagesLinks (); ?>
      <span style="float:right"><?php echo $this->vmPagination2->getPagesCounter (); ?></span>
   </div>

2# Set Subcategory Pagination

FILE: <root>/components/com_virtuemart/views/category/view.html.php

LINE Location: Inside "public function display"

CODE1 (top side from the function):

   if (!class_exists('VmImage'))
      require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'image.php');
      
      $productModel = VmModel::getModel('product');
      $categoryModel = VmModel::getModel('category');

CODE2 (bottom side of the function):

      $this->assignRef('category', $category);
      $pagination2 = $categoryModel->getPagination($perRow);
      $this->assignRef('vmPagination2', $pagination2);


      parent::display($tpl);
   }





3# Set Page Limit to function "getChildCategoryList"

FILE: <root>/administrator/components/com_virtuemart/model/category.php

LINE Location: Search function "getChildCategoryList", After last line of query, Before "$childList = $db->loadObjectList();"

CODE:

static public function getChildCategoryList($vendorId, $virtuemart_category_id) {

      $key = (int)$vendorId.'_'.(int)$virtuemart_category_id ;

      static $_childCateogryList = array ();
      if (! array_key_exists ($key,$_childCateogryList)){

         $query = 'SELECT L.* FROM `#__virtuemart_categories_'.VMLANG.'` as L
                  JOIN `#__virtuemart_categories` as C using (`virtuemart_category_id`)';
         $query .= ' LEFT JOIN `#__virtuemart_category_categories` as CC on C.`virtuemart_category_id` = CC.`category_child_id`';
         $query .= 'WHERE CC.`category_parent_id` = ' . (int)$virtuemart_category_id . ' ';
         //$query .= 'AND C.`virtuemart_category_id` = CC.`category_child_id` ';
         $query .= 'AND C.`virtuemart_vendor_id` = ' . (int)$vendorId . ' ';
         $query .= 'AND C.`published` = 1 ';
         $query .= ' ORDER BY C.`ordering`, L.`category_name` ASC';

         $db = JFactory::getDBO();
         
         $myCatPagination = new VmModel();
         $limits = $myCatPagination->setPaginationLimits();
         $limitStart = $limits[0];
         $limit = $limits[1];

         
         
         $db->setQuery( $query,$limitStart,$limit);
         $childList = $db->loadObjectList();
         
//          $childList = $this->_getList( $query );

         if(!empty($childList)){
            if(!class_exists('TableCategory_medias'))require(JPATH_VM_ADMINISTRATOR.DS.'tables'.DS.'category_medias.php');
            foreach($childList as $child){
               $xrefTable = new TableCategory_medias($db);
//                $xrefTable = $this->getTable('category_medias');
               $child->virtuemart_media_id = $xrefTable->load($child->virtuemart_category_id);
            }
         }

         $_childCateogryList[$key]=$childList ;
      }
      return $_childCateogryList[$key];
   }