Question

I'am working on a custom template, and I came to the point where I have to modify component's helper source code. To prevent that, I'am wondering if there is a corresponding approach to extend specific helper class of some component with own functions, or else override it ?

Introducing the override file within my custom template jmlroot/templates/mytemplate/html/com_hikashop/product/listing_div.php:

<form action="<?php echo hikashop_currentURL(); ?>" method="post" name="adminForm_<?php echo $this->params->get('main_div_name').$this->category_selected;?>_bottom">
    <div class="hikashop_products_pagination hikashop_products_pagination_bottom">
    <?php echo $this->pagination->getListFooter($this->params->get('limit')); ?>
    <span class="hikashop_results_counter"><?php echo $this->pagination->getResultsCounter(); ?></span>
    </div>
    <input type="hidden" name="filter_order_<?php echo $this->params->get('main_div_name').$this->category_selected;?>" value="<?php echo $this->pageInfo->filter->order->value; ?>" />
    <input type="hidden" name="filter_order_Dir_<?php echo $this->params->get('main_div_name').$this->category_selected;?>" value="<?php echo $this->pageInfo->filter->order->dir; ?>" />
    <?php echo JHTML::_( 'form.token' ); ?>
</form>

Inside that form there is a PHP code:

<?php echo $this->pagination->getListFooter($this->params->get('limit')); ?>

Which is called from helper file jmlroot/administrator/components/com_hikashop/helpers/pagination.php:

class hikashopPaginationHelper extends hikashopBridgePaginationHelper{
    function _item_active(JPaginationObject $item){
        $class = 'pagenav';
        $specials = array('start','end','previous','next');
        foreach($specials as $special){
            if(!empty($item->$special)){
                $class.=' hikashop_'.$special.'_link';
            }
        }
        if($item->base>0)
            return "<a class=\"".$class."\" title=\"".$item->text."\" onclick=\"javascript: document.adminForm".$this->hikaSuffix.$this->form.".limitstart".$this->hikaSuffix.".value=".$item->base."; document.adminForm".$this->hikaSuffix.$this->form.".submit();return false;\">".$item->text."</a>";
        else
            return "<a class=\"".$class."\" title=\"".$item->text."\" onclick=\"javascript: document.adminForm".$this->hikaSuffix.$this->form.".limitstart".$this->hikaSuffix.".value=0; document.adminForm".$this->hikaSuffix.$this->form.".submit();return false;\">".$item->text."</a>";
    }
    function _item_inactive(JPaginationObject $item){
        $mainframe = JFactory::getApplication();
        if ($mainframe->isAdmin()) {
            return "<span>".$item->text."</span>";
        } else {
            $class = 'pagenav';
            if(!is_numeric($item->text)){
                $class .= ' pagenav_text';
            }
            return '<span class="'.$class.'">'.$item->text."</span>";
        }
    }
}

And I need to override that class hikashopPaginationHelper with a little bit modified code (by remplacing <spans /> with <li/>.

I tried to add this portion of code into jmlroot/templates/mytemplate/html/com_hikashop/product/listing_div.php at the biggining of the file:

jimport('joomla.application.component.controller');
jimport('joomla.html.pagination');

require_once JPATH_ADMINISTRATOR . '/components/com_hikashop/helpers/pagination.php';

class MY_hikashopPaginationHelper extends hikashopBridgePaginationHelper{
    function _item_active(JPaginationObject $item){
        $class = 'pagenav';
        $specials = array('start','end','previous','next');
        foreach($specials as $special){
            if(!empty($item->$special)){
                $class.=' hikashop_'.$special.'_link';
            }
        }
        if($item->base>0)
            return "<li><a class=\"".$class."\" title=\"".$item->text."\" onclick=\"javascript: document.adminForm".$this->hikaSuffix.$this->form.".limitstart".$this->hikaSuffix.".value=".$item->base."; document.adminForm".$this->hikaSuffix.$this->form.".submit();return false;\">".$item->text."</a></li>";
        else
            return "<li><a class=\"".$class."\" title=\"".$item->text."\" onclick=\"javascript: document.adminForm".$this->hikaSuffix.$this->form.".limitstart".$this->hikaSuffix.".value=0; document.adminForm".$this->hikaSuffix.$this->form.".submit();return false;\">".$item->text."</a></li>";
    }
    function _item_inactive(JPaginationObject $item){
        $mainframe = JFactory::getApplication();
        if ($mainframe->isAdmin()) {
            return "<li>".$item->text."</li>";
        } else {
            $class = 'pagenav';
            if(!is_numeric($item->text)){
                $class .= ' pagenav_text';
            }
            return '<li class="'.$class.'">'.$item->text."</li>";
        }
    }
}

But it doesn't helped a bit. I think there is something I'am doing wrong, anyone remarked something ?

Was it helpful?

Solution

There are some plugins that make it easier to do this that are available on the JED or you can implement what they did.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top