Compate products button

  • Posts: 1119
  • Thank you received: 114
9 years 2 months ago #245480

Hi,

So I am trying to enable compare products feature. When pressing compare products button I get 404 page error.
I found that category/listing view override was giving me problems. Removing it all works fine.

The code giving me problems is below:

if(!function_exists('get_hikashop_activecat')){
    function get_hikashop_activecat(&$actives, $db, $cid=''){
        if(JRequest::getString('option')==HIKASHOP_COMPONENT && in_array(JRequest::getString('ctrl','category'),array('category','product'))){
            if($cid == ''){
                if(JRequest::getString('ctrl','category')=='product'&&JRequest::getString('task','listing')=='show'){
                    $app = JFactory::getApplication();
                    $found = $app->getUserState(HIKASHOP_COMPONENT.'.last_category_selected');
                    $config =& hikashop_config();
                    $pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
                    $cid = JRequest::getInt($pathway_sef_name,0);
                }else{
                    $cid = JRequest::getInt('cid',0);
                };
                $actives[] = $cid;
            }
            if($cid){
                $db->setQuery('SELECT category_parent_id FROM #__hikashop_category WHERE category_id='.$cid);
                $result = $db->loadResult();
                if($result){
                    $actives[] = $result;
                    get_hikashop_activecat($actives, $db, $result);
                }
            }
        }
    }
}

$actives = array();
get_hikashop_activecat($actives, JFactory::getDbo());

I cant remove it because it brakes my template/category list look a little bit... So could someone take a look in it and modify so my compare button would work? Or what i could add change? I would be very thankful.

Thanks for help.

Last edit: 9 years 2 months ago by kyratn.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
9 years 2 months ago #245520

Hello,
Firstly id you try to add that code on the last version (without override) of the category/listing_view file ?

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
9 years 2 months ago #245564

Hi,

My bad it was category listing_list view file...
So I have removed customization from that view and added this code to original view and compare products button would give 404 page error. :(

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.3.2
 * @author	hikashop.com
 * @copyright	(C) 2010-2014 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>

<?php
if(!function_exists('add_hikashop_childcat')){
    function add_hikashop_childcat($item, $that, $actives){
        if(!empty($item->childs)){
            $app = JFactory::getApplication();
            $only_if_products = $that->params->get('only_if_products',0);
        ?>

                <ul class="hikashop_category_list<?php echo $that->params->get('ul_class_name'); ?>">
                    <?php
                    $limit = $that->params->get('child_limit');
                    $i = 0;
                    foreach($item->childs as $child){
                        if($only_if_products && $child->number_of_products<1) continue;
                        if(!empty($limit) && $i >= $limit) break;
                        $i++;
                        $link = $that->getLink($child);
                        $class = '';
                        if(in_array($child->category_id, $actives)) $class=' current active';
                        ?>
                        <li class="hikashop_category_list_item<?php echo $class; ?> <?php if(!empty($child->childs)) echo 'parent'?>">
                            <a href="<?php echo $link; ?>">
                                <?php
                                echo $child->category_name;
                                if($that->params->get('number_of_products',0)){
                                    echo ' ('.$child->number_of_products.')';
                                }
                                ?>
                            </a>
                            <?php add_hikashop_childcat($child, $that, $actives);?>
                        </li>
                    <?php }?>
                </ul>

        <?php }
    }
}
if(!function_exists('get_hikashop_activecat')){
    function get_hikashop_activecat(&$actives, $db, $cid=''){
        if(JRequest::getString('option')==HIKASHOP_COMPONENT && in_array(JRequest::getString('ctrl','category'),array('category','product'))){
            if($cid == ''){
                if(JRequest::getString('ctrl','category')=='product'&&JRequest::getString('task','listing')=='show'){
                    $app = JFactory::getApplication();
                    $found = $app->getUserState(HIKASHOP_COMPONENT.'.last_category_selected');
                    $config =& hikashop_config();
                    $pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
                    $cid = JRequest::getInt($pathway_sef_name,0);
                }else{
                    $cid = JRequest::getInt('cid',0);
                };
                $actives[] = $cid;
            }
            if($cid){
                $db->setQuery('SELECT category_parent_id FROM #__hikashop_category WHERE category_id='.$cid);
                $result = $db->loadResult();
                if($result){
                    $actives[] = $result;
                    get_hikashop_activecat($actives, $db, $result);
                }
            }
        }
    }
}

$actives = array();
get_hikashop_activecat($actives, JFactory::getDbo());
?>

<?php
if(!empty($this->rows)){
	$pagination = $this->config->get('pagination','bottom');
	if(in_array($pagination,array('top','both')) && $this->params->get('show_limit') && $this->pageInfo->elements->total > $this->pageInfo->limit->value){ $this->pagination->form = '_top'; ?>
	<form action="<?php echo hikashop_currentURL();?>" method="post" name="adminForm_<?php echo $this->params->get('main_div_name').$this->category_selected;?>_top">
		<div class="hikashop_subcategories_pagination hikashop_subcategories_pagination_top">
		<?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>
	<?php } ?>
	<div class="hikashop_subcategories">
	<?php

	$only_if_products = $this->params->get('only_if_products',0);
	switch($this->params->get('child_display_type')){
		case 'nochild':
		default:
			if(!empty($this->rows)){
			?>
				<ul class="hikashop_category_list<?php echo $this->params->get('ul_class_name'); ?>">
				<?php

					$width = (int)(100/$this->params->get('columns'));
					if(empty($width)){
						$width='';
					}else{
						$width='style="width:'.$width.'%;"';
					}
					$app = JFactory::getApplication();
					$found = '';
					if(JRequest::getString('option')==HIKASHOP_COMPONENT && in_array(JRequest::getString('ctrl','category'),array('category','product'))){
						foreach($this->rows as $row){
							if(JRequest::getString('ctrl','category')=='product'&&JRequest::getString('task','listing')=='show'){
								$found = $app->getUserState(HIKASHOP_COMPONENT.'.last_category_selected');
								$config =& hikashop_config();
								$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
								$cid = JRequest::getInt($pathway_sef_name,0);
							}else{
								$cid = JRequest::getInt('cid',0);
							}
							if($cid == $row->category_id){
								$found=$row->category_id;
								$app->setUserState(HIKASHOP_COMPONENT.'.last_category_selected',$row->category_id);
								break;
							}
						}
					}
					foreach($this->rows as $row){
						if($only_if_products && $row->number_of_products<1) continue;
						$link = $this->getLink($row);
						$class = '';
						if($found == $row->category_id){
								$class=' current active';
						}
						?>
						<li class="hikashop_category_list_item<?php echo $class; ?>" <?php echo $width; ?>>
							<a href="<?php echo $link; ?>" >
							<?php
								echo $row->category_name;
								if($this->params->get('number_of_products',0)){
									echo ' ('.$row->number_of_products.')';
								}
							 ?>
							</a>
						</li>
						<?php
					}
				?>
				</ul>
		<?php
			}
			break;
		case 'allchildsexpand':
			?>
			<ul id="category_panel_<?php echo $this->params->get('id');?>" class="menu-sliders">
			<?php
			if(!empty($this->rows)){
				foreach($this->rows as $k => $row){
					if($only_if_products && $row->number_of_products<1) continue;
					$link = $this->getLink($row);
                    $class = '';
                    if(in_array($row->category_id, $actives)) $class=' current active';
					?>
					<li class=" <?php if(!empty($row->childs)) echo 'parent'?><?php echo $class; ?>">

								<a href="<?php echo $link;?>" id="category_pane_<?php echo $k;?>">
									<?php
										echo $row->category_name;
										if($this->params->get('number_of_products',0)){
											echo ' ('.$row->number_of_products.')';
										}
									?>
								</a>

                        <?php add_hikashop_childcat($row, $this, $actives);?>
					</li>
                <?php }?>
            <?php }?>
			</ul>
            <?php
			break;
		case 'allchilds':
			jimport('joomla.html.pane');
			$found = -1;
			if(JRequest::getString('option')==HIKASHOP_COMPONENT && in_array(JRequest::getString('ctrl','category'),array('category','product')) && $cid = JRequest::getInt('cid',0)){
				if(JRequest::getString('ctrl','category')=='product'&&JRequest::getString('task','listing')=='show'){
					$config =& hikashop_config();
					$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
					$cid = JRequest::getInt($pathway_sef_name,0);
					if(empty($cid)){
						$database = JFactory::getDBO();
						$query = "SELECT category_id FROM ".hikashop_table('product_category').' WHERE product_id='.hikashop_getCID('product_id').' ORDER BY product_category_id ASC';
						$database->setQuery($query);
						$cid = $database->loadResult();
						if(empty($cid)){
							$class=hikashop_get('class.product');
							$product = $class->get(hikashop_getCID('product_id'));
							if($product && $product->product_type=='variant' && $product->product_parent_id){
								$query = "SELECT category_id FROM ".hikashop_table('product_category').' WHERE product_id='.$product->product_parent_id.' ORDER BY product_category_id ASC';
								$database->setQuery($query);
								$cid = $database->loadResult();
							}
						}
					}
				}
				$i=0;
				if(!empty($this->rows)){
					foreach($this->rows as $k => $row){
						if($only_if_products && $row->number_of_products<1) continue;
						if($row->category_id==$cid){
							$found = $i;
							break;
						}
						if(!empty($row->childs)){
							foreach($row->childs as $child){
								if($child->category_id==$cid){
									$found = $i;
									break 2;
								}
							}
						}
						$i++;
					}
					$app = JFactory::getApplication();
					if($found>=0){
						$app->setUserState(HIKASHOP_COMPONENT.'.last_category_selected',$found);
					}elseif(JRequest::getString('ctrl','category')!='category'||JRequest::getString('task','listing')!='listing'){
						$found = (int)$app->getUserState(HIKASHOP_COMPONENT.'.last_category_selected');
					}
				}

			}else{
				$cid = 0;
			}

			$this->tabs = hikashop_get('helper.sliders');
			$this->tabs->setOptions(array('startOffset'=>$found,'startTransition'=>0,'displayFirst'=>0));
			echo $this->tabs->startPane( 'category_panel_'.$this->params->get('id'));
			if(!empty($this->rows)){
				foreach($this->rows as $k => $row){
					if($only_if_products && $row->number_of_products<1) continue;
					if($this->params->get('number_of_products',0)){
						$row->category_name.= ' ('.$row->number_of_products.')';
					}

					if( !$this->module || $this->params->get('links_on_main_categories')){
						$link = $this->getLink($row);
						$row->category_name = '<a href="'.$link.'">'.$row->category_name.'</a>';
					}

					$toOpen = false;
					if($row->category_id == hikashop_getCid())
						$toOpen = true;
					if(!empty($row->childs)){
						foreach($row->childs as $child){
							if($child->category_id == hikashop_getCid())
								$toOpen = true;
						}
					}

					echo $this->tabs->startPanel($row->category_name, 'category_pane_'.$k, !empty($row->childs), $toOpen);
					if(!empty($row->childs)){
						?><ul class="hikashop_category_list<?php echo $this->params->get('ul_class_name'); ?>"><?php
							foreach($row->childs as $child){
								if($only_if_products && $child->number_of_products<1) continue;
								$class = '';
								if($cid==$child->category_id){
									$class=' current active';
								}
								$link = $this->getLink($child);
								?>
								<li class="hikashop_category_list_item<?php echo $class; ?>">
									<a class="hikashop_category_list_item_link" href="<?php echo $link; ?>">
									<?php
										echo $child->category_name;
										if($this->params->get('number_of_products',0)){
											echo ' ('.$child->number_of_products.')';
										}
									?>
									</a>
								</li>
								<?php
							}
						?></ul><?php
					} else {
						echo JText::_('HIKA_LISTING_LIST_EMPTY');
					}
					echo $this->tabs->endPanel();
				}
			}
			echo $this->tabs->endPane();

			break;
	}
	?>
	</div>
	<?php if(in_array($pagination,array('bottom','both')) && $this->params->get('show_limit') && $this->pageInfo->elements->total > $this->pageInfo->limit->value){ $this->pagination->form = '_bottom'; ?>
	<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_subcategories_pagination hikashop_subcategories_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>
	<?php }
} ?>


So what is wrong with this code that product compare button stops working?

Thank you

Last edit: 9 years 2 months ago by kyratn.

Please Log in or Create an account to join the conversation.

  • Posts: 84313
  • Thank you received: 13702
  • MODERATOR
9 years 2 months ago #245595

Hi,

category/listing_list.php is not involved in the display of the comparison system or the products listing. So I don't see why it would change anything.
If the comparison system doesn't work, it must come from something else.
Could you provide a link to the page with the issue so that we could have a deeper look into it ?

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
9 years 2 months ago #245625

Hi,

Maybe you are right but to find which one of the view overrides is giving me a problem I had to rename every folder via ftp...
And I found that this view with that code doing something wrong...

You are welcome to try it here as example: kyra.lt/test/sukneles

Just add some product to compare and press compare button which will appear on the top near top pagination and that button should get you to comparison page but instead it gives 404 page error.
Removing that code all works fine.

Regards

Thanks

Last edit: 9 years 2 months ago by kyratn.

Please Log in or Create an account to join the conversation.

  • Posts: 84313
  • Thank you received: 13702
  • MODERATOR
9 years 2 months ago #245626

Hi,

The link generated for the comparison looks just fine.
If you turn off the SEF in the Joomla configuration, does it work ?
And if you use the default template of Joomla does it work ?
Are you using any third party SEF extension like sh404SEF on your website ?

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
9 years 2 months ago #245635

Hi,


I do not use third party SEF extensions.
Tried to turn off SEF in Joomla and same results.
Yes with default template it does work. But adding that piece of code it gives 404 page error....
As i said in my previous messages that everythings works fine without that code but that code is needed for template look....
I have no idea what is the problem with that code thats why i have created topic.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 84313
  • Thank you received: 13702
  • MODERATOR
9 years 2 months ago #245640

Hi,

Ah, I think I know. The problem is in that code. It resets the cid variable in some cases, but that's the variable used to give the list of products to compare.
Changing the line:

if(JRequest::getString('option')==HIKASHOP_COMPONENT && in_array(JRequest::getString('ctrl','category'),array('category','product'))){
to:
if(JRequest::getString('option')==HIKASHOP_COMPONENT && in_array(JRequest::getString('ctrl','category'),array('category','product')) && JRequest::getString('task') !='compare'){
and it might help.
In any case, you want to contact your template provider for help with that issue as it is not a problem originating in HikaShop but in the way they modify the views of HikaShop.

The following user(s) said Thank You: kyratn

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
9 years 2 months ago #245655

Hi,

Your code did the trick. ;)

As usual, thank you very much Nicolas!

Have a great evening

Please Log in or Create an account to join the conversation.

Time to create page: 0.081 seconds
Powered by Kunena Forum