Jump to content

[Solved] Help with a very helpful modules, Categoryfeatured


rob84

Recommended Posts

Hello. I installed a module called categoryfeatured, that display products that you choose in category page. Adding products showed in a specific category, is made through an ajax search in BO, selecting the corresponding category, and searching inside it for a products. Now the problem is that can not be chosen products in other categories except the one in which the products is contained.

Example:

 

Categories structures:

 

PC (no products)

  |

  |- - - - Hard Disk (4 products)

  |- - - - Ram (10 products)

 

Now I would to add 2 products from hard disk category, and 1 from RAM category, in PC category.

 

These are the files in module:

 

 

searchproduct.php :

<?php
	include_once(dirname(__FILE__).'../../../config/config.inc.php');
	include_once(dirname(__FILE__).'../../../init.php');



	global $smarty,$cookie;
		

		$lang_id = intval($cookie->id_lang);

		$search_query=$_GET['query'];
		$cat=$_GET['cat'];
		/*echo $search_query.'<br/>';*/
		
		if(isset($search_query) and isset($cat))
		{
			/*if (!Validate::isCatalogName($search_query))
				die(echo Tools::displayError());*/

			$result = Db::getInstance()->ExecuteS('
			SELECT p.`id_product`, pl.`name`, pl.`link_rewrite`, p.`active`, i.`id_image`, p.`reference`
			FROM `'._DB_PREFIX_.'category_product` cp
			LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
			LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($lang_id ).')
			LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`) AND i.`cover` = 1
			LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($lang_id ).')
			WHERE cp.`id_category` = '.intval($cat).' AND ( pl.`name` LIKE \'%'.pSQL($search_query).'%\'  OR  p.`id_product` LIKE \'%'.pSQL($search_query).'%\' )
			GROUP BY `id_product`
			ORDER BY pl.`name` ASC');

			if (!$result)
				echo "No results";
			else{
					echo '<div id="list" style="margin:0 0 0 15px!important;">
					<table style="width:290px;padding:5px;">
						<tr>
							<th style="padding:5px;">ID</th>
							<th style="padding:5px;">Image</th>
							<th style="padding:5px;">Name</th>
							<th style="padding:2px;">Add</th>
						</tr>';
					foreach($result as $row => $value){
					echo '<tr > 
					<td style="padding:5px;"> '.$value['id_product'].'</td>
					<td style="padding:5px;"><img src="../img/p/'.$value['id_product'].'-'. $value['id_image'].'-small.jpg" /></td>
					<td style="padding:5px;">  '.$value['name'].'</td>
					<td style="padding-left:5px;"><img Alt="Add" title="Add"  onClick="insertPro('.$cat.','.$value['id_product'].')" src="'._PS_BASE_URL_.__PS_BASE_URI__.'/img/admin/add.gif"></td>
					</tr>';
					}
				echo '<tfoot>
						<tr>
							<td colspan="4"><em>To add product click on <img Alt="Add" title="Add"  src="'._PS_BASE_URL_.__PS_BASE_URI__.'/img/admin/add.gif"> icon</em></td>
						</tr>
				     </tfoot>
				</table>
					</div>';
			}
			
				

		}	
		else echo $search_query.'ERROR';
		


?>

categoryfeatured-ajax.php :


<?php
	include_once(dirname(__FILE__).'../../../config/config.inc.php');
	include_once(dirname(__FILE__).'../../../init.php');


	global $smarty,$cookie;
		
	$cat=$_GET["cat"]; 

	if ($cat >0)		
	{ 
		$lang_id = intval($cookie->id_lang);
		if (isset($_GET['pid'])){
		/* Delete product */
			$delCFP=$_GET['pid'];
			if(isset($delCFP))
			{
				$sql = '
				DELETE FROM `' . _DB_PREFIX_ . 'category_featured_products` WHERE `' . _DB_PREFIX_ . 'category_featured_products`.`id_product` = '.$delCFP.' LIMIT 1';

				try {
				Db::getInstance()->ExecuteS($sql);
				} catch (Exception $e) {
					echo 'Caught exception: ',  $e->getMessage(), "\n";
				}

			}
		}
		if (isset($_GET['ip'])){
			/* Insert product */
			$insCFP=$_GET['ip'];
			if(isset($insCFP))
			{
				try {
				$array = array('id_category' => $cat, 'id_product' => $insCFP);
				$catuery = Db::getInstance()->autoExecute(_DB_PREFIX_."category_featured_products", $array, 'INSERT');
				$id = Db::getInstance()->Insert_ID();
				} catch (Exception $e) {
					echo 'Caught exception: ',  $e->getMessage(), "\n";
				}

			}
		}
		/* Get all featured products in category */
		$sql2 = '
		SELECT DISTINCT cl.`name` AS catname,cl.`link_rewrite` AS catlink,cfp.`id_product` As prID,pl.`name` AS product,pl.`link_rewrite` AS link_rewrite,i.`id_image`, il.`legend` FROM `' . _DB_PREFIX_ . 'category_featured_products` cfp 
		LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = cfp.`id_product`
		LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON cp.`id_category`=cfp.`id_category`
		LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.$lang_id.')
		LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.$lang_id.')
		LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.$lang_id.')
		where cfp.`id_category`='.intval($cat);
		
		$feat_products = Db::getInstance()->ExecuteS($sql2);
		/* Display table of featured products */
		if(count($feat_products) > 0 ){
		echo '	<div id="list">	

					<table id="listTable" >
					<thead>
							<tr>
							<th>Product</th>
							<th>Image</th>
							<th>X</th>
							</tr>
					</thead>';
				foreach($feat_products as $featured => $value){
						  echo '<tr>';
						  echo '<td class="width">' . $value['product'] . '</td>';
						  echo '<td class="width"><img src="../img/p/'.$value['prID'].'-'. $value['id_image'].'-medium.jpg" /></td>';
						  echo '<td><img Alt="Delete" title="Delete" onClick="delPro('.$value['prID'].','.$cat.')" src="'._PS_BASE_URL_.__PS_BASE_URI__.'/img/admin/delete.gif"></td>';
						  echo '</tr>';							
						
					} 
		echo '       <tfoot>
						<tr>
							<td colspan="3"><em>To remove product click on <img Alt="Delete" title="Delete"  src="'._PS_BASE_URL_.__PS_BASE_URI__.'/img/admin/delete.gif"> icon</em></td>
						</tr>
				     </tfoot>
			        </table>
					<br/>
		</div>';
		
		}
		
		echo '<br/>
		<form method="get" action="">
		<label for="product" style="margin-right:15px;">Search by product name or product Id: </label><input type="text" id="product" name="product" size="25" onkeyup="showResult(this.value,'.$cat.')"/>

		</form>
					<div id="livesearch"></div><br />';		
	}
	

		
	if ($cat == null)
	{ 
		echo 'Error';
	}

?>

categoryfeatured.php :

<?php
/**
  * Category Featured Products
  * @category featured
  *
  * @author Lazar Kaljeviæ
  * @copyright Lazar Kaljeviæ / PrestaShop
  * @license 
  * @version 0.2
  */


class CategoryFeatured extends Module
{
	function __construct()
	{
		$this->name = 'categoryfeatured';
		$this->tab = 'PrestaSpace';
		$this->version = '0.2';
		
		/* The parent construct is required for translations */
		parent::__construct();
		
		$this->page = basename(__FILE__, '.php');
		$this->displayName = $this->l('Category Featured Products');
		$this->description = $this->l('A module to set featured products in category');
	}

	function install()
	{
		try {
			$array = array('name' => 'categoryFeaturedHook', 'title' => 'Category Featured Products');
			$query = Db::getInstance()->autoExecute(_DB_PREFIX_."hook", $array, 'INSERT');
			$id = Db::getInstance()->Insert_ID();
		} 
		catch (Exception $e) {
				return false;
		}
		
		$category_featured_products_sql = "
		CREATE TABLE IF NOT EXISTS `" . _DB_PREFIX_ . "category_featured_products` (
			`id` int(10) NOT NULL auto_increment,
			`id_category` int(10) NOT NULL,
			`id_product` int(10) NOT NULL,
			PRIMARY KEY  (`id`)
		)";
		if (!parent::install() OR 
			!$this->registerHook('categoryFeaturedHook') OR 
			Db::getInstance()->Execute($category_featured_products_sql) == false)
			return false;
			
			if (!Configuration::updateValue('CATEGORY_FEATURED_VISIBLE', 3))return false;	
			if (!Configuration::updateValue('CATEGORY_FEATURED_SPEED', 600))return false;
			if (!Configuration::updateValue('CATEGORY_FEATURED_SCROLL', 1))return false;
			if (!Configuration::updateValue('CATEGORY_FEATURED_AUTO', 'null'))return false;
			if (!Configuration::updateValue('CATEGORY_FEATURED_MOUSEWHEEL', 0))return false;	

			if (!Configuration::updateValue('CATEGORY_FEATURED_VVISIBLE', 3))return false;	
			if (!Configuration::updateValue('CATEGORY_FEATURED_VSPEED', 600))return false;
			if (!Configuration::updateValue('CATEGORY_FEATURED_VSCROLL', 1))return false;
			if (!Configuration::updateValue('CATEGORY_FEATURED_VAUTO', 800))return false;
			if (!Configuration::updateValue('CATEGORY_FEATURED_VMOUSEWHEEL', 1))return false;				
			
		return true;
						
	}
	
	function uninstall()
	{
		return(Db::getInstance()->Execute('DROP TABLE ' . _DB_PREFIX_ . 'category_featured_products') AND
			  Db::getInstance()->Execute("DELETE FROM `". _DB_PREFIX_ ."hook` WHERE `name` = 'categoryFeaturedHook' LIMIT 1") AND
			   parent::uninstall());
	}
	
	function getContent()
	{		
		$output = $this->_displayForm();
		if (Tools::isSubmit('submitCategoryFeatured'))
		{
			/* Carousel settings */
			$vis = intval(Tools::getValue('vis'));
			if (!$vis OR $vis <= 0 OR !Validate::isInt($vis))
				$errors[] = $this->l('Invalid number of visible products');
			else
				Configuration::updateValue('CATEGORY_FEATURED_VISIBLE', $vis);
			
			$speed = intval(Tools::getValue('sp'));
			if (!$speed OR $speed < 0 OR !Validate::isInt($speed))
				$errors[] = $this->l('Invalid speed');
			else
				Configuration::updateValue('CATEGORY_FEATURED_SPEED', $speed);
				
			$scroll = intval(Tools::getValue('scr'));
			if (!$scroll OR $scroll < 0 OR !Validate::isInt($scroll))
				$errors[] = $this->l('Invalid scroll');
			else
				Configuration::updateValue('CATEGORY_FEATURED_SCROLL', $scroll);
				
			$auto = Tools::getValue('auto');
			if (!$auto){
				if (intval($auto) < 0 OR !Validate::isInt(intval($auto)))
					$errors[] = $this->l('Invalid settings for auto');}
			else
				Configuration::updateValue('CATEGORY_FEATURED_AUTO', $auto);
				
			$mousewheel = Tools::getValue('mousewheel');
			if ($mousewheel != 0 AND $mousewheel != 1){
				$errors[] = $this->l('Invalid settings for mousewheel');}
			else
			{
				Configuration::updateValue('CATEGORY_FEATURED_MOUSEWHEEL',$mousewheel);
			}	
			if (isset($errors) AND sizeof($errors))
				$output .= $this->displayError(implode('<br />', $errors));
			else
				$output .= $this->displayConfirmation($this->l('Settings updated'));
		}	
		if (Tools::isSubmit('submitCategoryFeaturedVertical'))
		{	
			/* Vertical carousel settings */
			$Vvis = intval(Tools::getValue('Vvis'));
			if (!$Vvis OR $Vvis <= 0 OR !Validate::isInt($Vvis))
				$errors[] = $this->l('Invalid number of visible products.Vertical');
			else
				Configuration::updateValue('CATEGORY_FEATURED_VVISIBLE', $Vvis);
			
			$Vspeed = intval(Tools::getValue('Vsp'));
			if (!$Vspeed OR $Vspeed < 0 OR !Validate::isInt($Vspeed))
				$errors[] = $this->l('Invalid speed.Vertical');
			else
				Configuration::updateValue('CATEGORY_FEATURED_VSPEED', $Vspeed);
				
			$Vscroll = intval(Tools::getValue('Vscr'));
			if (!$Vscroll OR $Vscroll < 0 OR !Validate::isInt($Vscroll))
				$errors[] = $this->l('Invalid scroll');
			else
				Configuration::updateValue('CATEGORY_FEATURED_VSCROLL', $Vscroll);
				
			$Vauto = Tools::getValue('Vauto');
			if (!$Vauto){
				if (intval($Vauto) < 0 OR !Validate::isInt(intval($Vauto)))
					$errors[] = $this->l('Invalid settings for auto');}
			else
				Configuration::updateValue('CATEGORY_FEATURED_VAUTO', $Vauto);
				
			$Vmousewheel = Tools::getValue('Vmousewheel');
			if ($Vmousewheel != 0 AND $Vmousewheel != 1){
				$errors[] = $this->l('Invalid settings for mousewheel');}
			else
			{
				Configuration::updateValue('CATEGORY_FEATURED_VMOUSEWHEEL',$Vmousewheel);
			}
			
			
			if (isset($errors) AND sizeof($errors))
				$output .= $this->displayError(implode('<br />', $errors));
			else
				$output .= $this->displayConfirmation($this->l('Settings updated'));
		}
				
		return $output;
					
	}

	private function _displayForm()
	{
		global $smarty, $cookie;
		
		
		echo '
		<script type="text/javascript">
			$(document).ready(function(){

				$("#btn-slide").click(function(){
					$("#Vpanel").hide("slow");
					$("#panel").slideToggle("slow");
					$(this).toggleClass("active"); return false;
				});
				$("#btn-Vslide").click(function(){
					$("#panel").hide("slow");
					$("#Vpanel").slideToggle("slow");
					$(this).toggleClass("active"); return false;
				});
				
				 
			});
			</script>
			
		<h2 >'.$this->displayName.'</h2>
		<div id="panel" style="display: none;">

		<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
			<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Carousel settings').'</legend>
				<label>'.$this->l('Visible products : ').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="vis" value="'.Tools::getValue('vis', Configuration::get('CATEGORY_FEATURED_VISIBLE')).'" />
					<p class="clear">'.$this->l('The number of visible products displayed in carousel (default: 3)').'</p>
					
				</div>
				<label>'.$this->l('Sliding speed : ').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="sp" value="'.Tools::getValue('sp', Configuration::get('CATEGORY_FEATURED_SPEED')).'" />
					<p class="clear">'.$this->l('Sliding speed of your carousel. (800, 600, 1500).Providing 0, will remove the slide effect. ').'</p>					
				</div>
				<label>'.$this->l('Scroll by : ').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="scr" value="'.Tools::getValue('scr', Configuration::get('CATEGORY_FEATURED_SCROLL')).'" />
					<p class="clear">'.$this->l('Number of items to scroll. (default: 1) ').'</p>					
				</div>
				<label>'.$this->l('Auto-scrolling : ').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="auto" value="'.Tools::getValue('auto', Configuration::get('CATEGORY_FEATURED_AUTO')).'" />
					<p class="clear">'.$this->l('Amount of time between 2 consecutive slides(ex. 500).Enter null to disable auto-scrolling.  ').'</p>					
				</div>
				
				<label>'.$this->l('Mouse wheel : ').'</label>
				<div class="margin-form">
					<input type="radio" name="mousewheel" id="mousewheel_on" value="1" '.(Tools::getValue('mousewheel', Configuration::get('CATEGORY_FEATURED_MOUSEWHEEL')) ? 'checked="checked" ' : '').'/>
					<label class="t" for="mousewheel_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
					<input type="radio" name="mousewheel" id="mousewheel_off" value="0" '.(!Tools::getValue('mousewheel', Configuration::get('CATEGORY_FEATURED_MOUSEWHEEL')) ? 'checked="checked" ' : '').'/>
					<label class="t" for="mousewheel_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
					<p class="clear">'.$this->l('Activate mouse wheel to scroll').'</p>
				</div>
				
				<center><input type="submit" name="submitCategoryFeatured" value="'.$this->l('Save').'" class="button" /></center>
			</fieldset>
		</form>
		</div>
		
		<div id="Vpanel" style="display: none;">

		<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
			<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Vertical carousel settings').'</legend>
				<label>'.$this->l('Visible products : ').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="Vvis" value="'.Tools::getValue('Vvis', Configuration::get('CATEGORY_FEATURED_VVISIBLE')).'" />
					<p class="clear">'.$this->l('The number of visible products displayed in carousel (default: 3)').'</p>
					
				</div>
				<label>'.$this->l('Sliding speed : ').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="Vsp" value="'.Tools::getValue('Vsp', Configuration::get('CATEGORY_FEATURED_VSPEED')).'" />
					<p class="clear">'.$this->l('Sliding speed of your carousel. (800, 600, 1500).Providing 0, will remove the slide effect. ').'</p>					
				</div>
				<label>'.$this->l('Scroll by : ').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="Vscr" value="'.Tools::getValue('Vscr', Configuration::get('CATEGORY_FEATURED_VSCROLL')).'" />
					<p class="clear">'.$this->l('Number of items to scroll. (default: 1) ').'</p>					
				</div>
				<label>'.$this->l('Auto-scrolling : ').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="Vauto" value="'.Tools::getValue('Vauto', Configuration::get('CATEGORY_FEATURED_VAUTO')).'" />
					<p class="clear">'.$this->l('Amount of time between 2 consecutive slides(ex. 500).Enter null to disable auto-scrolling.  ').'</p>					
				</div>
				
				<label>'.$this->l('Mouse wheel : ').'</label>
				<div class="margin-form">
					<input type="radio" name="Vmousewheel" id="Vmousewheel_on" value="1" '.(Tools::getValue('Vmousewheel', Configuration::get('CATEGORY_FEATURED_VMOUSEWHEEL')) ? 'checked="checked" ' : '').'/>
					<label class="t" for="Vmousewheel_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
					<input type="radio" name="Vmousewheel" id="Vmousewheel_off" value="0" '.(!Tools::getValue('Vmousewheel', Configuration::get('CATEGORY_FEATURED_VMOUSEWHEEL')) ? 'checked="checked" ' : '').'/>
					<label class="t" for="Vmousewheel_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
					<p class="clear">'.$this->l('Activate mouse wheel to scroll').'</p>
				</div>
				
				<center><input type="submit" name="submitCategoryFeaturedVertical" value="'.$this->l('Save').'" class="button" /></center>
			</fieldset>
		</form>
		</div>
		<p class="slide"><a id="btn-slide" class="button" href="#">'.$this->l('Carousel options').'</a></p>
		<p class="slide"><a id="btn-Vslide" class="button" href="#">'.$this->l('Vertical carousel options').'</a></p>
		<br class="clear" />
		';
		
		

		echo '

			<div ><label for="id_category_default" style="margin-right:15px;">'.$this->l('Choose  category: ').'</label></div>
			<div>
				<select id="id_category_default" name="id_category_default" onchange="getCat(this.value);">';
			$categories = Category::getCategories(intval($cookie->id_lang), false);
			Category::recurseCategory($categories, $categories[0][1], 1, Tools::getValue('id_category', 1));
		echo '
				</select>
			
			</div>

			<script type="text/javascript" src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/categoryfeatured/js/ajax.js"></script>
			<link rel="stylesheet" href="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/categoryfeatured/css/categoryfeaturedadmin.css" type="text/css" media="screen" title="UI CSS" charset="utf-8">

			<br/>
			<div id="txtCat"></div><br />';
				
	}

	public function hookRightColumn()
	{
		global $smarty, $cookie;
		$cat=Tools::getValue('id_category');
		$lang_id = intval($cookie->id_lang);
		
		$sql2 = '
		SELECT DISTINCT cfp.`id` as id,cl.`name` AS catname,cfp.`id_product` As prID,pl.`name` AS product,pl.`link_rewrite`,i.`id_image`, il.`legend` FROM `ps_category_featured_products` cfp 
		LEFT JOIN `ps_product` p ON p.`id_product` = cfp.`id_product`
		LEFT JOIN `ps_category_product` cp ON cp.`id_category`=cfp.`id_category`
		LEFT JOIN `ps_product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.$lang_id.')
		LEFT JOIN `ps_category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.$lang_id.')
		LEFT JOIN `ps_image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		LEFT JOIN `ps_image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.$lang_id.')
		where cfp.`id_category`='.Tools::getValue('id_category');
		
		$feat_products = Db::getInstance()->ExecuteS($sql2);
		if($feat_products != null){
		$smarty->assign(array(
				'Vbase_dir' => _PS_BASE_URL_.__PS_BASE_URI__ ,
				'Vfeat_products' => $feat_products ,
				'Vvisible' => intval(Tools::getValue('Vvis', Configuration::get('CATEGORY_FEATURED_VVISIBLE'))),
				'Vspeed' => intval(Tools::getValue('Vsp', Configuration::get('CATEGORY_FEATURED_VSPEED'))),
				'Vscroll' => intval(Tools::getValue('Vscr', Configuration::get('CATEGORY_FEATURED_VSCROLL'))),
				'Vauto' => intval(Tools::getValue('Vauto', Configuration::get('CATEGORY_FEATURED_VAUTO'))),
				'Vmousewheel' => intval(Tools::getValue('Vmousewheel', Configuration::get('CATEGORY_FEATURED_VMOUSEWHEEL')))			
			));

			return $this->display(__FILE__, 'categoryfeaturedvertical.tpl');
		}
	}
	public function hookLeftColumn()
	{
		return $this->hookRightColumn();
	
	}
	public function hookcategoryFeaturedHook()
	{
		global $smarty, $cookie;
		$cat=Tools::getValue('id_category');
		$lang_id = intval($cookie->id_lang);
		
		$sql2 = '
		SELECT DISTINCT cfp.`id` as id,cp.`id_category` AS catid,cl.`name` AS catname,cfp.`id_product` As prID,pl.`name` AS product,pl.`link_rewrite`,i.`id_image`, il.`legend` FROM `ps_category_featured_products` cfp 
		LEFT JOIN `ps_product` p ON p.`id_product` = cfp.`id_product`
		LEFT JOIN `ps_category_product` cp ON cp.`id_category`=cfp.`id_category`
		LEFT JOIN `ps_product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.$lang_id.')
		LEFT JOIN `ps_category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.$lang_id.')
		LEFT JOIN `ps_image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
		LEFT JOIN `ps_image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.$lang_id.')
		where cfp.`id_category`='.Tools::getValue('id_category');
		
		$feat_products = Db::getInstance()->ExecuteS($sql2);
		if($feat_products != null){
			$smarty->assign(array( 
				'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__ ,
				'feat_products' => $feat_products ,
				'visible' => intval(Tools::getValue('vis', Configuration::get('CATEGORY_FEATURED_VISIBLE'))),
				'speed' => intval(Tools::getValue('sp', Configuration::get('CATEGORY_FEATURED_SPEED'))),
				'scroll' => intval(Tools::getValue('scr', Configuration::get('CATEGORY_FEATURED_SCROLL'))),
				'auto' => intval(Tools::getValue('auto', Configuration::get('CATEGORY_FEATURED_AUTO'))),
				'mousewheel' => intval(Tools::getValue('mousewheel', Configuration::get('CATEGORY_FEATURED_MOUSEWHEEL')))

			));
			return $this->display(__FILE__, 'categoryfeatured.tpl');
		
		}
	}	
		
}

Practically, i would that when search is done for adding product in BO, it searches for all products in the shop, in this way I can add it in category that I want.

 

If you need more explanation feel free to ask !!!

 

Thanks.

Edited by rob84 (see edit history)
Link to comment
Share on other sites

In searchproduct.php, try replacing
 

WHERE cp.`id_category` = '.intval($cat).' AND ( pl.`name` LIKE \'%'.pSQL($search_query).'%\'  OR  p.`id_product` LIKE \'%'.pSQL($search_query).'%\' )

with

WHERE ( pl.`name` LIKE \'%'.pSQL($search_query).'%\'  OR  p.`id_product` LIKE \'%'.pSQL($search_query).'%\' )

and see where that gets you. From what I can see, that should at least give you search results from all categories. Couldn't see any input validation (quick glance only), so this might be enough.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...