{"id":412139,"date":"2023-11-20T11:50:14","date_gmt":"2023-11-20T11:50:14","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=412139"},"modified":"2024-07-29T13:43:16","modified_gmt":"2024-07-29T13:43:16","slug":"magento-2-custom-content-in-configurable-product-media-gallery-part-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/","title":{"rendered":"Magento 2 Custom Content in Configurable Product Media Gallery"},"content":{"rendered":"\n<p>Today, we will learn how can we add extra or custom content or media to Configurable Products\u2019 Fotorama media gallery at the front end in visual and text swatches case.<\/p>\n\n\n\n<p>Check our blog on Add Custom Content in Configurable Product Media Gallery in Magento 2 for <a href=\"https:\/\/webkul.com\/blog\/custom-content-in-configurableproduct-media-gallery-magento2\/\" target=\"_blank\" rel=\"noreferrer noopener\">drop-down swatch type<\/a>.<\/p>\n\n\n\n<p>In Magento 2, on the configurable product page, for rendering the swatch attributes, <em>&lt;magento-root-dir.&gt;\/vendor\/magento\/module-swatches\/view\/base\/web\/js\/swatch-renderer.js <\/em>file is responsible.<\/p>\n\n\n\n<p>So, to add extra content in the configurable product&#8217;s media gallery(in text and visual swatch case), we need to override a few methods of the swatch-renderer js file. <\/p>\n\n\n\n<p>For example, <strong>updateBaseImage<\/strong>, <strong>_onGalleryLoaded<\/strong> and <strong>_loadMedia<\/strong> functions are responsible for updating the media gallery after swatch rendering and swatch selection.<\/p>\n\n\n\n<p>So, to add the custom content I have overridden the required functions and added some required files which are required to achieve our goal.<\/p>\n\n\n\n<p>First of all, we will <a href=\"https:\/\/webkul.com\/blog\/create-hello-module-in-magento2\/\" target=\"_blank\" rel=\"noreferrer noopener\">create a demo module<\/a>. Here, I have created the <strong>Webkul_ExtraContentInFotorama<\/strong> module. Further, follow the below steps:<\/p>\n\n\n\n<p><strong>1. <\/strong>Create a <strong>di.xml <\/strong>file inside the <em>&lt;magento-root-dir&gt;\/app\/code\/Webkul\/ExtraContentInFotorama\/<\/em>etc\/<em> <\/em>directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;!--\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_ExtraContentInFotorama\n * @author    Webkul Software Private Limited\n * @copyright Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\n--&gt;\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:ObjectManager\/etc\/config.xsd&quot;&gt;\n  &lt;!--Add Extra Configuration Data In JsonConfig--&gt;\n  &lt;type name=&quot;Magento\\ConfigurableProduct\\Block\\Product\\View\\Type\\Configurable&quot;&gt;\n    &lt;plugin name=&quot;Wk_afterGetJsonConfig&quot;\n      type=&quot;Webkul\\ExtraContentInFotorama\\Plugin\\ConfigurableProduct\\Block\\ConfigurableAfterGetJsonConfigPlugin&quot;\n      sortOrder=&quot;50&quot; \/&gt;\n\t&lt;\/type&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p><strong>2.<\/strong> Create <strong>ConfigurableAfterGetJsonConfigPlugin.php<\/strong> file inside the <em>&lt;magento-root-dir&gt;\/app\/code\/Webkul\/ExtraContentInFotorama\/Plugin\/ConfigurableProduct\/Block\/<\/em> directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_ExtraContentInFotorama\n * @author    Webkul Software Private Limited\n * @copyright Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\nnamespace Webkul\\ExtraContentInFotorama\\Plugin\\ConfigurableProduct\\Block;\n\nclass ConfigurableAfterGetJsonConfigPlugin\n{\n    \/**\n     * @var \\Magento\\Framework\\App\\RequestInterface\n     *\/\n    protected $request;\n\n    \/**\n     * @var \\Magento\\Framework\\Json\\Helper\\Data\n     *\/\n    protected $jsonHelper;\n\n    \/**\n     * Initialize dependencies\n     *\n     * @param \\Magento\\Framework\\Json\\Helper\\Data $jsonHelper\n     * @param \\Magento\\Framework\\App\\RequestInterface $request\n     * @return void\n     *\/\n    public function __construct(\n        \\Magento\\Framework\\Json\\Helper\\Data $jsonHelper,\n        \\Magento\\Framework\\App\\RequestInterface $request\n    ) {\n        $this-&gt;request    = $request;\n        $this-&gt;jsonHelper = $jsonHelper;\n    }\n\n    \/**\n     * Composes configuration for js\n     *\n     * @param \\Magento\\ConfigurableProduct\\Block\\Product\\View\\Type\\Configurable $subject\n     * @param string $resultJson\n     * @return string\n     *\/\n    public function afterGetJsonConfig(\n        \\Magento\\ConfigurableProduct\\Block\\Product\\View\\Type\\Configurable $subject,\n        $resultJson\n    ) {\n        \/\/Check if request is made from product page\/\/\n        if (strtolower($this-&gt;request-&gt;getFullActionName()) == &quot;catalog_product_view&quot;) {\n            $result = $this-&gt;jsonHelper-&gt;jsonDecode($resultJson);\n\n            \/\/\/\/\/Set Extra Configuration Data\/\/\/\/\/\n            $customConfig = &#091;];\n            \n            $customConfig&#091;&quot;linkUrl&quot;] = &quot;https:\/\/webkul.com\/blog\/design-patterns-in-magento-2\/&quot;;\n            $customConfig&#091;&quot;thumbnailImage&quot;] = &quot;Provide a thumbnail Image URL&quot;;\n            $customConfig&#091;&quot;linkContent&quot;] =  &quot;Design Patterns in Magento 2&quot;;\n\n            \/\/set super attribute id, on which selection you want to change the content\/\/\n            $customConfig&#091;&quot;defaultVariantAttribute&quot;] = 138; \n\n            $result&#091;&quot;customConfig&quot;] = $customConfig;\n\n            $resultJson = $this-&gt;jsonHelper-&gt;jsonEncode($result);\n\n            \/\/\/\/\/\/\/\/\/\n        }\n       \n        return $resultJson;\n    }\n}<\/pre>\n\n\n\n<p><strong>3.<\/strong> Create a <strong>requires-config.js<\/strong> file to mention the mixin file for the <strong>swatch-renderer.js<\/strong> file inside the <em>&lt;magento-root-dir.&gt;\/app\/code\/Webkul\/ExtraContentInFotorama\/view\/frontend\/<\/em> directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_ExtraContentInFotorama\n * @author    Webkul Software Private Limited\n * @copyright Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\nvar config = {\n    config: {\n        mixins: {\n            &#039;Magento_Swatches\/js\/swatch-renderer&#039; : {&#039;Webkul_ExtraContentInFotorama\/js\/swatch-renderer&#039;:true}\n        }\n    }\n};<\/pre>\n\n\n\n<p><strong>4.<\/strong> Create a <strong>swatch-renderer.js <\/strong>file inside the <em>&lt;magento-root-dir.&gt;\/app\/code\/Webkul\/ExtraContentInFotorama\/view\/frontend\/web\/js\/<\/em> directory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/**\n * Webkul Software.\n *\n * @category  Webkul\n * @package   Webkul_ExtraContentInFotorama\n * @author    Webkul Software Private Limited\n * @copyright Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\ndefine(&#091;\n    &#039;jquery&#039;,\n    &#039;underscore&#039;,\n    &#039;mage\/translate&#039;\n], function ($, _, $t) {\n    &#039;use strict&#039;;\n\n    return function (SwatchRenderer) {\n        \n        $.widget(&#039;mage.SwatchRenderer&#039;, SwatchRenderer, {\n            \/**\n             * Update &#091;gallery-placeholder] or &#091;product-image-photo]\n             * @param {Array} images\n             * @param {jQuery} context\n             * @param {Boolean} isInProductView\n             *\/\n            updateBaseImage: function (images, context, isInProductView) {\n                var self = this.options.jsonConfig.customConfig; \/\/Load Custom Content Config.\n\n                \/\/\/Check if linkUrl is empty\/\/\n                if (self.linkUrl == &quot;&quot; || self.linkUrl == null) {\n                    return this._super(images, context, isInProductView);\n                }\n                \/\/\/\/\/\n\n                var justAnImage = images&#091;0],\n                    initialImages = this.options.mediaGalleryInitial,\n                    imagesToUpdate,\n                    gallery = context.find(this.options.mediaGallerySelector).data(&#039;gallery&#039;),\n                    isInitial;\n\n                if (isInProductView) {\n                    if (_.isUndefined(gallery)) {\n                        context.find(this.options.mediaGallerySelector).on(&#039;gallery:loaded&#039;, function () {\n                            this.updateBaseImage(images, context, isInProductView);\n                        }.bind(this));\n\n                        return;\n                    }\n\n                    imagesToUpdate = images.length ? this._setImageType($.extend(true, &#091;], images)) : &#091;];\n                    isInitial = _.isEqual(imagesToUpdate, initialImages);\n\n                    if (this.options.gallerySwitchStrategy === &#039;prepend&#039; &amp;&amp; !isInitial) {\n                        \/\/Remove Additional Extra Content\n                        initialImages = this._removeExtraContentfromArray(initialImages);\n                        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\n                        imagesToUpdate = imagesToUpdate.concat(initialImages);\n                    }\n\n                    imagesToUpdate = this._setImageIndex(imagesToUpdate);\n\n                    gallery.updateData(imagesToUpdate);\n                    this._addFotoramaVideoEvents(isInitial);\n                } else if (justAnImage &amp;&amp; justAnImage.img) {\n                    context.find(&#039;.product-image-photo&#039;).attr(&#039;src&#039;, justAnImage.img);\n                }\n            },\n\n            \/**\n             * Callback which fired after gallery gets initialized.\n             *\n             * @param {HTMLElement} element - DOM element associated with a gallery.\n             *\/\n            _onGalleryLoaded: function (element) {\n                var galleryObject = element.data(&#039;gallery&#039;);\n\n                \/\/\/\/\/\/\/\/\/\/\/\/\n                var currImgs = galleryObject.returnCurrentImages();\n            \n                \/\/Load Extra Content\/\/\n                this._loadExtraContent();\n\n                \/\/Push Extra Content in images gallery\n                var self = this.options.jsonConfig.customConfig;\n                var modelThumbnailImg = self.thumbnailImage;\n                \n                this._pushExtraContent(currImgs, modelThumbnailImg);\n                \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\n                this.options.mediaGalleryInitial = currImgs;\n\n                \/\/\/Update Current Images in Media Gallery\/\/\/\n                galleryObject.updateData(currImgs);\n            },\n\n            \/**\n             * Load media gallery using ajax or json config.\n             *\n             * @private\n             *\/\n            _loadMedia: function () {\n                var self = this.options.jsonConfig.customConfig; \/\/Get Custom Config.\n\n                var $main = this.inProductList ?\n                        this.element.parents(&#039;.product-item-info&#039;) :\n                        this.element.parents(&#039;.column.main&#039;),\n                    images;\n\n                if (this.options.useAjax) {\n                    this._debouncedLoadProductMedia();\n                }  else {\n                    images = this.options.jsonConfig.images&#091;this.getProduct()];\n\n                    if (!images) {\n                        images = this.options.mediaGalleryInitial;\n                    }\n\n                    \/\/\/\/\/\/\/\/\/\/\/\/Load Extra Content\/\/\/\/\/\n                    this._loadExtraContent();\n                    \/\/Remove Extra Content from image array\n                    images = this._removeExtraContentfromArray(images);\n\n                    var self = this.options.jsonConfig.customConfig;\n                    var modelThumbnailImg = self.thumbnailImage;\n                    \n                    \/\/Push Extra Content from image array\n                    this._pushExtraContent(images, modelThumbnailImg);\n                    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n            \n                    this.updateBaseImage(this._sortImages(images), $main, !this.inProductList);\n                }\n            },\n\n\n            \/**\n             * Delete Additional Extra Content from array\n             * \n             * @param {Array} imagesArray\n             * @returns {Array}\n             * @private\n             *\/\n            _removeExtraContentfromArray: function(imagesArray) {\n                imagesArray = imagesArray.filter(element =&gt; element.type !== &quot;ExtraContent&quot;);\n                return imagesArray;\n            },\n\n            \/**\n             * Push Extra Content in array\n             * \n             * @param {Array} fotoramaContentArray\n             * @param {string} modelThumbnailImg\n             * @private\n             *\/\n            _pushExtraContent: function(fotoramaContentArray, modelThumbnailImg) {\n                var self = this.options.jsonConfig.customConfig;\n\n                if (typeof fotoramaContentArray != &quot;undefined&quot; &amp;&amp; \n                    (self.linkUrl != &quot;&quot; || self.linkUrl != null)) {\n                        fotoramaContentArray.unshift({\n                        thumb: modelThumbnailImg,\n                        src: self.linkUrl,\n                        type: &#039;ExtraContent&#039;,\n                        caption: self.linkContent,\n                        isMain: &quot;true&quot;,\n                        position: 0\n                    });\n                }\n            },\n\n            \/**\n             * Get Selected Variant Value\n             * \n             * @return {string}\n             * @private\n             *\/\n            _getSelectedVariantValue: function() {\n                var self = this.options.jsonConfig.customConfig;\n                var optionTextVal = &quot;&quot;;\n                var optionTextArr = &#091;]; \n                var selectedText = &quot;&quot;;\n                var selectedVal = &quot;&quot;;\n                var selectedSwatchAttrId = 0;\n                var defaultVariantAttribute = self.defaultVariantAttribute;\n            \n                if ($(&#039;.product-options-wrapper select&#091;id^=&quot;attribute&quot;]&#039;).find().length) {\n                    selectedText = $(&#039;.product-options-wrapper select&#091;id^=&quot;attribute&quot;] option:selected&#039;).text();\n                } else {\n                    if ($(&#039;.swatch-attribute-options .swatch-option&#091;aria-checked=&quot;true&quot;]&#039;).length) {\n                        var swatchId = &quot;&quot;;\n                        var idParts = &#091;];\n                        $(&#039;.swatch-attribute-options .swatch-option&#091;aria-checked=&quot;true&quot;]&#039;).each(function() {\n                            swatchId = $(this).attr(&quot;id&quot;);\n                            idParts = swatchId.split(&#039;-&#039;);\n\n                            for (let index=0; index&lt;idParts.length; index++) {\n                                if ($.isNumeric(idParts&#091;index])) {\n                                    selectedSwatchAttrId = idParts&#091;index];\n                                    break;\n                                }\n                            }\n                            if (parseInt(defaultVariantAttribute) == selectedSwatchAttrId) {\n                                selectedText = $(this).attr(&quot;data-option-label&quot;);\n                            }\n                        });\n                    }\n                }\n\n                \/\/\/\/\/Get Selected Variant Value\/\/\/\/\/\n                selectedVal = $(&#039;.product-options-wrapper select&#091;id^=&quot;attribute&quot;] option:selected&#039;).val();\n                if (selectedVal == &quot;&quot; &amp;&amp; $(&#039;.product-options-wrapper select&#091;id^=&quot;attribute&quot;]&#039;).find().length) {\n                    selectedText = $(&#039;.product-options-wrapper select&#091;id^=&quot;attribute&quot;] option:eq(1)&#039;).text();\n                } else {\n                    selectedVal = selectedText;\n                }\n                \/\/\/\/\/\n\n                if ($(&#039;.product-options-wrapper select&#091;id^=&quot;attribute&quot;]&#039;).find().length) {\n                    if (selectedText.indexOf(&#039;+&#039;) == -1) {\n                        optionTextVal = selectedText;\n                    } else {\n                        optionTextArr =  selectedText.split(&#039;+&#039;);\n                        optionTextVal = $.trim(optionTextArr&#091;0]);\n                    }    \n                } else {\n                    optionTextVal = selectedVal;\n                }\n              \n                return optionTextVal;\n            },\n\n\n            \/**\n             * Event for swatch options\n             *\n             * @param {Object} $this\n             * @param {Object} $widget\n             * @private\n             *\/\n            _OnClick: function ($this, $widget) {\n                var self = this.options.jsonConfig.customConfig;\n                var wkExtraContentDiv = $(&quot;#wkExtraContent&quot;);\n                var mainVariantAttributeId = self.defaultVariantAttribute;\n\n                var swatchId = $this.attr(&quot;id&quot;);\n                var idParts = swatchId.split(&#039;-&#039;);\n                var selectedSwatchAttrId = 0;\n\n                for (let index=0; index&lt;idParts.length; index++) {\n                    if ($.isNumeric(idParts&#091;index])) {\n                        selectedSwatchAttrId = idParts&#091;index];\n                        break;\n                    }\n                }\n                \n                if (typeof wkExtraContentDiv == &quot;object&quot; \n                    &amp;&amp; selectedSwatchAttrId == parseInt(mainVariantAttributeId)) {\n                        var label = $this.attr(&quot;data-option-label&quot;);\n                        var bgColor = &quot;#86FA50&quot;;\n\n                        switch (label) {\n                            case &#039;Gold&#039;: bgColor = &quot;#DFD906&quot;; break;\n                            case &#039;Diamond&#039;: bgColor = &quot;#AFF3F2&quot;; break;\n                        }\n\n                        setTimeout(function(){\n                            $(&quot;#wkExtraContent&quot;).css(&quot;background-color&quot;, bgColor);\n                        }, 300);\n                        \n                }\n\n                this._super($this, $widget);\n            },\n\n            \/**\n             * Load Extra Content\n             * \n             * @private\n             *\/\n            _loadExtraContent: function() {\n                var thisJs = this;\n                var self = this.options.jsonConfig.customConfig;\n                var divFotorama = $(&#039;div.gallery-placeholder &gt; div.fotorama&#039;);\n\n                if (self.linkUrl == &quot;&quot;) {\n                    return;\n                }\n                var variantText = &quot;None&quot;;\n                 \n                \/\/Get Selected Variant Value\n                variantText = thisJs._getSelectedVariantValue();\n\n                divFotorama.on(&#039;fotorama:load&#039;, function fotorama_onLoad(e, fotorama, extra) {\n\n                    if (extra.frame.type === &#039;ExtraContent&#039; &amp;&amp; extra.frame.src != &quot;&quot;) {\n                        var extraContentHtml = &#039;&#039;;\n                       \n                        extraContentHtml += &#039;&lt;div id=&quot;wkExtraContent&quot; style=&quot;background-color:#86FA50&quot;&gt;&#039;;\n                        extraContentHtml += &#039;&lt;h1 style=&quot;margin-top:250px&quot;&gt;&#039;+&#039;Extra Content&#039;+&#039;&lt;\/h1&gt;&#039;;\n                        \/\/\/Show Variant Text\/\/\/\n                        if (variantText != &#039;&#039;) {\n                            extraContentHtml += &#039;&lt;p style=&quot;font-size:20px&quot;&gt;Selected Variant:&lt;\/p&gt;&#039;;\n                            extraContentHtml += &#039;&lt;p style=&quot;font-size:18px&quot;&gt;&#039;+variantText+&#039;&lt;\/p&gt;&lt;br\/&gt;&#039;;\n                        }\n                        \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n                        extraContentHtml += &#039;&lt;a href=&quot;&#039;+self.linkUrl+&#039;&quot; style=&quot;font-size:18px&quot;&gt;&#039;\n                        extraContentHtml += self.linkContent+&#039;&lt;\/a&gt;&#039;;\n                        extraContentHtml += &#039;&lt;\/div&gt;&#039;;\n\n                        extra.frame.$stageFrame.html(extraContentHtml);\n                    }\n                });\n            }\n\n        });\n\n        return $.mage.SwatchRenderer;\n    };\n});<\/pre>\n\n\n\n<p><strong>5.<\/strong> After adding the above code to your module. Deploy the code and see the result in the<strong> text swatch case<\/strong>. Refer to the below images for the result.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"606\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-1200x606.png\" alt=\"TextSwatchAttribute\" class=\"wp-image-412152\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-1200x606.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-300x151.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-250x126.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-768x388.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute.png 1301w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"600\" height=\"309\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchResult.gif\" alt=\"TextSwatchResult\" class=\"wp-image-412156\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p><strong>6. <\/strong>See the result in the<strong> visual swatch case<\/strong>. Refer to the below images for the result.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"605\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/VisualSwatchAttribute-1200x605.png\" alt=\"VisualSwatchAttribute\" class=\"wp-image-412154\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/VisualSwatchAttribute-1200x605.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/VisualSwatchAttribute-300x151.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/VisualSwatchAttribute-250x126.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/VisualSwatchAttribute-768x387.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/VisualSwatchAttribute.png 1300w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"600\" height=\"309\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/VisualSwatchResult.gif\" alt=\"VisualSwatchResult\" class=\"wp-image-412157\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p><strong>Note:<\/strong> Remember to add <em>&lt;sequence><\/em> in the <strong>module.xml<\/strong> file to load the <strong>Magento_Swatches<\/strong> module before your custom module.<br><br>Check the <a href=\"https:\/\/store.webkul.com\/magento2-advanced-media-manager.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Advanced Media Manager<\/a> extension that allows editing the images present in the media gallery and add watermarks, filter, rotate, resize, and more.<\/p>\n\n\n\n<p><a href=\"https:\/\/webkul.com\/hire-magento-developers\/\" target=\"_blank\" rel=\"noreferrer noopener\">Hire Magento developers<\/a> who are dedicated to achieving outstanding outcomes for your unique e-commerce ventures in order to add a personal touch.<\/p>\n\n\n\n<p>Additionally, there is no need to search further; seize the chance to kickstart your projects with the suggested <a href=\"https:\/\/webkul.com\/magento-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento development company<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we will learn how can we add extra or custom content or media to Configurable Products\u2019 Fotorama media gallery at the front end in visual and text swatches case. Check our blog on Add Custom Content in Configurable Product Media Gallery in Magento 2 for drop-down swatch type. In Magento 2, on the configurable <a href=\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":249,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9121],"tags":[14821,15164,15165,15166,2460],"class_list":["post-412139","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-add-custom-content-in-media-gallery","tag-add-extra-content-in-media-gallery","tag-custom-content-in-configurable-product-media-gallery","tag-custom-content-in-fotorama-media-gallery","tag-magento-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento 2 Custom Content in Configurable Product Media Gallery<\/title>\n<meta name=\"description\" content=\"Hello Friends, in this blog, we will learn how can we add extra content to Configurable Products&#039; Fotorama media gallery.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2 Custom Content in Configurable Product Media Gallery\" \/>\n<meta property=\"og:description\" content=\"Hello Friends, in this blog, we will learn how can we add extra content to Configurable Products&#039; Fotorama media gallery.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-20T11:50:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-29T13:43:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-1200x606.png\" \/>\n<meta name=\"author\" content=\"Khushboo Sahu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khushboo Sahu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/\"},\"author\":{\"name\":\"Khushboo Sahu\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca\"},\"headline\":\"Magento 2 Custom Content in Configurable Product Media Gallery\",\"datePublished\":\"2023-11-20T11:50:14+00:00\",\"dateModified\":\"2024-07-29T13:43:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/\"},\"wordCount\":390,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-1200x606.png\",\"keywords\":[\"add custom content in media gallery\",\"add extra content in media gallery\",\"custom content in configurable product media gallery\",\"custom content in fotorama media gallery\",\"Magento 2\"],\"articleSection\":[\"Magento 2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/\",\"name\":\"Magento 2 Custom Content in Configurable Product Media Gallery\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-1200x606.png\",\"datePublished\":\"2023-11-20T11:50:14+00:00\",\"dateModified\":\"2024-07-29T13:43:16+00:00\",\"description\":\"Hello Friends, in this blog, we will learn how can we add extra content to Configurable Products' Fotorama media gallery.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute.png\",\"width\":1301,\"height\":657,\"caption\":\"TextSwatchAttribute\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento 2 Custom Content in Configurable Product Media Gallery\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca\",\"name\":\"Khushboo Sahu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Khushboo Sahu\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/khushboo-sahu062\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento 2 Custom Content in Configurable Product Media Gallery","description":"Hello Friends, in this blog, we will learn how can we add extra content to Configurable Products' Fotorama media gallery.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/","og_locale":"en_US","og_type":"article","og_title":"Magento 2 Custom Content in Configurable Product Media Gallery","og_description":"Hello Friends, in this blog, we will learn how can we add extra content to Configurable Products' Fotorama media gallery.","og_url":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-11-20T11:50:14+00:00","article_modified_time":"2024-07-29T13:43:16+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-1200x606.png","type":"","width":"","height":""}],"author":"Khushboo Sahu","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Khushboo Sahu","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/"},"author":{"name":"Khushboo Sahu","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca"},"headline":"Magento 2 Custom Content in Configurable Product Media Gallery","datePublished":"2023-11-20T11:50:14+00:00","dateModified":"2024-07-29T13:43:16+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/"},"wordCount":390,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-1200x606.png","keywords":["add custom content in media gallery","add extra content in media gallery","custom content in configurable product media gallery","custom content in fotorama media gallery","Magento 2"],"articleSection":["Magento 2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/","url":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/","name":"Magento 2 Custom Content in Configurable Product Media Gallery","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute-1200x606.png","datePublished":"2023-11-20T11:50:14+00:00","dateModified":"2024-07-29T13:43:16+00:00","description":"Hello Friends, in this blog, we will learn how can we add extra content to Configurable Products' Fotorama media gallery.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/11\/TextSwatchAttribute.png","width":1301,"height":657,"caption":"TextSwatchAttribute"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/magento-2-custom-content-in-configurable-product-media-gallery-part-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento 2 Custom Content in Configurable Product Media Gallery"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca","name":"Khushboo Sahu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Khushboo Sahu"},"url":"https:\/\/webkul.com\/blog\/author\/khushboo-sahu062\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/412139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/249"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=412139"}],"version-history":[{"count":12,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/412139\/revisions"}],"predecessor-version":[{"id":455229,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/412139\/revisions\/455229"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=412139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=412139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=412139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}