mage2kishan / module-productgallery
Custom product image gallery for Magento 2 product detail pages. Features configurable thumbnail layouts (horizontal, vertical, grid), image zoom (inner/lens), fullscreen lightbox, and responsive navigation. Compatible with Hyva and Luma themes.
Package info
github.com/mage2sk/module-productgallery
Language:HTML
Type:magento2-module
pkg:composer/mage2kishan/module-productgallery
Requires
- php: >=8.1
- mage2kishan/module-core: ^1.0
- magento/framework: ^103.0
- magento/module-backend: ^102.0
- magento/module-catalog: ^104.0
- magento/module-config: ^101.0
- magento/module-store: ^101.0
- magento/module-widget: ^101.0
Requires (Dev)
- phpunit/phpunit: ^9.5|^10.0
Suggests
- hyva-themes/magento2-default-theme: Required for Hyva theme compatibility (^1.0)
Provides
None
Conflicts
None
Replaces
None
README
Panth Product Gallery replaces the default image gallery on the Magento 2 product detail page with a gallery that is configured from the admin. It offers horizontal, vertical and grid thumbnail layouts, inner zoom on hover, a fullscreen lightbox with an image counter and keyboard navigation, and prev/next arrows on the main image. When the module is enabled, a plugin on Magento\Catalog\Block\Product\View\Gallery swaps the output of the standard gallery block for the module's own template; when it is disabled, Magento renders its default gallery again.
The module is aimed at merchants who want a different gallery layout on the product page without theme work. It ships two templates: one for Hyva (Alpine.js and Tailwind CSS) and one for Luma (vanilla JavaScript). The active theme is detected through Panth_Core and the matching template is selected automatically.
Product page: kishansavaliya.com/magento-2-productgallery.html
Features
- Three thumbnail layouts selectable in the admin: "Horizontal Thumbnails (Below Main Image)", "Vertical Thumbnails (Left of Main Image)" and "Grid (All Images Visible)".
- Inner zoom on hover over the main image (3x by default); the Luma template preloads the large image on first hover, the Hyva template shows the large image in a positioned overlay.
- Fullscreen lightbox opened by clicking the main image (or a grid item on Hyva), with prev/next controls, an optional "1 / 5" style image counter, zoom in/out buttons and mouse-wheel zoom.
- Optional keyboard navigation in the lightbox: arrow keys to move between images, Escape to close, "+" and "-" to zoom (the Hyva template also resets zoom with "0").
- Optional prev/next arrows on the main image and an optional infinite loop from the last image back to the first.
- Optional touch swipe on the main image in both templates (a left or right swipe of more than 50 px changes the image).
- The gallery opens on the product's base image.
- On Hyva, the horizontal and vertical layouts follow configurable product option changes: the
update-galleryevent sent by the Hyva configurable options script replaces the images and thumbnails, andreset-galleryrestores the parent product images. - On Luma, the gallery follows configurable swatch and drop-down option changes. The gallery element carries
data-gallery-role="gallery-placeholder"and exposes a small gallery API through jQuerydata('gallery')(updateData,returnCurrentImages,first,last,prev,next,seek), which Magento'sswatch-renderer.jsandconfigurable.jscall instead of the Fotorama gallery. The main image, thumbnails and arrows are rebuilt from the images of the selected child product, and resetting the options restores the parent images. Product videos are not shown by this gallery; when it replaces the Luma gallery, the core product video initialisation block (product.info.media.video) is not rendered. - Disabled gallery entries are skipped and images are ordered by their media gallery position.
- Every image gets an
altattribute and atitleattribute, taken from the caption and title of the core gallery images JSON (see Optional alt text integration below). - Media gallery data is added to product collections while the module is enabled, so the images are available without a second load.
- A "Panth Product Gallery" widget is declared in
etc/widget.xmlfor use through the Magento widget system. - Admin settings are available at default, website and store view scope.
- Unit tests are included under
Test/Unit.
Compatibility
| Platform | Versions |
|---|---|
| Magento Open Source | 2.4.4 to 2.4.8 |
| Adobe Commerce | 2.4.4 to 2.4.8 |
| PHP | >= 8.1 (from composer.json) |
| Themes | Hyva (Alpine.js template) and Luma (vanilla JavaScript template) |
Composer constraints for Magento packages: magento/framework ^103.0, magento/module-catalog ^104.0, magento/module-store ^101.0, magento/module-backend ^102.0, magento/module-widget ^101.0, magento/module-config ^101.0.
Requirements
- Magento Open Source or Adobe Commerce 2.4.4 to 2.4.8
- PHP 8.1 or newer
mage2kishan/module-core^1.0(required; provides the "Panth Extensions" configuration tab, the admin menu parent, the theme detection helper and the theme-config view model)- Suggested:
hyva-themes/magento2-default-theme^1.0when the store runs on Hyva
Installation
composer require mage2kishan/module-productgallery bin/magento module:enable Panth_Core Panth_ProductGallery bin/magento setup:upgrade bin/magento setup:di:compile bin/magento setup:static-content:deploy -f bin/magento cache:flush
setup:di:compile is only needed in production mode. setup:static-content:deploy -f is listed because the module ships a LESS file under view/frontend/web/css/source/ for Luma.
Check that the module is enabled:
bin/magento module:status Panth_ProductGallery
Configuration
Go to Stores > Configuration > Panth Extensions > Product Gallery. The section is also reachable from the admin menu under Panth Extensions > Product Gallery > Configuration. All settings can be set at default, website and store view scope.
General Settings
| Setting | Default | What it does |
|---|---|---|
| Enable Module | Yes | Enables the gallery replacement. When set to No, the plugin and the collection observer do nothing and Magento's default gallery is shown. |
Gallery Layout
| Setting | Default | What it does |
|---|---|---|
| Thumbnail Layout | Horizontal Thumbnails (Below Main Image) | Chooses how thumbnails are displayed relative to the main image: horizontal strip below, vertical column on the left, or a grid with all images visible. |
Zoom
| Setting | Default | What it does |
|---|---|---|
| Enable Zoom | Yes | Enables inner zoom on hover over the main gallery image. |
Lightbox
| Setting | Default | What it does |
|---|---|---|
| Enable Lightbox | Yes | Opens a fullscreen lightbox when the main image is clicked. |
| Show Image Counter | Yes | Shows a "1 / 5" counter in the lightbox. Only shown when "Enable Lightbox" is Yes. |
| Keyboard Navigation | Yes | Enables arrow key and Escape key handling in the lightbox. Only shown when "Enable Lightbox" is Yes. |
Navigation
| Setting | Default | What it does |
|---|---|---|
| Show Navigation Arrows | Yes | Shows prev/next arrows on the main image when the product has more than one image. |
| Enable Swipe | Yes | Enables touch swipe navigation on the main image. |
| Infinite Loop | No | When Yes, prev/next wrap around from the last image to the first and back. |
Design & Colors
This group has no fields. It explains that gallery colours and sizes come from etc/theme-config.json, which is registered with the Panth\Core\ViewModel\ThemeConfig view model from Panth_Core. The file defines CSS variables such as --gallery-primary, --gallery-thumb-active-border, --gallery-zoom-bg, --gallery-lightbox-bg and --gallery-border-radius, which are used by the Luma LESS file.
Config paths:
panth_productgallery/general/enabledpanth_productgallery/layout/layout_typepanth_productgallery/zoom/enable_zoompanth_productgallery/lightbox/enable_lightboxpanth_productgallery/lightbox/show_counterpanth_productgallery/lightbox/enable_keyboard_navpanth_productgallery/navigation/show_arrowspanth_productgallery/navigation/enable_swipepanth_productgallery/navigation/infinite_loop
etc/config.xml also sets defaults that have no admin field and are read through Helper\Data: layout/thumb_position (bottom), layout/main_image_width and layout/main_image_height (700), layout/thumb_width and layout/thumb_height (72), layout/visible_thumbs (5), zoom/zoom_type (inner) and zoom/zoom_level (3, clamped to 2 to 5). The main image and thumbnail sizes, and the thumbnail width and height attributes, are taken from these values.
Default behaviour after installation: the module is enabled, the horizontal layout is used, zoom, lightbox, counter, keyboard navigation and arrows are on, and infinite loop is off.
Usage
On the product page, Plugin\HideDefaultGallery runs as an afterToHtml plugin on Magento\Catalog\Block\Product\View\Gallery. It acts only on the blocks named product.media (Hyva) and product.info.media.image (Luma), builds the image list for the current product, and re-renders the block with the module template. If the product has no enabled images, or rendering fails, the original gallery HTML is returned. No layout XML overrides are needed; the layout files shipped with the module are intentionally empty.
- Hyva:
view/frontend/templates/hyva/gallery.phtmlis used. It is an Alpine.js component (panthGallery()) with Tailwind utility classes and inline styles, plus a lightbox script that appends its overlay todocument.bodyand exposes it aswindow.panthLightbox. - Luma:
view/frontend/templates/gallery.phtmlis used. It is plain JavaScript and includes its own inline<style>block; RequireJS and jQuery are only used, when present, to register the gallery API withdata('gallery')and triggergallery:loaded. Additional Luma styles are inview/frontend/web/css/source/_module.less.
Layouts: the horizontal and vertical layouts show a main image with a strip of clickable thumbnails (below or on the left) and, optionally, arrows; thumbnails are only rendered when the product has more than one image. On Hyva the grid layout lists all images in a 2-column grid (3 columns from the md breakpoint) without a separate main image, and clicking a grid item opens the lightbox. On Luma the grid option adds the panth-gallery--grid class to the wrapper, but the markup is the same main image with a thumbnail strip.
Zoom: while the cursor moves over the main image, the large image is shown scaled by the zoom level (3 by default) with the origin following the cursor. There is no lens or overlay zoom mode in the templates.
Lightbox: shows the large image size (product_page_image_large), the current position counter, prev/next arrows, zoom in/out buttons and a close button; clicking the backdrop closes it. Keyboard handling is a keydown listener on the document that is only emitted when "Keyboard Navigation" is Yes. The lightbox always wraps around at the ends regardless of the "Infinite Loop" setting, which only affects the main image navigation.
Templates can be overridden in a theme in the usual way by placing a copy under Panth_ProductGallery/templates/gallery.phtml or Panth_ProductGallery/templates/hyva/gallery.phtml. Both templates read their data from the block: panth_gallery_images, panth_gallery_config and panth_gallery_viewmodel (an instance of Panth\ProductGallery\ViewModel\Config), which the plugin sets before rendering.
Widget: etc/widget.xml declares the "Panth Product Gallery" widget backed by Block\Widget\Gallery, with a single "Template" parameter ("Default Gallery"). The block renders the gallery for the product currently in the catalog registry and outputs nothing when no product is loaded, so it is only useful on pages where a product is set.
Optional alt text integration: the alt and title of each image are read from getGalleryImagesJson() of the core Magento\Catalog\Block\Product\View\Gallery block (the caption and, when present, title keys). Plugin\HideDefaultGallery uses the gallery block it wraps; Block\Gallery creates a core gallery block for the current product. Any module that rewrites that JSON, for example an image SEO module with an after-plugin on getGalleryImagesJson(), therefore also changes the alt and title in this gallery. Without such a module the caption is the image label, or the product name when no label is set. If the JSON cannot be read or does not match the product's media gallery, the image label or product name is used.
Developer Notes
- Module name:
Panth_ProductGallery - Composer package:
mage2kishan/module-productgallery - Namespace:
Panth\ProductGallery(PSR-4 from the module root) - Load sequence: after
Magento_Catalog,Magento_Store,Panth_Core - Key classes:
Plugin\HideDefaultGallery:afterToHtmlplugin onMagento\Catalog\Block\Product\View\Gallery(declared inetc/frontend/di.xml, sort order 10)Block\Gallery:AbstractProductblock withgetGalleryImages(),getGalleryConfig(),getGalleryConfigJson(),isEnabled();getTemplate()picks the Hyva or Luma templateBlock\Widget\Gallery: widget block extendingBlock\GalleryViewModel\Config: view model exposing all configuration getters andgetGalleryConfig()Helper\Data: configuration reader forpanth_productgallery/*Observer\ProductCollectionLoadAfter: observer oncatalog_product_collection_load_afterthat callsaddMediaGalleryData()on the collection while the module is enabledModel\Config\Source\LayoutType,ThumbPosition,ZoomType: option sources (onlyLayoutTypeis used bysystem.xml)
- DI:
etc/frontend/di.xmlregisters the module withPanth\Core\ViewModel\ThemeConfig(registeredModules) soetc/theme-config.jsonis picked up - ACL resource:
Panth_ProductGallery::config("Panth Product Gallery Configuration") underMagento_Config::config - Admin menu:
Panth_ProductGallery::group("Product Gallery") andPanth_ProductGallery::settings("Configuration") underPanth_Core::panth_extensions - No database tables, controllers, routes, web API endpoints, console commands or cron jobs are defined
- Translations:
i18n/en_US.csv
Uninstallation
bin/magento module:disable Panth_ProductGallery composer remove mage2kishan/module-productgallery bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush
The module creates no database tables. Values saved under panth_productgallery/* in core_config_data remain after removal and can be deleted manually if required.
Support
- Product page: kishansavaliya.com/magento-2-productgallery.html
- Contact: kishansavaliya.com/contact
- Email: kishansavaliyakb@gmail.com
- GitHub issues: github.com/mage2sk/module-productgallery/issues
Documentation
See USER_GUIDE.md. It covers installation, verifying the module is active, configuration, gallery layouts, zoom, lightbox and navigation settings, widget usage, theme customization and troubleshooting.
License
Commercial software license. See LICENSE.txt in this repository.
Changelog
See CHANGELOG.md.
Links
- Website: kishansavaliya.com
- All extensions: kishansavaliya.com/magento-extensions.html
- GitHub: github.com/mage2sk/module-productgallery
- Packagist: packagist.org/packages/mage2kishan/module-productgallery