Module produit + itemID autodetect

  • Posts: 3
  • Thank you received: 0
10 years 3 months ago #139738

-- url of the page with the problem -- : 188.24.13.226/jcservice/ (version en construction)
-- HikaShop version -- : 2.2.2
-- Joomla version -- : 3
-- PHP version -- : 5
-- Browser(s) name and version -- : I tested all
-- Error-message(debug-mod must be tuned on) -- : No error

Bonjour, je vous explique ma situation. Sur le lien fournis vous verrez 1 menu horizontal présentant :

Accueil / blabla / HIKASHOP(le catalogue) / blabla / blabla

Dans le menu HIKASHOP j'ai créer tous les catégories référents aux catégories de produits. Jusque là tout va bien.
Mon soucis ce trouve un page d'accueil j'ai un module montrant les nouveaux arrivages listant tous les produits.
Dans ce module j'ai mentioné menu->HIKASHOP(le catalogue).
Ce qui fait que mes produits TOUS si je clique dessus prendront l'itemID 112 (le catalogue). Moi je voudrais que l'itemID sois trouvé automatiquement.

Pareil pour le module "Nos promotion ICI" et pour la page catalogue qui liste des produits de toutes les catégories et sous-catégories

PS : J'ai lu le tutorial disant de créer un lien menu + module associé... Mais ce cas n'est bon que si le module et composant sont unis dans la même page et ne s'avère pas très pratique si on doit dupliquer 100 fois le module.

Je pense que je dois modifier le code et je voudrais en être sur avant de commencer. J'ai repéré la fonction getlink().

Merci

Nouveau sur ce forum, d'habitude je trouve toujours la solution à mon problème.

Last edit: 10 years 3 months ago by klin34970.

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

  • Posts: 81590
  • Thank you received: 13079
  • MODERATOR
10 years 3 months ago #139817

Bonjour,

En effet, il n'y a pas d'option pour faire cela automatiquement car c'est assez complexe à faire pour gérer tous les différents cas de configuration possible des menus/modules.
La fonction getLink est en effet l'endroit où vous allez pouvoir ajouter votre code pour modifier l'URL des produits sur votre module.

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

  • Posts: 3
  • Thank you received: 0
10 years 3 months ago #139842

Merci ! En route vers l'aventure du codage :)

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

  • Posts: 3
  • Thank you received: 0
10 years 3 months ago #140093

Re, je n'ai toujours pas attaqué le code car je suis toujours entrain de construire le site.
Bref, Il me vient en tête qu'un module Universal AJAX Live Search dont le plugin search for hukashop detecte automatiquement l'itemID

Voici le code :

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.2.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2013 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
class plgSearchHikashop_products extends JPlugin{
	function plgSearchHikashop_products(&$subject, $config){
		$this->loadLanguage('plg_search_hikashop_products');
		$this->loadLanguage('plg_search_hikashop_products_override');
		parent::__construct($subject, $config);
		if(!isset($this->params)){
			$plugin = JPluginHelper::getPlugin('search', 'hikashop_products');
			if(version_compare(JVERSION,'2.5','<')){
				jimport('joomla.html.parameter');
				$this->params = new JParameter($plugin->params);
			} else {
				$this->params = new JRegistry($plugin->params);
			}
		}
	}

	function onContentSearchAreas(){
		return $this->onSearchAreas();
	}
	function onContentSearch( $text, $phrase='', $ordering='', $areas=null ){
		return $this->onSearch( $text, $phrase, $ordering, $areas );
	}

	function &onSearchAreas(){
		$areas = array(
			'products' => JText::_('PRODUCTS')
		);
		return $areas;
	}

	function onSearch( $text, $phrase='', $ordering='', $areas=null ){
		if(!defined('DS'))
			define('DS', DIRECTORY_SEPARATOR);
		if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return array();
		$db		= JFactory::getDBO();
		if (is_array( $areas )) {
			if (!array_intersect( $areas, array_keys( $this->onSearchAreas() ) )) {
				return array();
			}
		}

		$limit = $this->params->def( 'search_limit', 50 );

		$text = trim( $text );
		if ( $text == '' ) {
			return array();
		}

		switch($ordering){
			case 'alpha':
				$order = 'a.product_name ASC';
				break;
			case 'newest':
				$order = 'a.product_modified DESC';
				break;
			case 'oldest':
				$order = 'a.product_created ASC';
				break;
			case 'popular':
				$order = 'a.product_hit DESC';
				break;
			case 'category':
			default:
				$order = 'a.product_name DESC';
				break;
		}
		$trans=hikashop_get('helper.translation');
		$multi=$trans->isMulti();
		$trans_table = 'jf_content';
		if($trans->falang){
			$trans_table = 'falang_content';
		}

		$rows = array();

		$filters = array('a.product_published=1');

		$variants = (int)$this->params->get('variants','0');
		if(!$variants){
			$filters[]='a.product_type=\'main\'';
		}
		$out_of_stock = (int)$this->params->get('out_of_stock_display','1');
		if(!$out_of_stock){
			$filters[]='a.product_quantity!=0';
		}

		hikashop_addACLFilters($filters,'product_access','a');
		$leftjoin='';

		if(hikashop_level(2)){
			$catFilters = array('category_published=1','category_type=\'product\'');
			hikashop_addACLFilters($catFilters,'category_access');
			$db->setQuery('SELECT category_id FROM '.hikashop_table('category').' WHERE '.implode(' AND ',$catFilters));
			if(!HIKASHOP_J25){
				$cats = $db->loadResultArray();
			} else {
				$cats = $db->loadColumn();
			}
			if(!empty($cats)){
				$filters[]='b.category_id IN ('.implode(',',$cats).')';
			}
		}


		if($variants){
			$leftjoin=' INNER JOIN '.hikashop_table('product_category').' AS b ON a.product_parent_id=b.product_id OR a.product_id=b.product_id';
		}else{
			$leftjoin=' INNER JOIN '.hikashop_table('product_category').' AS b ON a.product_id=b.product_id';
		}

		$filters2 = array();

		if($multi){
			$registry = JFactory::getConfig();
			if(!HIKASHOP_J25){
				$code = $registry->getValue('config.jflang');
			}else{
				$code = $registry->get('language');
			}
			$lg = $trans->getId($code);
			$filters2[] = "b.reference_table='hikashop_product'";
			$filters2[] = "b.published=1";
			$filters2[] = 'b.language_id='.$lg;
		}

		$fields = $this->params->get('fields','');
		if(empty($fields)){
			$fields = array('product_name','product_description');
		}else{
			$fields = explode(',',$fields);
		}

		switch($phrase){
			case 'exact':
				$text		= $db->Quote( '%'.hikashop_getEscaped( $text, true ).'%', false );
				foreach($fields as $f){
					$filters[] = "a.".$f." LIKE ".$text;
				}

				if($multi){
					$filters2[] = "b.value LIKE ".$text;
				}
				break;
			case 'all':
			case 'any':
			default:
				$words = explode( ' ', $text );
				$wordFilters = array();
				$subWordFiltersX = array();
				$wordFilters2 = array();
				foreach ($words as $word) {
					$word		= $db->Quote( '%'.hikashop_getEscaped( $word, true ).'%', false );
					foreach($fields as $i => $f){
						$subWordFiltersX[$i][] = "a.".$f." LIKE ".$word;
					}
					if($multi){
						$wordFilters2[] = "b.value LIKE ".$word;
					}
				}
				foreach($subWordFiltersX as $i => $subWordFilters){
					$wordFilters[$i]= '((' .implode( ($phrase == 'all' ? ') AND (' : ') OR ('),$subWordFilters). '))';
				}
				$filters[] = '((' . implode( ') OR (', $wordFilters ) . '))';
				if($multi){
					$filters2[] = '((' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wordFilters2 ) . '))';
				}
				break;
		}

		$new_page = (int)$this->params->get('new_page','1');

		$select = ' a.product_id AS id, a.product_name, a.product_created AS created , a.product_description, "'.$new_page.'" AS browsernav';
		if($variants){
			$select.=', a.product_type, a.product_parent_id';
		}
		$count = 0;
		if($multi && !empty($lg)){
			$db->setQuery('SET SQL_BIG_SELECTS=1');
			$db->query();
			$query = ' SELECT DISTINCT '.$select.', f.file_path AS product_image FROM '.hikashop_table($trans_table,false) . ' AS b LEFT JOIN '.hikashop_table('product').' AS a ON b.reference_id=a.product_id INNER JOIN '.hikashop_table('file').' AS f ON f.file_ref_id=a.product_id WHERE '.implode(' AND ',$filters2).' AND f.file_type="product" ORDER BY '.$order;			                                                                          
			$db->setQuery($query, 0, $limit);
			$rows = $db->loadObjectList("id");
			$count = count($rows);
			if($count){
				$limit = $limit-$count;
				$filters[]='a.product_id NOT IN ('.implode(',',array_keys($rows)).')';
			}
		}

		if($limit){
			if(!empty($leftjoin)){
				$select.=', b.category_id as category_id';
			}
			$db->setQuery('SET SQL_BIG_SELECTS=1');
			$db->query();

			$query = ' SELECT DISTINCT '.$select.', f.file_path AS product_image FROM '.hikashop_table('product') . ' AS a '.$leftjoin.' LEFT JOIN '.hikashop_table('file').' AS f ON f.file_ref_id=a.product_id WHERE '.implode(' AND ',$filters).' GROUP BY (a.product_id) ORDER BY '.$order;

			$db->setQuery( $query, 0, $limit );
			$mainRows = $db->loadObjectList("id");
			if(!empty($mainRows)){
				foreach($mainRows as $k => $main){
					$rows[$k]=$main;
				}
				$count = count( $rows );
			}
		}
		if($count){

			if($multi && !empty($lg)){
				$query = ' SELECT * FROM '.hikashop_table($trans_table,false) . ' WHERE reference_table=\'hikashop_product\' AND language_id=\''.$lg.'\' AND published=1 AND reference_id IN ('.implode(',',array_keys($rows)).')';
				$db->setQuery($query);
				$trans = $db->loadObjectList();
				foreach($trans as $item){
					foreach($rows as $key => $row){
						if($row->id==$item->reference_id){
							if($item->reference_field=='product_name'){
								$row->product_name=$item->value;
							}elseif($item->reference_field=='product_description'){
								$row->product_description=$item->value;
							}else{
								$row->product_name=$item->value;
							}
							break;
						}
					}
				}
			}
			$parent = '';
			$item_id = $this->params->get('item_id','');
			$menuClass = hikashop_get('class.menus');
			$config =& hikashop_config();
			$pathway_sef_name = $config->get('pathway_sef_name','category_pathway');
			$menus=array();
			$Itemid='';
			if(!empty($item_id)){
				$Itemid='&Itemid='.$item_id;
				if($this->params->get('full_path',1)){
					$menuData = $menus[$item_id] = $menuClass->get($item_id);
					if(!empty($menuData->hikashop_params['selectparentlisting'])){
						$parent = '&'.$pathway_sef_name.'='.(int)$menuData->hikashop_params['selectparentlisting'];
					}
				}
			}
			$itemids=array();
			$app= JFactory::getApplication();
			$class = hikashop_get('class.product');
			foreach ( $rows as $k => $row ) {
				if(!empty($row->category_id)){
					if(empty($item_id)){
						if(!isset($itemids[$row->category_id])) $itemids[$row->category_id] = $menuClass->getItemidFromCategory($row->category_id);
						$item_id = $itemids[$row->category_id];
					}
					if(!empty($item_id)){
						$Itemid='&Itemid='.$item_id;
					}
					if($this->params->get('full_path',1)){
						$parent = '&'.$pathway_sef_name.'='.(int)$row->category_id;
					}
					if(!$this->params->get('item_id','')) $item_id = '';
				}
				$class->addAlias($row);
				$row->title=$row->product_name;
				$row->text=$row->product_description;
				if($variants && $row->product_type=='variant'){
					static $mains = array();
					if(!isset($mains[$row->product_parent_id])){
						$mains[$row->product_parent_id] = $class->get((int)$row->product_parent_id);
						$class->addAlias($mains[$row->product_parent_id]);
					}
					$db = JFactory::getDBO();
					$db->setQuery('SELECT * FROM '.hikashop_table('variant').' AS a LEFT JOIN '.hikashop_table('characteristic') .' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id='.(int)$row->id.' ORDER BY a.ordering');
					$row->characteristics = $db->loadObjectList();
					$class->checkVariant($row,$mains[$row->product_parent_id]);
					if(empty($row->title)){
						$row->title = $row->product_name;
					}
					if(empty($row->text)){
						$row->text = $mains[$row->product_parent_id]->product_description;
					}
				}

				$rows[$k]->href = 'index.php?option=com_hikashop&ctrl=product&task=show&name='.$row->alias.'&cid='.$row->id.$Itemid.$parent;
				$rows[$k]->section 	= JText::_( 'PRODUCT' );				
				if ($row->product_image) {
  				  $rows[$k]->image = JUri::Root().'media/com_hikashop/upload/'.$row->product_image;
  			}
			}

		}
		return $rows;
	}
}

Si ça peut aider.

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

  • Posts: 81590
  • Thank you received: 13079
  • MODERATOR
10 years 3 months ago #140185

C'est quasiment le même code que le plugin search par défaut dans HikaShop.
C'est bien en effet mais pour l'implémenter dans les modules d'affichage, c'est plus complexe que cela car il y a plus de cas à prendre en compte et il nécessiterait de rajouter des options pour activer ou non cela. Après, pour votre personnalisation, ce sera très bien oui.

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

  • Posts: 99
  • Thank you received: 2
9 years 11 months ago #158039

Hello,
does it comes to any result the search for an update on auto-find the correct link/menu-item for products in module ?

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

Time to create page: 0.061 seconds
Powered by Kunena Forum