This is the complete documentation for Product Attachments & Downloads for Magento 2 (module STM_ProductAttachments, version 2.1.2). Everything on this page is free to read — no registration, no account. The same documents are attached to the Marketplace listing as PDF downloads.

Product Attachments & Downloads for Magento 2 adds downloadable files to your products: data sheets, manuals, certificates, price lists, images, videos and YouTube videos. Customers find them in their own tab on the product page, can preview them without leaving the page and download them with one click. In the admin you attach files on the product, in a central grid, to many products at once, by CSV import or automatically with rules.

Item Details
Composer package storetown-media/module-product-attachments
Magento module STM_ProductAttachments
Version 2.1.2
Requirements Magento Open Source or Adobe Commerce 2.4, PHP 8.1 to 8.5
Themes Luma and Luma-based themes
Libraries phpoffice/phpspreadsheet, phpoffice/phpword and phpoffice/phppresentation for the Office preview; Composer installs them with the extension
Languages English, German (i18n/de_DE.csv)

User Guide

Set up and use every feature, with its place in the admin and its effect in the store.

1. Getting started

After the installation (see the Installation Guide) the extension is switched on. Products without attachments look as before: the tab appears only on products that have at least one attachment.

  1. Check the settings under Stores › Configuration › STM › Product Attachments, above all the allowed file types and the maximum file size.
  2. Optional: create attachment categories such as Manuals, Data Sheets or Certificates (section 7).
  3. Attach a first file to a product (section 2) and open the product page in the store.
Configuration with the quick actions Manage Attachments, Add New Attachment and Import Attachments (CSV), followed by General Settings and File Settings.
Figure 1. Configuration with the quick actions Manage Attachments, Add New Attachment and Import Attachments (CSV), followed by General Settings and File Settings.

2. Attachments on the product

Catalog › Products › edit a product › section “Product Attachments”

Click Add Attachment and fill in one row per file:

Field Meaning
File Upload the file. Allowed types and the maximum size come from the configuration (File Settings).
YouTube URL Instead of a file: the address of a YouTube video (youtube.com/watch?v=…, youtu.be/… or youtube.com/embed/…).
Title The name customers see, for example “User Manual”.
Sort Order Lower numbers appear first.
Category Optional attachment category (section 7).

Save the product. The attachments are stored together with the product.

3. Managing all attachments

Catalog › Product Attachments › Manage Attachments

The grid lists the attachments of all products with title, file, type, video URL, size, product SKU, product name, category, downloads and creation date. It has search, filters and the mass actions Delete and Assign Category.

Manage Attachments: all attachments of all products in one grid.
Figure 2. Manage Attachments: all attachments of all products in one grid.

Add New Attachment opens the form with Title, File or YouTube URL, Product SKU, Category and Sort Order. The product is found by its SKU when you save.

New Attachment: title, file or YouTube URL, product SKU, category and sort order.
Figure 3. New Attachment: title, file or YouTube URL, product SKU, category and sort order.

4. One file for many products

Catalog › Products › select products › Actions › Assign Attachment

Select the products in the product grid and choose Assign Attachment. On the next page drop the file into the upload area, enter the title and the sort order and save. The same file is attached to every selected product, for example a safety data sheet for a whole series. The product grid also gets the column Attachments with the number of attachments per product.

Product grid with the mass action Assign Attachment.
Figure 4. Product grid with the mass action Assign Attachment.

5. CSV import

Catalog › Product Attachments › Import Attachments

  1. Copy the files to pub/media/import/attachments/ on the server.
  2. Create a CSV file (comma as separator, first row with the column names).
  3. Select the CSV file and click Import. The result shows the number of imported rows and, for rows that failed, the row number and the reason (the first ten on screen).
sku,title,file_path,category,sort_order
PROD-001,User Manual,manual.pdf,Manuals,0
PROD-001,Data Sheet,datasheet.pdf,Data Sheets,1
PROD-002,Certificate,cert.pdf,Certificates,0
Column Required Content
sku yes SKU of an existing product.
title yes Title shown to customers.
file_path yes File name inside pub/media/import/attachments/, for example manual.pdf. The file type must be allowed in the configuration.
category no Name of an existing attachment category. An unknown name imports the row without category.
sort_order no Number, lower numbers first. Default 0.

The import copies each file to pub/media/stm/attachments/. If a file of the same name exists there, the copy gets a number (manual_1.pdf). The files in the import folder stay; delete them when the import is done.

Import Attachments with the steps and an example file.
Figure 5. Import Attachments with the steps and an example file.

6. Auto-assign rules

Catalog › Product Attachments › Auto-Assign Rules

A rule attaches one file (or one YouTube video) to all products that match its conditions, for example the washing instructions to all T-shirts of a category.

Field Meaning
Rule Name, Active Name in the grid; only active rules are applied.
Priority Lower numbers are processed first.
Apply on Save Applies the rule each time you save it.
Match ALL conditions (product must meet every condition) or ANY condition (one is enough).
Conditions Condition Type Product Category, Attribute Set or Product Attribute; operator is, is not, is one of or is not one of; value. Categories are entered by ID, several IDs separated by commas for “is one of”. For a product attribute enter its code, for example manufacturer or color.
File, YouTube URL The attachment the rule adds.
Attachment Title, Category, Sort Order How the attachment appears on the product page.

A rule runs

  • when you save it with Apply on Save,
  • from the grid with the mass action Apply Rules,
  • every night at 2:00 if Enable Nightly Rule Execution is set to Yes (Stores › Configuration › STM › Product Attachments › Auto-Assign Rules; needs the Magento cron).

Each run adds the attachment only to products that do not have it from this rule yet, so running a rule twice creates no duplicates. Products that no longer match keep their attachment. Deleting a rule also deletes the attachments it created. When a run adds attachments, the full page cache is cleaned so the product pages show them at once.

Auto-Assign Rules grid with status, attachment title, category, file and priority.
Figure 6. Auto-Assign Rules grid with status, attachment title, category, file and priority.

7. Attachment categories

Stores › Configuration › STM › Product Attachments › Attachment Categories

Categories group the attachments on the product page, for example Manuals, Data Sheets and Certificates. Add a row per category with name and sort order and save the configuration. New names become new categories; a name you remove is set inactive, not deleted. With Group by Category (Display Settings) the product page shows one block per category in the order of the sort order.

Display Settings, Attachment Categories and File Extension Icons in the configuration.
Figure 7. Display Settings, Attachment Categories and File Extension Icons in the configuration.

8. The product page

The tab (title under General Settings, default “Attachments”) lists the attachments with file type badge or thumbnail, title, size, number of downloads and the buttons Preview and Download; YouTube videos get a button that plays the video. What is shown is set under Display Settings: file size, file type icon, download count, sort order (position, title, date or file size), grouping by category and the preview.

Download sends the file with its title as file name and counts the download. The download address only works for products that are enabled and visible in the current store view.

Attachments tab grouped by category, with Preview and Download buttons.
Figure 8. Attachments tab grouped by category, with Preview and Download buttons.

9. Preview

With Enable Inline Preview the button Preview opens the file in a window on the product page. Office files, text and CSV are converted to HTML on your server; no external viewer and no third-party service is used.

Format Preview
PDF The PDF in the browser’s PDF viewer.
Images (jpg, jpeg, png, gif, webp) The image itself.
Video (mp4, webm) Video player of the browser.
YouTube Embedded player from youtube-nocookie.com.
Text (txt) Text with detected encoding (UTF-8, Windows-1252, ISO-8859-1, ISO-8859-15).
CSV Table; separator detected automatically.
Word (doc, docx) Converted with PhpWord.
Excel (xls, xlsx) Converted with PhpSpreadsheet.
PowerPoint (pptx) Slides converted with PhpPresentation. The old format .ppt cannot be previewed; the window asks to save the file as .pptx.

Only file types listed under Allowed File Extensions can be uploaded. webp is previewable but not in the default list; add it there if you need it.

10. Who may download

Stores › Configuration › STM › Product Attachments › Access Restrictions

Setting Effect
Allow Guest Downloads = No Visitors who are not logged in cannot download or preview.
Restrict by Customer Group = Yes Logged-in customers may download and preview only if their group is selected under Allowed Customer Groups.

The list of attachments stays visible to everyone; a blocked download or preview answers with the store’s 404 page. All three settings can be set per website and store view.

11. File type badges

Each attachment shows a coloured badge with a short label. The extension installs this file type list:

Extension Label Colour
pdf PDF #d93025
doc Word #1a73e8
docx Word #1a73e8
xls Excel #188038
xlsx Excel #188038
csv CSV #188038
ppt PowerPoint #d56e0c
pptx PowerPoint #d56e0c
jpg Image #8430ce
jpeg Image #8430ce
png Image #8430ce
gif Image #8430ce
zip Archive #5f6368
rar Archive #5f6368
txt Text #5f6368

The list is stored in the table stm_attachment_file_extensions. Version 2.1.2 opens it at the admin address stm_attachment/extension/index (no menu entry): there you change label, colour and an own icon per type; icons are stored in pub/media/stm/extension_icons/. Images show their own thumbnail.

12. Troubleshooting

Symptom Cause and fix
No tab on the product page The product has no attachment, or the extension is switched off for this store view (General Settings).
Upload refused File type not in Allowed File Extensions, or the file is larger than Max File Size or the PHP limits upload_max_filesize and post_max_size.
Download or preview shows 404 Access restrictions (section 10), the product is disabled or not visible in this store view, or the file is missing in pub/media/stm/attachments/.
Rule added nothing Rule inactive, no product matches (check category IDs and attribute codes), or every matching product has the attachment already.
Nightly rules do not run Enable Nightly Rule Execution is No, or the Magento cron does not run.
Import row: file not found The file is not in pub/media/import/attachments/ or the name in file_path differs (upper and lower case count).
Changes not visible in the store Run bin/magento cache:flush or clean the full page cache.

13. Support

Support is provided by Storetown Media through the support link of this extension on the Adobe Commerce Marketplace and at moin@storetown-media.de.

Installation Guide

Install with Composer from repo.magento.com, check, update, switch off and remove.

1. Before you start

  • Your access keys for repo.magento.com. You find them in your Commerce Marketplace account under My Profile › Access Keys.
  • PHP 8.1 to 8.5, Composer 2 and command line access to the Magento root directory.
  • Back up files and database. On a live store, switch on maintenance mode during the installation (bin/magento maintenance:enable).

2. Install with Composer

Run in the Magento root directory (the folder that contains app and bin):

composer require storetown-media/module-product-attachments
bin/magento module:enable STM_ProductAttachments
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:flush

If Composer asks for a username and password, enter the public key as username and the private key as password. setup:static-content:deploy is only needed in production mode. Composer also installs phpoffice/phpspreadsheet, phpoffice/phpword and phpoffice/phppresentation (MIT licence) for the Office preview.

The installation creates the tables stm_product_attachments, stm_attachment_categories, stm_attachment_file_extensions, stm_attachment_rules and the file type list. Uploaded files are stored in pub/media/stm/attachments/, own icons in pub/media/stm/extension_icons/; Magento creates the folders on the first upload.

3. Check the installation

bin/magento module:status STM_ProductAttachments

The answer must say that the module is enabled. In the admin you then find:

  • Catalog › Product Attachments with Manage Attachments, Auto-Assign Rules and Import Attachments.
  • Stores › Configuration › STM › Product Attachments with the groups Manage & Import, General Settings, File Settings, Display Settings, Attachment Categories, File Extension Icons, Auto-Assign Rules and Access Restrictions.
  • In Catalog › Products the mass action Assign Attachment and, on the product edit page, the section Product Attachments.

Attach a file to a product, save, run bin/magento cache:flush and open the product page: the tab “Attachments” lists the file.

For the nightly rule run the Magento cron must be set up (bin/magento cron:install).

4. Updates

composer update storetown-media/module-product-attachments
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
bin/magento cache:flush

Attachments, files, categories, rules and settings are kept.

5. Switch off and uninstall

Switch off the module without removing anything:

bin/magento module:disable STM_ProductAttachments
bin/magento setup:upgrade
bin/magento cache:flush

Since version 2.1.2 the tables stay when the module is disabled. To hide the tab only, set General Settings › Enable Product Attachments to No instead.

Remove the extension:

bin/magento module:disable STM_ProductAttachments
composer remove storetown-media/module-product-attachments
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush

The tables (stm_product_attachments, stm_attachment_categories, stm_attachment_file_extensions, stm_attachment_rules) and the files in pub/media/stm/attachments/ and pub/media/stm/extension_icons/ stay until you delete them yourself.

6. Common errors

Symptom Cause and fix
Composer asks for a username and password The access keys for repo.magento.com are missing in the project (section 1).
Composer refuses the PHP version The extension needs PHP 8.1 to 8.5.
Menu Catalog › Product Attachments missing Run bin/magento setup:upgrade and bin/magento cache:flush; check the ACL role of the admin user (Reference Manual, section 4).
Upload fails The web server cannot write to pub/media/, or the file exceeds the PHP limits upload_max_filesize and post_max_size.
Office preview shows an error Run composer install so the phpoffice packages are present; save old .ppt files as .pptx.

Help

For installation questions use the support link of this extension on the Adobe Commerce Marketplace or write to moin@storetown-media.de.

Reference Manual

This manual lists every setting, admin page, permission, address, table and folder of the extension. It is generated from the source code of version 2.1.2 and therefore matches the backend. The User Guide explains the use with examples.

1. Module

Item Value
Composer package storetown-media/module-product-attachments
Magento module STM_ProductAttachments
Version 2.1.2
PHP 8.1, 8.2, 8.3, 8.4 and 8.5
Install path vendor/storetown-media/module-product-attachments/
Depends on magento/framework, magento/module-backend, magento/module-catalog, magento/module-config, magento/module-customer, magento/module-media-storage, magento/module-store, magento/module-ui, phpoffice/phppresentation, phpoffice/phpspreadsheet, phpoffice/phpword

Service contracts in STM\ProductAttachments\Api: AttachmentRepositoryInterface, CategoryRepositoryInterface, FileExtensionRepositoryInterface, RuleRepositoryInterface.

2. Configuration

Stores › Configuration › STM › Product Attachments · configuration path stm_attachments/…

General Settings

Field Meaning and path Default Scope
Enable Product Attachments Show attachments tab on product pages.
stm_attachments/general/enabled
Yes Global, Website, Store View
Tab Title Title of the attachments tab on the product page.
stm_attachments/general/tab_title
Attachments Global, Website, Store View

File Settings

Field Meaning and path Default Scope
Allowed File Extensions Comma-separated list of file extensions that can be uploaded and imported.
stm_attachments/file/allowed_extensions
pdf,doc,docx,xls,xlsx,ppt,pptx,jpg,jpeg,png,gif,zip,rar,txt,csv,mp4,avi,mov,webm Global
Max File Size (MB) Maximum upload file size in megabytes. The PHP limits upload_max_filesize and post_max_size of the server apply as well.
stm_attachments/file/max_file_size
10 Global

Display Settings

Field Meaning and path Default Scope
Show File Size Display the file size next to attachment name.
stm_attachments/display/show_file_size
Yes Global, Website, Store View
Show File Type Icon Display a file type icon/badge for each attachment.
stm_attachments/display/show_file_icon
Yes Global, Website, Store View
Show Download Count Display download count for each attachment.
stm_attachments/display/show_download_count
No Global, Website, Store View
Open in New Window Opens the Download link in a new browser tab.
stm_attachments/display/open_in_new_window
Yes Global, Website, Store View
Sort Attachments By Default sort order for attachments on product pages.
Values: Position (Sort Order), Title (A-Z), Date (Newest First), File Size
stm_attachments/display/sort_by
Position (Sort Order) Global, Website, Store View
Group by Category Group attachments by category on the product page.
stm_attachments/display/group_by_category
No Global, Website, Store View
Enable Inline Preview Shows a Preview button next to each attachment that can be previewed (PDF, images, video, text, CSV, Word, Excel, PowerPoint). Opens in a modal on the product page.
stm_attachments/display/enable_preview
Yes Global, Website, Store View

Attachment Categories

Field Meaning and path Default Scope
Categories Category name and sort order. Saving the configuration creates new categories; names that are removed are set inactive, not deleted.
stm_attachments/categories/items
– Global

File Extension Icons

Field Meaning and path Default Scope
Custom File Extensions Saved with the configuration. The badges on the product page are taken from the file type list (User Guide, section 11).
stm_attachments/extension_icons/items
– Global

Auto-Assign Rules

Field Meaning and path Default Scope
Enable Nightly Rule Execution Runs all active rules every night at 2:00 (Magento cron, group default).
stm_attachments/rules/cron_enabled
No Global

Access Restrictions

Field Meaning and path Default Scope
Restrict by Customer Group Allows downloads and previews only for logged-in customers of the groups selected below. The list of attachments stays visible.
stm_attachments/access/restrict_to_customer_groups
No Global, Website, Store View
Allowed Customer Groups Customer groups that may download and preview attachments. Empty means all groups.
stm_attachments/access/allowed_customer_groups
– Global, Website, Store View
Allow Guest Downloads Set to No to allow downloads and previews only for logged-in customers.
stm_attachments/access/guest_access
Yes Global, Website, Store View

3. Admin menu

Entry under Catalog › Product Attachments Address ACL
Manage Attachments stm_attachment/manage/index STM_ProductAttachments::manage
Auto-Assign Rules stm_attachment/rule/index STM_ProductAttachments::rules
Import Attachments stm_attachment/import/index STM_ProductAttachments::import

Further admin pages without menu entry: the mass action Assign Attachment in Catalog › Products, the section Product Attachments on the product edit page, and the grids stm_attachment/category/index and stm_attachment/extension/index.

4. Permissions (ACL)

Resource Title
STM_ProductAttachments::attachments Product Attachments
STM_ProductAttachments::manage Manage Attachments
STM_ProductAttachments::categories Manage Categories
STM_ProductAttachments::file_extensions Manage File Extensions
STM_ProductAttachments::rules Auto-Assign Rules
STM_ProductAttachments::import Import Attachments
STM_ProductAttachments::config Storetown Product Attachments

5. Admin routes

Front name stm_attachment (router admin).

Route Method ACL Purpose
stm_attachment/attachment/massAssign POST …::manage Assign Attachment form (from the product grid)
stm_attachment/attachment/massAssignPost POST …::manage Attach the file to the selected products
stm_attachment/attachment/upload POST …::manage File upload of the forms
stm_attachment/category/delete POST …::categories Delete category
stm_attachment/category/edit GET …::categories New or edit category
stm_attachment/category/index GET …::categories Grid of attachment categories
stm_attachment/category/massDelete POST …::categories Delete selected categories
stm_attachment/category/save POST …::categories Save category
stm_attachment/extension/delete POST …::file_extensions Delete file type
stm_attachment/extension/edit GET …::file_extensions New or edit file type
stm_attachment/extension/iconUpload POST …::file_extensions Icon upload of the file type form
stm_attachment/extension/index GET …::file_extensions File type list (badges)
stm_attachment/extension/massDelete POST …::file_extensions Delete selected file types
stm_attachment/extension/save POST …::file_extensions Save file type
stm_attachment/import/index GET …::import CSV import form
stm_attachment/import/process POST …::import Run the CSV import
stm_attachment/manage/delete POST …::manage Delete one attachment
stm_attachment/manage/edit GET …::manage New or edit attachment
stm_attachment/manage/index GET …::manage Grid of all attachments
stm_attachment/manage/massCategoryAssign POST …::manage Assign a category to selected attachments
stm_attachment/manage/massDelete POST …::manage Delete selected attachments
stm_attachment/manage/productSearch GET …::manage Product lookup for the form
stm_attachment/manage/save POST …::manage Save attachment
stm_attachment/rule/apply POST …::rules Apply one rule now
stm_attachment/rule/delete POST …::rules Delete rule and the attachments it created
stm_attachment/rule/edit GET …::rules New or edit rule
stm_attachment/rule/index GET …::rules Auto-Assign Rules grid
stm_attachment/rule/massApply POST …::rules Apply selected rules now
stm_attachment/rule/massDelete POST …::rules Delete selected rules
stm_attachment/rule/save POST …::rules Save rule (optionally apply it)
stm_attachment/rule/upload POST …::rules File upload of the rule form

6. Storefront routes

Front name stm_attachment (router standard).

Route Purpose
stm_attachment/download/index/id/{id} Sends the file as download with the attachment title as file name and increases the download count. YouTube attachments redirect to the video.
stm_attachment/preview/index/id/{id} Delivers the preview: PDF, images and video as file, text, CSV and Office files as HTML. The content type comes from a fixed list per file extension (section 9).

Both answer with the 404 page if the extension is switched off, the attachment does not exist, the product is disabled or not visible in the store view, the access restrictions block the visitor, or the file is missing.

7. Database tables

stm_product_attachments · Product Attachments

Column Type Content Note
attachment_id int Attachment ID primary key, auto increment
product_id int Product ID
file_path varchar(255) File Path nullable
title varchar(255) Attachment Title
file_type varchar(100) File MIME Type nullable
file_size int File Size in Bytes nullable
sort_order int Sort Order default 0
category_id int Category ID nullable
download_count int Download Count default 0
created_at timestamp Created At default CURRENT_TIMESTAMP
video_url varchar(500) Video URL (YouTube) nullable
rule_id int Auto-Assign Rule ID nullable

Foreign keys: product_id → catalog_product_entity.entity_id (on delete CASCADE); category_id → stm_attachment_categories.category_id (on delete SET NULL); rule_id → stm_attachment_rules.rule_id (on delete CASCADE)

stm_attachment_categories · Attachment Categories

Column Type Content Note
category_id int Category ID primary key, auto increment
name varchar(255) Category Name
sort_order int Sort Order default 0
is_active smallint Is Active default 1

stm_attachment_file_extensions · Attachment File Extensions

Column Type Content Note
extension_id int Extension ID primary key, auto increment
extension varchar(20) File Extension
icon_image varchar(255) Icon Image Path nullable
label varchar(100) Extension Label
color varchar(7) Badge Color nullable
is_active smallint Is Active default 1

stm_attachment_rules · Attachment Auto-Assign Rules

Column Type Content Note
rule_id int Rule ID primary key, auto increment
name varchar(255) Rule Name
is_active smallint Is Active default 1
conditions_serialized text Conditions JSON nullable
file_path varchar(255) File Path nullable
file_type varchar(100) File MIME Type nullable
file_size int File Size in Bytes nullable
video_url varchar(500) Video URL (YouTube) nullable
attachment_title varchar(255) Attachment Title
attachment_category_id int Attachment Category ID nullable
attachment_sort_order int Attachment Sort Order default 0
sort_order int Rule Sort Order default 0
created_at timestamp Created At default CURRENT_TIMESTAMP
updated_at timestamp Updated At default CURRENT_TIMESTAMP

Foreign keys: attachment_category_id → stm_attachment_categories.category_id (on delete SET NULL)

No Magento table is changed. The tables stay when the module is disabled or removed.

8. Files and folders

Folder Content
pub/media/stm/attachments/ Uploaded attachments (product, grid, mass action, rules, CSV import).
pub/media/stm/extension_icons/ Own icons of the file type list.
pub/media/import/attachments/ Source folder for the CSV import; the import copies from here and leaves the files in place.

CSV import columns: required sku, title, file_path; optional category, sort_order. Separator comma, enclosure double quote, first row column names (not case sensitive).

9. Preview formats

Extension Content type of the preview
pdf application/pdf
jpg image/jpeg
jpeg image/jpeg
png image/png
gif image/gif
webp image/webp
mp4 video/mp4
webm video/webm
txt text/html; charset=utf-8 (converted to HTML)
csv text/html; charset=utf-8 (converted to HTML)
docx text/html; charset=utf-8 (converted to HTML)
doc text/html; charset=utf-8 (converted to HTML)
xlsx text/html; charset=utf-8 (converted to HTML)
xls text/html; charset=utf-8 (converted to HTML)
pptx text/html; charset=utf-8 (converted to HTML)
ppt text/html; charset=utf-8 (converted to HTML)

ppt shows a message instead of the slides. YouTube previews use www.youtube-nocookie.com; the module adds it and www.youtube.com to the CSP policy frame-src and img.youtube.com to img-src.

10. Cron, events and commands

Item Details
Cron job stm_attachment_apply_rules, schedule 0 2 * * *, group default; runs only if stm_attachments/rules/cron_enabled = 1
Event (admin) catalog_product_save_after: saves the attachments of the product form
Event (admin) admin_system_config_changed_section_stm_attachments: syncs the attachment categories from the configuration
Console commands none

Support

Questions about the extension are answered through the support link on its Marketplace listing and at moin@storetown-media.de.