Jump to content

[SOLVED] Products by the same manufacturer


andy T

Recommended Posts

Hi all,

on my product page in the product footer I have "productsCategory" module showing products in the same category, I want to have another block to show products by the same manufacturer.

I have duplicated and renamed the module, but my php is not great and I cannot figure out how to switch it to pull the products by manufacturer rather than category?

Any help appreciated
Andy

Original PHP =

<?php

class productsCategory extends Module
{
    function __construct()
    {
         $this->name = 'productscategory';
         $this->version = '1.2.1';
         $this->tab = 'Products';

       parent::__construct();
       $this->page = basename(__FILE__, '.php');
       $this->displayName = $this->l('Products Category');
       $this->description = $this->l('Display products of the same category on the product page');
    }

   function install()
   {
        if (!parent::install())
            return false;
        return $this->registerHook('productfooter');
   }

   private function getCurrentProduct($products, $id_current)
   {
       if ($products)
           foreach ($products as $key => $product)
               if ($product['id_product'] == $id_current)
                   return $key;
       return false;
   }

   public function hookProductFooter($params)
   {
       global $smarty, $cookie;

       $idProduct = intval(Tools::getValue('id_product'));
       $product = new Product(intval($idProduct));

       $category = new Category(1);
       if (isset($params['category']->id_category))
           $category = $params['category'];
       if ($category->id_category == 1 AND isset($product->id_category_default) AND $product->id_category_default > 1)
           $category = New Category(intval($product->id_category_default));
       if (!Validate::isLoadedObject($category))
           Tools::displayError('Bad category !');

       // Get infos

       $sizeOfCategoryProducts = $category->getProducts(intval($cookie->id_lang), 1, 30, NULL, NULL, true);
       $categoryProducts = $category->getProducts(intval($cookie->id_lang), 1, $sizeOfCategoryProducts);        

       // Get positions
       $middlePosition = round($sizeOfCategoryProducts / 2, 0);
       $productPosition = $this->getCurrentProduct($categoryProducts, $idProduct);

       // Flip middle product with current product
       if ($productPosition)
       {
           $tmp = $categoryProducts[$middlePosition-1];
           $categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
           $categoryProducts[$productPosition] = $tmp;
       }

       // If products tab higher than 30, slice it
       if ($sizeOfCategoryProducts > 30)
       {
           $categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
           $middlePosition = 15;
       }


       // Display tpl
       $smarty->assign('categoryProducts', $categoryProducts);
       $smarty->assign('middlePosition', $middlePosition);
       return $this->display(__FILE__, 'productscategory.tpl');
   }
}
?>

Link to comment
Share on other sites

Try renaming the module's folder to productsmanufacturer and rename productscategory.php to productsmanufacturer.php and put the following in the file:

<?php

class ProductsManufacturer extends Module
{
    function __construct()
    {
         $this->name = 'productsmanufacturer';
         $this->version = '1.2.1';
         $this->tab = 'Products';

       parent::__construct();
       $this->page = basename(__FILE__, '.php');
       $this->displayName = $this->l('Products Manufacturer');
       $this->description = $this->l('Display products of the same manufacturer on the product page');
    }

   function install()
   {
        if (!parent::install())
            return false;
        return $this->registerHook('productfooter');
   }

   private function getCurrentProduct($products, $id_current)
   {
       if ($products)
           foreach ($products as $key => $product)
               if ($product['id_product'] == $id_current)
                   return $key;
       return false;
   }

   public function hookProductFooter($params)
   {
       global $smarty, $cookie;

       $idProduct = intval(Tools::getValue('id_product'));
       $product = new Product(intval($idProduct));

       // Get infos

       $sizeOfManufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, 30, NULL, NULL, true);
       $manufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, $sizeOfCategoryProducts);        

       // Get positions
       $middlePosition = round($sizeOfManufacturerProducts / 2, 0);
       $productPosition = $this->getCurrentProduct($manufacturerProducts, $idProduct);

       // Flip middle product with current product
       if ($productPosition)
       {
           $tmp = $manufacturerProducts[$middlePosition-1];
           $manufacturerProducts[$middlePosition-1] = $manufacturerProducts[$productPosition];
           $manufacturerProducts[$productPosition] = $tmp;
       }

       // If products tab higher than 30, slice it
       if ($sizeOfManufacturerProducts > 30)
       {
           $manufacturerProducts = array_slice($manufacturerProducts, $middlePosition - 15, 30, true);
           $middlePosition = 15;
       }


       // Display tpl
       $smarty->assign('categoryProducts', $manufacturerProducts);
       $smarty->assign('middlePosition', $middlePosition);
       return $this->display(__FILE__, 'productscategory.tpl');
   }
}
?>



You can also change productscategory.tpl to productsmanufacturer.tpl and the variable 'categoryProducts' to 'manufacturerProducts' for consistency if you want, but it is not needed for the module to work.

Link to comment
Share on other sites

Hi, thanks for the help.

I am getting Parse error in the module, as far as I can work out it is down to these lines, probably the $sizeOfManufacturer


       // Get infos        
       $sizeOfManufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, 30, NULL, NULL, true);
       $manufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), (intval($cookie->id_lang), 1, $sizeOfManufacturerProducts);        



any thoughts?
Thanks Andy

----

On further investigation, the original categories version had the following

       $category = new Category(1);
       if (isset($params['category']->id_category))
           $category = $params['category'];
       if ($category->id_category == 1 AND isset($product->id_category_default) AND $product->id_category_default > 1)
           $category = New Category(intval($product->id_category_default));
       if (!Validate::isLoadedObject($category))
           Tools::displayError('Bad category !');



which "$sizeOfManufacturerProducts = Manufacturer" I think refers to, is this correct?

Link to comment
Share on other sites

Thanks for that.

In the .tpl I have renamed the elements to match the vars, but nothing is being displayed, in debug I am getting "{$manufacturerProducts}: false"

I have both the original productsCategory + the new productsManufacturer modules running, could there be a conflict between the two?

I tried with the original tpl file with the $manufacturerProducts swapped in for $categoryProducts, no luck, then:
{foreach from=$manufacturerProducts item='manufacturerProduct' name=manufacturerProduct}
and all the $manufacturerProduct vars to match.

Not sure if it is of relevance but also in debug is the following:

for the category block there is:
{$category}: Object { id=1, more...}
{$categoryProduct}: false
{$categoryProducts}: [Object { id_produc

for manufacturer block there is:
{$manufacturerProducts}: false
{$manufacturers}: []

but no {$manufacturer} or {$manufacturerProduct}, also there is {$product_manufacturer}: Object { id=1, more...} if we need to reference the manufacturer info?

Thanks Andy

Link to comment
Share on other sites

Hi, please ignor previous, it was due to a naming error,


// Get infos
$sizeOfManufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, 30, NULL, NULL, true);
$manufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, $sizeOfManufacturerProducts);

I had renamed line 1 - sizeOfManufacturerProducts, but not the call to it on line 2

Thanks for the help
Andy

Link to comment
Share on other sites

I am probably doing something very silly, but in the title of the .tpl for both "productsCategory" and "productsManufacturer" module I am trying to add a "View All" link to take the user to relevant category page.

I have all the code in place for the link and it displays the correct name, but I cannot get the HREF to be correct, most attempts just break the page. I have tried a lot of variations on {$link->($category.category_id)} or getCategoryLink() but none have worked.

Any thoughts on the best way to achieve this?

Thanks
Andy

Link to comment
Share on other sites

Change the first line of the hookProductFooter function of modules/productscategory/productscategory.php file from:

global $smarty, $cookie;



to:

global $smarty, $cookie, $link;



and change lines 40-44 from:

$category = new Category(1);
if (isset($params['category']->id_category))
   $category = $params['category'];
if ($category->id_category == 1 AND isset($product->id_category_default) AND $product->id_category_default > 1)
   $category = New Category(intval($product->id_category_default));



to:

$category = new Category(1, intval($cookie->id_lang));
if (isset($params['category']->id_category))
   $category = $params['category'];
if ($category->id_category == 1 AND isset($product->id_category_default) AND $product->id_category_default > 1)
   $category = new Category(intval($product->id_category_default), intval($cookie->id_lang));



then add the following anywhere before the return on the last line:

$categoryLink = $link->getCategoryLink(intval($category->id), $category->link_rewrite);
$smarty->assign('categoryLink', $categoryLink);



You can then put the following code in modules/productscategory.tpl:

<a href="{$categoryLink}">{l s='View all' mod='productscategory'}



You can do a similar thing for the manufacturers too by calling getManufacturerLink instead of getCategoryLink.

Link to comment
Share on other sites

  • 2 months later...

The only things I can think of that would cause that a "no template found" error are if modules/productscategory/productscategory.tpl was missing from your server or didn't have read permissions, or perhaps the __FILE__ variable is wrong, which is causing it to look in the wrong place for the template. It is the following code that is leading to the error:

if (file_exists(_PS_THEME_DIR_.'modules/'.basename($file, '.php').'/'.$template))
{
   $smarty->assign('module_template_dir', _THEME_DIR_.'modules/'.basename($file, '.php').'/');
   $result = $smarty->fetch(_PS_THEME_DIR_.'modules/'.basename($file, '.php').'/'.$template);
}
elseif (file_exists(dirname($file).'/'.$template))
{
   $smarty->assign('module_template_dir', __PS_BASE_URI__.'modules/'.basename($file, '.php').'/');
   $result = $smarty->fetch(dirname($file).'/'.$template);
}
else
   $result = Tools::displayError('No template found');



PrestaShop first checks whether themes/yourtheme/modules/productscategory/productscategory.tpl exists, then checks whether modules/productscategory/productscategory.tpl exists. The function file_exists must return false for both of those for you to get that error message.

Link to comment
Share on other sites

Hi Rocky,

Works well... Thanks, i had forgotten to do what Andy also did:

Hi, please ignor previous, it was due to a naming error,


// Get infos
$sizeOfManufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, 30, NULL, NULL, true);
$manufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, $sizeOfManufacturerProducts);

I had renamed line 1 - sizeOfManufacturerProducts, but not the call to it on line 2

Thanks for the help
Andy


Do you know how i would go about getting only 5 products showing?

Cheers for your help so far.

Robert
Link to comment
Share on other sites

To have five products instead of 30, change:

$sizeOfManufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, 30, NULL, NULL, true);



to:

$sizeOfManufacturerProducts = Manufacturer::getProducts(intval($product->id_manufacturer), intval($cookie->id_lang), 1, 5, NULL, NULL, true);

Link to comment
Share on other sites

  • 1 year later...
  • 3 weeks later...

Hi Rocky,

 

 

is there any chance to get help for the version 1.4.5.1?

 

I tried to duplicate your instructions above but without success.

 

Here is my PHP file :

 

<?php
if (!defined('_PS_VERSION_'))
exit;
class productsManufacturer extends Module
{
 private $_html;
public function __construct()
 {
   $this->name = 'productsmanufacturer';
   $this->version = '1.3';
 $this->author = 'PrestaShop';
   $this->tab = 'front_office_features';
 $this->need_instance = 0;

 parent::__construct();

 $this->displayName = $this->l('Products Manufacturer');
 $this->description = $this->l('Display products of the same collection on the product page.');

 if (!$this->isRegisteredInHook('header'))
  $this->registerHook('header');
 }
public function install()
{
  if (!parent::install() OR !$this->registerHook('productfooter') OR !$this->registerHook('header') OR !Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0))
   return false;
  return true;
}

public function uninstall()
{
  if (!parent::uninstall() OR !Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE'))
   return false;
  return true;
}

public function getContent()
{
 $this->_html = '';
 if (Tools::isSubmit('submitCross') AND Tools::getValue('displayPrice') != 0 AND Tools::getValue('displayPrice') != 1)
  $this->_html .= $this->displayError('Invalid displayPrice');
 elseif (Tools::isSubmit('submitCross'))
 {
  Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', Tools::getValue('displayPrice'));
  $this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
 }
 $this->_html .= '
 <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
 <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
  <label>'.$this->l('Display price on products').'</label>
  <div class="margin-form">
   <input type="radio" name="displayPrice" id="display_on" value="1" '.(Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE') ? 'checked="checked" ' : '').'/>
   <label class="t" for="display_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
   <input type="radio" name="displayPrice" id="display_off" value="0" '.(!Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE') ? 'checked="checked" ' : '').'/>
   <label class="t" for="display_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
   <p class="clear">'.$this->l('Show the price on the products in the block.').'</p>
  </div>
  <center><input type="submit" name="submitCross" value="'.$this->l('Save').'" class="button" /></center>
 </fieldset>
 </form>';
 return $this->_html;
}

private function getCurrentProduct($products, $id_current)
{
 if ($products)
  foreach ($products AS $key => $product)
   if ($product['id_product'] == $id_current)
 return $key;
 return false;
}

public function hookProductFooter($params)
{
 global $smarty, $cookie;

 $idProduct = (int)(Tools::getValue('id_product'));
 $product = new Product((int)($idProduct));
 /* If the visitor has came to this product by a category, use this one */
 if (isset($params['manufacturer']->id_manufacturer))
  $manufacturer = $params['manufacturer'];
 /* Else, use the default product category */
 else
 {
  if (isset($product->id_manufacturer_default) AND $product->id_manufacturer_default > 1)
   $manufacturer = New Manufacturer((int)($product->id_manufacturer_default));
 }

 if (!Validate::isLoadedObject($manufacturer) OR !$manufacturer->active)
  return;
 // Get infos
 $manufacturerProducts = $manufacturer->getProducts((int)($cookie->id_lang), 1, 100); /* 100 products max. */
 $sizeOfManufacturerProducts = (int)sizeof($manufacturerProducts);
 $middlePosition = 0;

 // Remove current product from the list
 if (is_array($manufacturerProducts) AND sizeof($manufacturerProducts))
 {
  foreach ($manufacturerProducts AS $key => $manufacturerProduct)
   if ($manufacturerProduct['id_product'] == $idProduct)
   {
 unset($manufacturerProducts[$key]);
 break;
   }
  $taxes = Product::getTaxCalculationMethod();
  if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE'))
   foreach ($manufacturerProducts AS $key => $manufacturerProduct)
 if ($manufacturerProduct['id_product'] != $idProduct)
 {
  if ($taxes == 0 OR $taxes == 2)
   $manufacturerProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$manufacturerProduct['id_product'], true, NULL, 2);
  elseif ($taxes == 1)
   $manufacturerProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$manufacturerProduct['id_product'], false, NULL, 2);
 }

  // Get positions
  $middlePosition = round($sizeOfManufacturerProducts / 2, 0);
  $productPosition = $this->getCurrentProduct($manufacturerProducts, (int)$idProduct);

  // Flip middle product with current product
  if ($productPosition)
  {
   $tmp = $manufacturerProducts[$middlePosition-1];
   $manufacturerProducts[$middlePosition-1] = $manufacturerProducts[$productPosition];
   $manufacturerProducts[$productPosition] = $tmp;
  }

  // If products tab higher than 30, slice it
  if ($sizeOfManufacturerProducts > 30)
  {
   $manufacturerProducts = array_slice($manufacturerProducts, $middlePosition - 15, 30, true);
   $middlePosition = 15;
  }
 }

 // Display tpl
 $smarty->assign(array(
  'manufacturerProducts' => $manufacturerProducts,
  'middlePosition' => (int)$middlePosition,
  'ProdDisplayPrice' => Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')));
 return $this->display(__FILE__, 'productsmanufacturer.tpl');
}

public function hookHeader($params)
{
 Tools::addCSS($this->_path.'productsmanufacturer.css', 'all');
 Tools::addJS(array($this->_path.'productsmanufacturer.js', _PS_JS_DIR_.'jquery/jquery.serialScroll-1.2.2-min.js'));
}
}

 

Thanks in advance for your help and your time.

 

Cheers,

 

Gregg

Link to comment
Share on other sites

  • 5 months later...

Hello,

 

I used with success this code on my product pages (Prestashop 1.4.7). Thanks for the tutorial :)

In my case, I use it for artists instead of manufacturers.

 

But I have a problem in the product list under my product page : I would like the current product not to appear in this list.

 

Can you help me to create this exception in my 'productsmanufacturer.php' script?

 

Thank you in advance !

Link to comment
Share on other sites

  • 1 year later...

Any way to repeat your process in the latest PS ?

Im more then sure that I made the nessecary alterations for the database querys. However it takes the manufacturer id, but still shows categorys ( but now it shows the category which is corresponding to the manfucaturer id ) [ if manufacturer id is 4 then it will show category which id is 4 ]

 

Can anyone help me ? Here is my code with alterations which should work ...

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

if (!defined('_PS_VERSION_'))
	exit;

class productsCategory extends Module
{
 	private $_html;

	public function __construct()
 	{
 	 	$this->name = 'productscategory';
 	 	$this->version = '1.5';
		$this->author = 'PrestaShop';
 	 	$this->tab = 'front_office_features';
		$this->need_instance = 0;
		
		parent::__construct();
		
		$this->displayName = $this->l('Products Category');
		$this->description = $this->l('Display products of the same category on the product page.');
 	}

	public function install()
	{
		Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', 0);
		$this->_clearCache('productscategory.tpl');
	 	return (parent::install()
			&& $this->registerHook('productfooter')
			&& $this->registerHook('header')
			&& $this->registerHook('addproduct')
			&& $this->registerHook('updateproduct')
			&& $this->registerHook('deleteproduct')
		);
	}
	
	public function uninstall()
	{
		Configuration::deleteByName('PRODUCTSCATEGORY_DISPLAY_PRICE');
		$this->_clearCache('productscategory.tpl');
	 	return parent::uninstall();
	}
	
	public function getContent()
	{
		$this->_html = '';
		if (Tools::isSubmit('submitCross') AND Tools::getValue('displayPrice') != 0 AND Tools::getValue('displayPrice') != 1)
			$this->_html .= $this->displayError('Invalid displayPrice');
		elseif (Tools::isSubmit('submitCross'))
		{
			Configuration::updateValue('PRODUCTSCATEGORY_DISPLAY_PRICE', Tools::getValue('displayPrice'));
			$this->_clearCache('productscategory.tpl');
			$this->_html .= $this->displayConfirmation($this->l('Settings updated successfully'));
		}
		$this->_html .= '
		<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
		<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
			<label>'.$this->l('Display price on products').'</label>
			<div class="margin-form">
				<input type="radio" name="displayPrice" id="display_on" value="1" '.(Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE') ? 'checked="checked" ' : '').'/>
				<label class="t" for="display_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
				<input type="radio" name="displayPrice" id="display_off" value="0" '.(!Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE') ? 'checked="checked" ' : '').'/>
				<label class="t" for="display_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
				<p class="clear">'.$this->l('Show the price on the products in the block.').'</p>
			</div>
			<center><input type="submit" name="submitCross" value="'.$this->l('Save').'" class="button" /></center>
		</fieldset>
		</form>';
		return $this->_html;
	}
	
	private function getCurrentProduct($products, $id_current)
	{
		if ($products)
			foreach ($products AS $key => $product)
				if ($product['id_product'] == $id_current)
					return $key;
		return false;
	}
	
	public function hookProductFooter($params)
	{
		$id_product = (int)$params['product']->id;
		$product = $params['product'];
		
		$cache_id = 'productscategory|'.$id_product.'|'.(isset($params['manufacturer']->id_manufacturer) ? (int)$params['manufacturer']->id_manufacturer : $product->id_manufacturer);

		if (!$this->isCached('productscategory.tpl', $this->getCacheId($cache_id)))
		{
			/* If the visitor has came to this product by a category, use this one */
			if (isset($params['manufacturer']->id_manufacturer))
				$category = $params['manufacturer'];
			/* Else, use the default product category */
			else
			{
				if (isset($product->id_manufacturer) AND $product->id_manufacturer > 1)
					$category = new Category((int)$product->id_manufacturer);
			}
			
			if (!Validate::isLoadedObject($category) OR !$category->active) 
				return;

			// Get infos
			$categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
			$sizeOfCategoryProducts = (int)sizeof($categoryProducts);
			$middlePosition = 0;
			
			// Remove current product from the list
			if (is_array($categoryProducts) AND sizeof($categoryProducts))
			{
				foreach ($categoryProducts AS $key => $categoryProduct)
					if ($categoryProduct['id_product'] == $id_product)
					{
						unset($categoryProducts[$key]);
						break;
					}

				$taxes = Product::getTaxCalculationMethod();
				if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE'))
					foreach ($categoryProducts AS $key => $categoryProduct)
						if ($categoryProduct['id_product'] != $id_product)
						{
							if ($taxes == 0 OR $taxes == 2)
								$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], true, NULL, 2);
							elseif ($taxes == 1)
								$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], false, NULL, 2);
						}
			
				// Get positions
				$middlePosition = round($sizeOfCategoryProducts / 2, 0);
				$productPosition = $this->getCurrentProduct($categoryProducts, (int)$id_product);
			
				// Flip middle product with current product
				if ($productPosition)
				{
					$tmp = $categoryProducts[$middlePosition-1];
					$categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
					$categoryProducts[$productPosition] = $tmp;
				}
			
				// If products tab higher than 30, slice it
				if ($sizeOfCategoryProducts > 30)
				{
					$categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
					$middlePosition = 15;
				}
			}
			
			// Display tpl
			$this->smarty->assign(array(
				'categoryProducts' => $categoryProducts,
				'middlePosition' => (int)$middlePosition,
				'ProdDisplayPrice' => Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')));
		}
		return $this->display(__FILE__, 'productscategory.tpl', $this->getCacheId($cache_id));
	}
	
	public function hookHeader($params)
	{
		$this->context->controller->addCSS($this->_path.'productscategory.css', 'all');
		$this->context->controller->addJS($this->_path.'productscategory.js');
		$this->context->controller->addJqueryPlugin(array('scrollTo', 'serialScroll'));
	}

	public function hookAddProduct($params)
	{
		$this->_clearCache('productscategory.tpl');
	}

	public function hookUpdateProduct($params)
	{
		$this->_clearCache('productscategory.tpl');
	}

	public function hookDeleteProduct($params)
	{
		$this->_clearCache('productscategory.tpl');
	}
}

Edited by senso321 (see edit history)
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...