How To Create Featured Products Slider in Prestashop 1.7

How To Create Featured Products Slider in Prestashop 1.7

After the article Slider for home featured products in Prestashop 1.6 was released, people usually ask how to create a slider for featured products in Prestashop 1.7. This article will describe all the steps of creating a slider and will help you perform it easily.

featured-products slider in prestashop 1.7

First, let’s decide which slider plugin we will use to implement into featured product list. There are many slider plugins and you are able to implement any in Prestashop 1.7. I like Swiper and I’ll show how to implement it into the product list. Let’s start.

First, we need to include Swiper files into our theme. There are several ways to do that. General information about how to include Swiper files listed here. The ways to include Swiper into Prestashop 1.7 theme are following.

1. Using NPM:

In the downloaded package, we need files from the dist/ folder. Style files should be included into theme.scss file:

@import “~swiper/dist/swiper.min.css”;

Java Script files should be included into theme.js file:

import ‘swiper/dist/swiper.jquery.min’;

2. Include files into _dev theme folder. Download actual Swiper files. Place style files into _dev/css/ components folder and call them into theme.scss file:

@import “components/swiper.min”;

Place Java Script files into _dev/js/lib folder and call them into theme.js file:

import ‘./lib/swiper.jquery.min’;

These two ways described above are expected that you are using theme compilation with Webpack. Those our blog reader who found it’s hard to compile theme, may use custom.css (classic/assets/css/custom.css) and custom.js(classic/assets/css/custom.js) files in order to include Swiper files.

Next step we’ll create a HTML markup. Open ps_featuredproducts.tpl file. Here is a full path to this file:
themes/classic/modules/ps_featuredproducts/views/templates/hook/ps_featuredproducts.tpl. When we open file we see the following code:

Let’s modify this code in order to implement slider. Wrap product.tpl inclusion into “swiper-slide” container. Then wrap “swiper-slide” into “swiper-wrapper” container and add class “swiper-container” to “products” container. This is a base markup of Swiper Slider. This markup listed at Swiper API. Also let’s add “swiper-pagination” and “swiper-button” containers that are being slider controls. Below is a final markup:

Next step we need to initialize Swiper using the following function:

new Swiper(swiperContainer, parameters) – initialize swiper with options:

  • swiperContainer – HTMLElement or string (with CSS Selector) of swiper container HTML element. Required.
  • parameters – object – object with Swiper parameters. Optional.

Let’s create file featured-products-slider.js and include it into theme.js file:

import ‘./components/featured-products-slider’;

Now let’s initialize Swiper in featured-products-slider.js file:

The result you can see here: http://belvg.net/prestashop-themes/PS17-demo/

Feel free to ask any questions and I’ll reply you as soon as possible.



12 comments

  1. hi lena,
    thanks for the tutorial very very good.
    hm.. i want ask.
    how to instal swiper in my hosting.
    thank you.

    enda :)

  2. hello Lena..i cannot understand your instructions. could you plz instruct me one more time??

  3. I dont understand how to instal with npm .. coz i know that must be instal via terminal or console right ?

  4. Dear Lena,

    Thank you for this amazing tutorial.

    i just have a question about someting.
    i followd the tutorial but de slider does not slide when i click on the next and prev buttons.
    can you please help me out?

    Thanx a lot!

Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *