Presentation
Prestashop natively offers the functionality to attach files to products. Under the "Options" tab on the product page, we have the "Attached files" feature.
But this feature has limitations, you cannot attach a file specifically for a shop or a language. For example, a notice in French will appear on the English store.
We have developed a module to attach a file to product for the shop and language currently selected in the product edit page:
You can define a title, a description and the file position. The file will be attached to the current selected shop and language, but can be available for all shops and all languages if needed.
A simple widget allows to display all product files on the product page:
Installation
Download the pixel_product_files.zip file from the last release assets.
Admin
Go to the admin module catalog section and click Upload a module. Select the downloaded zip file.
Manually
Move the downloaded file in the Prestashop modules directory and unzip the archive. Go to the admin module catalog section and search for "File".
Configuration
Admin
On the product page in admin, select "Modules", then "Configure" for the "Product Files" module.
Click "Add a file" to attach a file to the product.
When the shop is multi-shops or multi-languages, the file will be assigned to the current shop in the current language, except if the "Available in all shops/languages" option is checked.
Widget
In the product page template, add the following Widget:
{widget name='pixel_product_files'}
Widget options:
- id_product: Force the display for the given product id
- id_shop: Force the display for the given shop id
- id_lang: Force the display for the given language id
- template: Custom template path
- icons_path: Custom icon images base URL
Example:
{widget name='pixel_product_files' id_product='1' id_lang='1' id_shop='1' template='module:pixel_product_files/product-files.tpl' icons_path="`$urls.base_url`img/file-icons/"}
With product-files.tpl
in themes/{themeName}/modules/pixel_product_files/product-files.tpl
directory.
Template
In a custom template, browse the files as follows:
{foreach from=$files item=file}
{assign var="extension" value=$file->getFile()|pathinfo:$smarty.const.PATHINFO_EXTENSION}
File URL: {$path.docs}{$file->getFile()}
Icon: {$path.icons}{$icons[$extension]}
Title: {$file->getTitle()}
Description: {$file->getDescription()}
{/foreach}
Icons
Frontend file icons are divided into several categories:
Document (document.png): pdf, odt, doc, opt, docx, rtf
Table (table.png): csv, ods, xls, xlsx
Presentation (presentation.png): pptx, pptm, ppt, odp
Image (image.png): png, gif, svg, webp, jpeg, jpg, bmp, avif, apng, ico, tiff
Video (video.png): avi, mp4, m4v
Audio (audio.png): mp3, ogg, flac, wav, m4a, wma, aac
Archive (archive.png): zip, rar, gz, tar, bz2, xz, 7z
Other files extension are not allowed.
Set you own icon files with the icons_path
option:
{widget name='pixel_product_files' icons_path="`$urls.base_url`img/file-icons/"}
Then add icons in the img/file-icons
directory:
- /img/file-icons/document.png
- /img/file-icons/table.png
- /img/file-icons/presentation.png
- ...
In the template, display the icon as follows:
{foreach from=$files item=file}
{assign var="extension" value=$file->getFile()|pathinfo:$smarty.const.PATHINFO_EXTENSION}
{if isset($icons[$extension])}
<img src="{$path.icons}{$icons[$extension]}" alt="{$file->getTitle()}" />
{/if}
{/foreach}
Changelog
1.2.0
Prestashop 8.1 compatibility
1.1.0
Allow translating title and description when lang is global
Fix validation for extension in uppercase
File renamed before copying
1.0.0
First stable release