PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

[MODULE] Next and previous links on the product page

84 replies to this topic
#1
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
This module adds Next and Previous links on the product page that go to the next and previous product in the last visited category. It displays in the product footer by default, but it can also be repositioned to the "Product actions", "Extra Left" or "Extra Right" hooks.

UPDATE v1.1

* Friendly URLs are now used when enabled

UPDATE v1.2

* Changed so that it uses the last visited category instead of the product's default category
* Added code so that visiting the homepage is counted as the last visited category

UPDATE v1.3

* Added product name tooltip over links
* Made links translatable
* Made compatible with Prestashop v1.1

UPDATE v1.3.1

* Removed 1 from homepage

UPDATE v1.4

* Improved breadcrumb bar when navigating products
* Added option to choose whether to navigate featured products or the product's default category on the homepage
* Module can now be hooked in the Extra Left and Extra Right hooks.

UPDATE v1.4.1

* Made separate module that is compatible with Prestashop v1.1
* Improved breadcrumb bar when navigating products

UPDATE v1.4.2

* Remove compatibility code that was unnecessary now that the modules are separate

UPDATE v1.5

* Added option to loop next and previous links
* Fixed bug in PrestaShop v1.1 version of the module

Download this module from my website here.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#2
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts
Thanks for this module.

Only one thing: the links previous or next are not "rewrited" when "url rewriting" is On.

Link http://www.myshop.co...id_product=2407
should be Link http://www.myshop.co...07-name-product

#3
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
Thank you for letting me know. I thought a simple $link->getProductLink($id_product) would get the friendly URL, but it turned out to be more complicated than that. I've updated my module.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#4
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts
Links are ok now, great ! :cheese:

I noticed another problem: when I have a product in a category from another category (a product can be displayed on several category), the next link go to the other category, not staying in the curent category.
(tested on 1.1)

#5
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
I've updated my module to use the last visited category in the cookie instead of the product's default category. You'll need to uninstall and reinstall the module, since I added a hook to the homepage so visiting it is counted as the last visited category. For some reason, Prestashop doesn't do that by default.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#6
mooshi

    PrestaShop Apprentice

  • Members
  • PipPip
  • 168 posts
Thank you! very much Rocky

#7
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts
There is a "1" displayed on home

It's not working on PS 1.1

Quote

Fatal error: Call to undefined method Product::idIsOnCategoryId() in /homez.34/myshop/www/boutique/modules/productnextprevnc/productnextprevnc.php on line 29


I suggest:
What do you think about adding "name of next or previous product" in title links previous and next?
(as it's done in blockpnav module http://www.prestasho...d/31247/#141414, this previous/next module doesn't work well)

#8
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
Good idea. I've added product name tooltips to the buttons. The reason you were getting that error was because the method was changed between Prestashop v1.1 and Prestashop v1.2. In Prestashop v1.1, the function was a non-static function called isOnCategoryId(). In Prestashop v1.2, this was changed to a static function called idIsOnCategoryId(). I've written code to check which method exists and then call the right method. Let me know if it works for you.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#9
elmolight

    PrestaShop Newbie

  • Members
  • Pip
  • 4 posts
Great MOD!
However I still see "1" on the homepage :(
http://elmolight.eu/ LED lighting

#10
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
Thank you. I didn't even notice the 1 on the homepage. I've removed it.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#11
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts
It works with PS 1.1, great job

but I noticed:

featured products:

When a product is displayed as a featured product, if you go to the product using product listing, the previous and next links go to other featured products but not the current category, the products belonging to the category should be linked, not the featured products

about breadcrumb :
When a product is from another category than current category, if you go to the product page from product listing, the breadcrumb is right, it shows the current category, but if you use the previous/next links, the name of category shown in breadcrumb is the default category of the product but not the current category. So when visiting the category, the category breadcrumb change, but should stay the same for all products displayed in the category.

Not simple ;-)

Another suggestion

I display the links using extra left hook
So perhaps you could add ability to hook on extra left and why not extra right

    function hookExtraLeft($params)
{
return $this->hookProductFooter($params);
}


function hookExtraRight($params)
{
return $this->hookProductFooter($params);
}


#12
ysco

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 1015 posts
Thanks rocky i will try your module, seems to be a nice add-on.

Best regards,


ysco..

#13
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
I've fixed the breadcrumb bar issue and added the hooks. I personally think it is better to navigate the featured products when clicking on a featured product rather than navigate the product's default category, since it is consistent with the behaviour when clicking from a category. It may be confusing to jump to the product's default category. I added it as an option you can choose which behaviour you want.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#14
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts
Unfortunatly I've got this message using PS1.1 with 1.4 version

Quote

Fatal error: Call to undefined method Tools::getFullPath() in /homez.34/myshop/www/boutique/modules/productnextprevnc/productnextprevnc.php on line 125


I've changed Tools::getFullPath with Tools::getlPath, no more error message but links with Featured products in categories show other featured products, not current category. configuration in BO do nothing, breadcrumb is not good too ( perhaps shouldn't be default category of product $product->id_category_default).


Quote

I personally think it is better to navigate the featured products when clicking on a featured product rather than navigate the product’s default category


Yes of course, but in my case, when I visit the category I navigate in featured products if the first product is featured, so it's better to see products of the category than featured products when navigate in a category.

#15
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
Since the getPath() function was changed in Prestashop v1.2, I had to copy the v1.2 getPath() instead of using the v1.1 one to get things working. This means I had to create two separate modules for each of the versions.

I think I've got the breadcrumb bar sorted out now. Let me know whether it works. I thought this was going to be a simple module, but it has turned out to be quite complicated.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#16
capclem

    PrestaShop Apprentice

  • Members
  • PipPip
  • 304 posts
Hello and thank you for this module.

I installed "productnextprevnc v1.4.1 for PrestaShop v1.2 .zip".
I do not see the difference between "Featured" and "Default Category".

In the 2 cases I do not surf to the default category (I wish only products of the same category)

Is it possible and which is the solution?

Thank you !

___________
EDIT

I think to know where is the trouble : all the articles of my shop are in 2 categories: home and their category… So :-S
PS 1.2.5 & PS 1.4.5.1
Hébergement : PHPNET Premium
----------------
Inscrivez votre site gratuitement sur l'annuaire au féminin
http://annuaire.tent...sclementine.com

#17
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts
It's OK for me ! breadcrumb is good,

featured products : if a customer just coming from home open a featured product wich is the first product in a category, other products linked are featured products, if he visits first other category and go to this product, it'ok, other category products are linked


because you made 2 modules for 1.1 and 1.2 (thanks a lot) perhaps, the test
// For compatibility with both Prestashop v1.1 and Prestashop v1.2, check which method exists and call it
can be removed



Something strange when I open and save the php file:

when I save the file using dreamweaver ')') is added:


so it makes error, i must use another way to save

#18
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts
other question:
how to take off name in breadcrumb, I tried to remove in code but I had an error, thank you :-)

#19
rocky

    PrestaShop Superstar

  • US Moderators
  • 9988 posts
@capclem

Make sure that the default category of your products is not "Home", but another category. Obviously, if the default category is "Home", then that is what will be displayed when the "Default category" option is selected, which happens to be the same result as when "Featured products" is selected, making it look like my module isn't working, when in fact it is.

@jolvil

To remove the product name from the breadcrumb, change line 107 of productnextprevnc.php from:


return self::getPath($id_category, Category::hideCategoryPosition($category->name), true).' '.$pipe.' '.htmlentities($end, ENT_NOQUOTES, 'UTF-8');


to:


return self::getPath($id_category, Category::hideCategoryPosition($category->name), true)/*.' '.$pipe.' '.htmlentities($end, ENT_NOQUOTES, 'UTF-8')*/;


I can't reproduce the issue you are having in Dreamweaver. I changed the line anyway to remove the == part in case it helps.
Check out Nethercott Constructions for PrestaShop guides and modules. Like us on Facebook for news updates.

#20
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts

Quote

To remove the product name from the breadcrumb, change line 107 of productnextprevnc.php from:


return self::getPath($id_category, Category::hideCategoryPosition($category->name), true).' '.$pipe.' '.htmlentities($end, ENT_NOQUOTES, 'UTF-8');


to:


return self::getPath($id_category, Category::hideCategoryPosition($category->name), true)/*.' '.$pipe.' '.htmlentities($end, ENT_NOQUOTES, 'UTF-8')*/;


I can't reproduce the issue you are having in Dreamweaver. I changed the line anyway to remove the == part in case it helps.


Thank you :-)