Jump to content

different banner per category


Recommended Posts

  • 5 months later...

Edit header.php and change:

$smarty->assign(array(
   'HOOK_HEADER' => Module::hookExec('header'),
   'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'),
   'HOOK_TOP' => Module::hookExec('top'),
   'static_token' => Tools::getToken(false),
   'token' => Tools::getToken(),
   'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
   'content_only' => intval(Tools::getValue('content_only'))
));



to:

$smarty->assign(array(
   'HOOK_HEADER' => Module::hookExec('header'),
   'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'),
   'HOOK_TOP' => Module::hookExec('top'),
   'static_token' => Tools::getToken(false),
   'token' => Tools::getToken(),
   'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
   'content_only' => intval(Tools::getValue('content_only')),
   'id_category' => $_GET['id_category']
));



Then you can access $id_category in header.tpl.

Link to comment
Share on other sites

Hey that code works brilliantly... thank a mil..

just needed to know one more thing... the point is that the banner that i want changes per parent category and not for the sub categories...

so when a person is browsing the sub categories the banner of the parent category should show.

now the issue here is that i can hard code the thing to work with the present categories. but in the future if i add sub categories or parent categories it would be an issue.

any hints on this one?

Link to comment
Share on other sites

@Rocky


I understand the header.php part but what exactly do I do with: "Then you can access $id_category in header.tpl" ?

I have several categories and they all have the same header except for two categories (e.g. ID's)
If I understand it correctly I have to put some extra code for the ID's 7 and 8 (in my case) in the header.tpl. But to be honest, I don't know how....


Best regards,

Steven

Link to comment
Share on other sites

I think you could write something like this in header.php to get the parent category of the current category:

$category = new Category($_GET['id_category']);
$parentCategory = $category->id_parent;



and then pass it in to header.tpl like in my original post.

Link to comment
Share on other sites

thanks a mil.

the earlier code that you had given me to access the parent category id to change the banner worked great.

however i want to use the same in the category-tree-branch.tpl but the $id_parentcategory doesnt seem to be accessible there.

is there a way to set it globally or something if not how can one achieve that?

Link to comment
Share on other sites

You must modify line 10 and 12 of modules/blockcategories/blockcategories.tpl and change them to:

{include file=$branche_tpl_path node=$child parent=$parentCategory last='true'}



and:

{include file=$branche_tpl_path node=$child parent=$parentCategory}



This will pass the parent category variable into the template so that you can access it using {$parent}.

Link to comment
Share on other sites

Yep, like in my previous code, you must enter:

$category = new Category($_GET['id_category']);
$parentCategory = $category->id_parent;
$smarty->assign('parentCategory', $parentCategory);



so that $parentCategory can be accessed by blockcategories.tpl and then passed into category-tree-branch.tpl.

Link to comment
Share on other sites

  • 2 weeks later...

Hi Guys,


I got the code working for the main categories. What I would like to have is that the product page under a main categorie has the the same header.

For example:

A main categorie has picture 1. When you click on a product in that main categorie it's shows the actual product. In this page I would like to have the same header as it's main categorie(picture 1.) Is that possible and how do I achieve that?

Any one?


Regards,

Steven

Link to comment
Share on other sites

Hi steven,
I had the same problem. This is how i solved it
1) in your header.php you have to do add the code to get the parent category id using the _.Get method as pointed out by rocky earlier in this post
2) pass it as a smarty assign for the header.tpl
3) compare the parent id in if statemet in header.tpl for appropriate banner per parent id

You will also have to check for product id by doing a _get(id_product) then use that to get the parent of that product to compare in the header.tpl just in case the user is on the product details page.

Link to comment
Share on other sites

Hi Hardik,

Thanks for your reply. Sorry for being a noob but I not quit get it. What do you mean by "pass it as a smarty assign" and how do I do that?
This is my code in the header.php:

$smarty->assign(array(
   'HOOK_HEADER' => Module::hookExec('header'),
   'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'),
   'HOOK_TOP' => Module::hookExec('top'),
   'static_token' => Tools::getToken(false),
   'token' => Tools::getToken(),
   'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
   'content_only' => intval(Tools::getValue('content_only')),
   'id_category' => $_GET['id_category']
)); 



This is the code in the header.tpl:

{if $id_category == 2 }

{elseif $id_category == 4 }

{elseif $id_category == 5 }

{elseif $id_category == 7 }

{elseif $id_category == 8 }


{else}


{/if}



In this situation every main category has its own header. What do I have to add to make the productpages have the same header as the main category of that product?

Thanks a lot in advance.

Regards,

Steven

Link to comment
Share on other sites

Hi Steve,
Been a little busy so couldnt reply back. here's the code. I saw your website and noticed that you do not have sub categories, so the below mentioned code should work fine.

in your header.php add

$category = new Category($_GET['id_category']);
$parentCategory = $category->id_parent; 

if (isset($_GET['id_product']))
       {
           $product = new Product(intval($_GET['id_product']));
           $categ1 = $product->id_category_default;
       }

$smarty->assign(array(
   'HOOK_HEADER' => Module::hookExec('header'),
   'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'),
   'HOOK_TOP' => Module::hookExec('top'),
   'static_token' => Tools::getToken(false),
   'token' => Tools::getToken(),
   'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_,
   'content_only' => intval(Tools::getValue('content_only')),
   'id_parentcategory' => $parentCategory,
   'categ1' => $categ1

));



in your header.tpl


{if $categ1 == 2 || $id_parentcategory == 2 }


               {elseif $categ1 == 6 || $id_parentcategory == 6 }


               {elseif $categ1 == 12 || $id_parentcategory == 12}


               {elseif $categ1 == 13 || $id_parentcategory == 13}


               {else}

{/if}



Hope you can go live as soon as possible.

Link to comment
Share on other sites

  • 7 months later...

Hi guys.

I've trying with the $path variable. As you know, this variable is used in breadcrumb to show wherre you are. I´ve been using it to show a different banner for each manufacturer and runs ok, but when I´ve tried to use it with the categorys simply it doesn't work.

The file with which I want to work product-list.tpl an this is the code that I´ve using:


{assign var='banner' value=$path|lower}
{assign var='thecategory' value=$banner}

{assign var='width' value='540'}
{assign var='height' value='250'}

{if ($thecategory  == 'category1')}
   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=6,0,47,0" id="animation" width="{$width}" height="{$height}">




   <embed src="img/banners/{$thecategory}.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="{$width}" height="{$height}" wmode="transparent"></embed>
   </object>{/if}

{if ($banner == 'manufacturer1')}
   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=6,0,47,0" id="animation" width="{$width}" height="{$height}">




   <embed src="img/banners/{$banner}.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="{$width}" height="{$height}" wmode="transparent"></embed>
   </object>

{elseif ($banner == 'manufacturer2')}
   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=6,0,47,0" id="animation" width="{$width}" height="{$height}">




   <embed src="img/banners/{$banner}.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="{$width}" height="{$height}" wmode="transparent"></embed>
   </object>



Anyone knows why dosn't work with the categorys if the $path returns category1?

Thanks, and sorry for my english (i'm spanish).

Link to comment
Share on other sites

×
×
  • Create New...