Jump to content

Adding products to blockcategories module for product page quick and dirty (Prestashop 1.5)


defuzed
 Share

Recommended Posts

Warning: I'm terrible at php and really new to prestashop as well, this is in no way a good solution and i CANNOT guarantee either functionality or that it won't break anything anywhere else. This being said, I have seen this asked a bunch of times and never answered, so i hope this can be useful to someone. I needed it for a shop with just a few products, where the customer wasn't satisfied with only the productscategory module way of displaying the products.

 

Adding products to the category-tree-branch for the product page in blockcategories module, quick and dirty:

 

find blockcategories.php in modules/blockcategories and add

 

 if (Tools::isSubmit('id_product')) {

  if (isset($params['category']->id_category))
   $category = $params['category'];

  else
  {
   if (isset($product->id_category_default) AND $product->id_category_default > 1)
 $category = New Category((int)($product->id_category_default));
  }

  if (!Validate::isLoadedObject($product) OR !$product->active)
   return;

  $categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
  $this->smarty->assign(array(
  'categoryProducts' => $categoryProducts));
 }

 

right after

 

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

 

(should be around line 220)

 

then find category-tree-branch.tpl in [YOUR_THEME]/modules/blockcategories and add:

 

{if isset($currentCategoryId) && $node.id == $currentCategoryId && $page_name == 'product'}
 <ul>
  {foreach from=$categoryProducts item='categoryProduct' name=categoryProduct}
   <li><a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" title="{$categoryProduct.name|htmlspecialchars}">{$categoryProduct.name|truncate:30:'...'|escape:'htmlall':'UTF-8'}</a></li>
  {/foreach}
 </ul>
{/if}

 

right after

 

<a href="{$node.link|escape:'htmlall':'UTF-8'}" {if isset($currentCategoryId) && $node.id == $currentCategoryId}class="selected"{/if} title="{$node.desc|escape:'htmlall':'UTF-8'}">{$node.name|escape:'htmlall':'UTF-8'}</a>

 

(should be around line 27)

 

Let me know if it works, or what horrible sins i have commited with this :(

Share this post


Link to post
Share on other sites

  • 4 months later...

Hi,

 

Thank you for your tips. But I couldn't find the codes in blockcategories.php for Prestashop versions 1.5.4 and 1.5.5.

 

Found the following codes instead,

 

line 190

$id_product = (int)Tools::getValue('id_product');

 

line 204

$product = new Product($id_product);

 

I'd try to put your codes right after $product = new Product($id_product);. Thank you.

 

Oops, it doesn't work.

 

Regards,

Sinoland

Edited by sinoland (see edit history)

Share this post


Link to post
Share on other sites

Hi Sinoland,

 

sorry didn't realize they changed the blockcategories module since 1.5.3 (I've been using a modified blockcategories module to avoid having to modify core files, i'll upload this module later this week or over the weekend).

 

In the meantime you can try this: (worked for me on 1.5.5)

 

add the following:

$id_category = (int)Tools::getValue('id_category');
$idProduct = (int)(Tools::getValue('id_product'));
$product = new Product((int)($idProduct));
                
if (Tools::isSubmit('id_product')) {
	if (isset($params['category']->id_category))
		$category = $params['category'];
	else
		{
		if (isset($product->id_category_default) AND $product->id_category_default > 1)
			$category = New Category((int)($product->id_category_default));
		}
			
		if (!Validate::isLoadedObject($product) OR !$product->active) 
			return;

		// Get infos
		$categoryProducts = $category->getProducts($this->context->language->id, 1, 100, 'price'); /* 100 products max. */

		$this->smarty->assign(array('categoryProducts' => $categoryProducts));
}
                
if (Tools::isSubmit('id_category')) {
	$category = new Category((int)($this->context->cookie->last_visited_category));
	// Get infos
	$categoryProducts = $category->getProducts($this->context->language->id, 1, 100, 'price'); 
	$this->smarty->assign(array('categoryProducts' => $categoryProducts));
}

at line 218 of 'blockcategories.php' , so in between the 'if (!$this->isCached('blockcategories.tpl', $this->getCacheId()))' and 'display = ...'

This is definitely not good coding and will probably definitely break the caching for the categories menu ... ( each time i disable a product i have to empty the modules cache folder ) but it works for me. 

I should mention that i haven't tried this with multiple levels of subcategories etc and have a quite limited catalog of only about 50 products. 

You can see it in action by visiting the link in my footer.

Good luck with it, as i said i will upload my module later this week.

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More