Link Last Item in Breadcrumbs in Hikashop

  • Posts: 124
  • Thank you received: 6
2 years 6 months ago #341620

Hi
I am using the default Joomla breadcrumbs module and I want the last item (which is the product) to be linked to the same page.
I did this by edit breadcrumbs module layout:

$breadcrumbItem = '<a href="' . Route::_($item->link) . '" itemprop="name">' . html_entity_decode($item->name, ENT_QUOTES, 'UTF-8') . '</a>';
but there is a problem.
In products that have variants, instead of the main product link, takes the default variant product link.
How to get the right link?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 6 months ago #341630

Hi,

That's somehting which needs code to be changed in HikaShop's core.
Change the code:

		// Add missing variants (they will be disabled)
		//
		$productClass->checkVariants($element);
		if(!empty($element->options)) {
			foreach($element->options as $k => $optionElement) {
				$productClass->checkVariants($element->options[$k]);
			}
		}

		// Set the default variant data
		//
		$productClass->setDefault($element);
		if(!empty($element->options)) {
			foreach($element->options as $k => $optionElement) {
				$productClass->setDefault($element->options[$k]);
			}
		}

		if(!empty($element->variants)) {
			foreach($element->variants as $k => $variant) {
				$variant->main =& $element->main;
			}
		}

		$this->assignRef('element', $element);

		$product_name = hikashop_translate($this->element->product_name);
		$product_page_title = hikashop_translate($this->element->product_page_title);
		$product_description = hikashop_translate($element->product_meta_description);
		$product_keywords = hikashop_translate($element->product_keywords);

		if(!empty($this->element->main)) {
			$product_name = hikashop_translate($this->element->main->product_name);
			if(!empty($this->element->main->product_page_title))
				$product_page_title = hikashop_translate($this->element->main->product_page_title);
			if(!empty($this->element->main->product_meta_description))
				$product_description = hikashop_translate($this->element->main->product_meta_description);
			if(!empty($this->element->main->product_keywords))
				$product_keywords = hikashop_translate($this->element->main->product_keywords);
		}

		//
		$doc = JFactory::getDocument();
		if(is_object($menu)) {
			if(HIKASHOP_J30 && method_exists($menu, 'getParams'))
				$menuParams = $menu->getParams();
			else
				$menuParams = @$menu->params;
			//
			if(empty($product_keywords))
				$product_keywords =  $menuParams->get('menu-meta_keywords', '');
			if(empty($product_description))
				$product_description =  $menuParams->get('menu-meta_description', '');
			if($menuParams->get('robots'))
				$doc->setMetadata('robots', $menuParams->get('robots'));
		}

		if(!empty($product_keywords))
			$doc->setMetadata('keywords', $product_keywords);
		if(!empty($product_description))
			$doc->setMetadata('description', $product_description);

		// Page title
		if(empty($product_page_title)){
			$product_page_title = $product_name;
		}
		hikashop_setPageTitle($product_page_title);

		//
		$parent = 0;
		$url_itemid = '';
		if(!empty($Itemid))
			$url_itemid = '&Itemid='.$Itemid;
		$tmpl = hikaInput::get()->getString('tmpl');
		if(!empty($tmpl))
			$url_itemid = '&tmpl='.$tmpl;
		$this->assignRef('url_itemid', $url_itemid);

		// Set pathway only when we are not coming directly from a menu
		if(empty($menu) || !(strpos($menu->link,'option='.HIKASHOP_COMPONENT) !== false && strpos($menu->link,'view=product') !== false && strpos($menu->link,'layout=show') !== false)) {
			$pathway = $app->getPathway();
			$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
			$category_pathway = hikaInput::get()->getInt($pathway_sef_name,0);
			if($category_pathway) {
				$categoryClass = hikashop_get('class.category');

				if(!empty($menu->id)) {
					$menuClass = hikashop_get('class.menus');
					$menuData = $menuClass->get($menu->id);
					if(@$menuData->hikashop_params['content_type'] == 'manufacturer') {
						$new_id = 'manufacturer';
						$categoryClass->getMainElement($new_id);
						$menuData->hikashop_params['selectparentlisting'] = $new_id;
					}
					if(!empty($menuData->hikashop_params['selectparentlisting'])) {
						$parent = $menuData->hikashop_params['selectparentlisting'];
					}
				}

				$categories = $categoryClass->getParents($category_pathway, $parent);
				array_shift($categories);
				foreach($categories as $category) {
					$categoryClass->addAlias($category);
					$pathway->addItem(hikashop_translate($category->category_name), hikashop_completeLink('category&task=listing&cid='.(int)$category->category_id.'&name='.$category->alias.$url_itemid));
				}
				unset($categories);
			}
			$related_sef_name = $config->get('related_sef_name','related_product');
			$related = hikaInput::get()->getInt($related_sef_name,0);
			if($config->get('simplified_breadcrumbs',1) || !$category_pathway) {
				$category_pathway = '';
			} else {
				$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
				$category_pathway = '&'.$pathway_sef_name.'='.$category_pathway;
			}

			if(!empty($related)) {
				$prod = $productClass->get($related);
				if(!empty($prod)) {
					$productClass->addAlias($prod);
					$pathway->addItem(strip_tags(hikashop_translate($prod->product_name)), hikashop_completeLink('product&task=show&cid='.(int)$prod->product_id.'&name='.$prod->alias.$category_pathway.$url_itemid));
				}
			}
			$pathway->addItem(strip_tags($product_name), hikashop_completeLink('product&task=show&cid='.(int)$element->product_id.'&name='.$element->alias.$category_pathway.$url_itemid));
		}
to:
		$product_name = hikashop_translate($this->element->product_name);
		$product_page_title = hikashop_translate($this->element->product_page_title);
		$product_description = hikashop_translate($element->product_meta_description);
		$product_keywords = hikashop_translate($element->product_keywords);


		//
		$doc = JFactory::getDocument();
		if(is_object($menu)) {
			if(HIKASHOP_J30 && method_exists($menu, 'getParams'))
				$menuParams = $menu->getParams();
			else
				$menuParams = @$menu->params;
			//
			if(empty($product_keywords))
				$product_keywords =  $menuParams->get('menu-meta_keywords', '');
			if(empty($product_description))
				$product_description =  $menuParams->get('menu-meta_description', '');
			if($menuParams->get('robots'))
				$doc->setMetadata('robots', $menuParams->get('robots'));
		}

		if(!empty($product_keywords))
			$doc->setMetadata('keywords', $product_keywords);
		if(!empty($product_description))
			$doc->setMetadata('description', $product_description);

		// Page title
		if(empty($product_page_title)){
			$product_page_title = $product_name;
		}
		hikashop_setPageTitle($product_page_title);

		//
		$parent = 0;
		$url_itemid = '';
		if(!empty($Itemid))
			$url_itemid = '&Itemid='.$Itemid;
		$tmpl = hikaInput::get()->getString('tmpl');
		if(!empty($tmpl))
			$url_itemid = '&tmpl='.$tmpl;
		$this->assignRef('url_itemid', $url_itemid);

		// Set pathway only when we are not coming directly from a menu
		if(empty($menu) || !(strpos($menu->link,'option='.HIKASHOP_COMPONENT) !== false && strpos($menu->link,'view=product') !== false && strpos($menu->link,'layout=show') !== false)) {
			$pathway = $app->getPathway();
			$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
			$category_pathway = hikaInput::get()->getInt($pathway_sef_name,0);
			if($category_pathway) {
				$categoryClass = hikashop_get('class.category');

				if(!empty($menu->id)) {
					$menuClass = hikashop_get('class.menus');
					$menuData = $menuClass->get($menu->id);
					if(@$menuData->hikashop_params['content_type'] == 'manufacturer') {
						$new_id = 'manufacturer';
						$categoryClass->getMainElement($new_id);
						$menuData->hikashop_params['selectparentlisting'] = $new_id;
					}
					if(!empty($menuData->hikashop_params['selectparentlisting'])) {
						$parent = $menuData->hikashop_params['selectparentlisting'];
					}
				}

				$categories = $categoryClass->getParents($category_pathway, $parent);
				array_shift($categories);
				foreach($categories as $category) {
					$categoryClass->addAlias($category);
					$pathway->addItem(hikashop_translate($category->category_name), hikashop_completeLink('category&task=listing&cid='.(int)$category->category_id.'&name='.$category->alias.$url_itemid));
				}
				unset($categories);
			}
			$related_sef_name = $config->get('related_sef_name','related_product');
			$related = hikaInput::get()->getInt($related_sef_name,0);
			if($config->get('simplified_breadcrumbs',1) || !$category_pathway) {
				$category_pathway = '';
			} else {
				$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
				$category_pathway = '&'.$pathway_sef_name.'='.$category_pathway;
			}

			if(!empty($related)) {
				$prod = $productClass->get($related);
				if(!empty($prod)) {
					$productClass->addAlias($prod);
					$pathway->addItem(strip_tags(hikashop_translate($prod->product_name)), hikashop_completeLink('product&task=show&cid='.(int)$prod->product_id.'&name='.$prod->alias.$category_pathway.$url_itemid));
				}
			}
			$pathway->addItem(strip_tags($product_name), hikashop_completeLink('product&task=show&cid='.(int)$element->product_id.'&name='.$element->alias.$category_pathway.$url_itemid));
		}
		
		// Add missing variants (they will be disabled)
		//
		$productClass->checkVariants($element);
		if(!empty($element->options)) {
			foreach($element->options as $k => $optionElement) {
				$productClass->checkVariants($element->options[$k]);
			}
		}

		// Set the default variant data
		//
		$productClass->setDefault($element);
		if(!empty($element->options)) {
			foreach($element->options as $k => $optionElement) {
				$productClass->setDefault($element->options[$k]);
			}
		}

		if(!empty($element->variants)) {
			foreach($element->variants as $k => $variant) {
				$variant->main =& $element->main;
			}
		}

		$this->assignRef('element', $element);
in the file components/com_hikashop/views/product/view.html.php and it should fix the problem.
We'll add the change on our end for the next version of HikaShop.

The following user(s) said Thank You: levelup

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

Time to create page: 0.060 seconds
Powered by Kunena Forum