Jump to content

[Solved] Remote link to specific tab on product page


mikecheung

Recommended Posts

I have tried searching Google and these forums and have not found a solution. So I am hoping that someone here can help. I am currently on version 1.5 of prestashop and am still using the default idTabs plugin that comes with the package.

 

I have successfully added a custom tab via a module I am creating but cant seem to remotely link to it.

 

To be more specific, I would like to have a anchor tag that I place below the products price and when clicked it will open/activate a specific tab.

 

Does anyone know of a solution for this?

 

Your help is greatly appreciated.

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

The function of this plugin is based on the identifiers of the individual tabs.

 

So link:

<a href="#idTab99">Some tab</a>

 

Open:

<div id="idTab99">content</div>

 

Correct, but the problem is that the anchor tag needs to be within a class="idTabs" and it will not work if I define two different divs with that class (i've tried). If I take it out of the original tab group, it no longer works.

Link to comment
Share on other sites

Maybe produtctcomments-extra.tpl example will help you?

 

<script type="text/javascript">
$(function(){
$('a[href=#idTab5]').click(function(){
 $('*[id^="idTab"]').addClass('block_hidden_only_for_screen');
 $('div#idTab5').removeClass('block_hidden_only_for_screen');
 $('ul#more_info_tabs a[href^="#idTab"]').removeClass('selected');
 $('a[href="#idTab5"]').addClass('selected');
});
});
</script>

Link to comment
Share on other sites

Maybe produtctcomments-extra.tpl example will help you?

 

<script type="text/javascript">
$(function(){
$('a[href=#idTab5]').click(function(){
 $('*[id^="idTab"]').addClass('block_hidden_only_for_screen');
 $('div#idTab5').removeClass('block_hidden_only_for_screen');
 $('ul#more_info_tabs a[href^="#idTab"]').removeClass('selected');
 $('a[href="#idTab5"]').addClass('selected');
});
});
</script>

 

Thanks Krystian, I was thinking about doing it manually as well, but figured i'd ask before I try it. You sharing the code really helps. I was using productComments as a guide as well, but missed this.

 

Appreciate the help. If there is any cleaner way to do this, please do share.

Link to comment
Share on other sites

You can place this code in function, something like:

 

function changeTab(tabID)
{
$('a[href=#idTab'+tabID+']').click(function(){
 $('ul#more_info_tabs a[href^="#idTab"]').removeClass('selected');
 $('a[href="#iidTab'+tabID+"]').addClass('selected');
});
}
<a href="#" class="changeTab" data-tab="99" title="My Tab">My Tab</a>
$('.changeTab').click(function()
{
changeTab($(this).data('tab'));
});

Link to comment
Share on other sites

Maybe produtctcomments-extra.tpl example will help you?

 

<script type="text/javascript">
$(function(){
$('a[href=#idTab5]').click(function(){
 $('*[id^="idTab"]').addClass('block_hidden_only_for_screen');
 $('div#idTab5').removeClass('block_hidden_only_for_screen');
 $('ul#more_info_tabs a[href^="#idTab"]').removeClass('selected');
 $('a[href="#idTab5"]').addClass('selected');
});
});
</script>

 

Edited the above code a bit to be more versatile. Just add the class "linkTab" and target ID as the href to any anchor tag and the below code will detect which tab you are referring to.

 

$('a[href^=#].linkTab').click(function(){
tabId = $(this).attr('href');
$('*[id^="idTab"]').addClass('block_hidden_only_for_screen');
$('div' + tabId).removeClass('block_hidden_only_for_screen');
$('ul#more_info_tabs a').removeClass('selected');
$('a[href="' + tabId + '"]').addClass('selected');
});

Edited by mikecheung (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Edited the above code a bit to be more versatile. Just add the class "linkTab" and target ID as the href to any anchor tag and the below code will detect which tab you are referring to.

 

$('a[href^=#].linkTab').click(function(){
tabId = $(this).attr('href');
$('*[id^="idTab"]').addClass('block_hidden_only_for_screen');
$('div' + tabId).removeClass('block_hidden_only_for_screen');
$('ul#more_info_tabs a').removeClass('selected');
$('a[href="' + tabId + '"]').addClass('selected');
});

 

 

Can you show an example of tpl with this code? Thanks

Link to comment
Share on other sites

  • 2 years later...

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...