Sanjoya

define([ 'jquery', 'Magento_Ui/js/modal/modal', 'mage/url', 'mage/translate' ], function($, modal, urlBuilder, $t) { 'use strict'; return function(config, element) { var quickViewModal; var currentProductUrl = ''; // Initialize modal var modalOptions = { type: 'popup', responsive: true, innerScroll: true, title: $t('Product Quick View'), buttons: [{ text: $t('Close'), class: 'action secondary', click: function() { this.closeModal(); history.replaceState(null, '', window.location.pathname + window.location.search); } }], closed: function() { history.replaceState(null, '', window.location.pathname + window.location.search); } }; quickViewModal = modal(modalOptions, $('#product-quickview-modal')); // Handle quick view clicks $(document).on('click', '.quickview-trigger', function(e) { e.preventDefault(); var productId = $(this).data('product-id'); var productUrl = $(this).data('product-url'); var productName = $(this).data('product-name'); currentProductUrl = productUrl; // Update URL in address bar without reloading page var newUrl = productUrl; history.pushState({productId: productId}, productName, newUrl); // Update modal title $('.modal-title').text(productName); // Show loading message $('#product-quickview-content').html('
' + $t('Loading...') + '
'); // Open modal $('#product-quickview-modal').modal('openModal'); // Load product content via AJAX $.ajax({ url: urlBuilder.build('catalog/product/quickview'), type: 'GET', data: { id: productId, _: new Date().getTime() }, showLoader: true, success: function(response) { if (response.success) { $('#product-quickview-content').html(response.html); } else { $('#product-quickview-content').html('
' + $t('Unable to load product details.') + '
'); } }, error: function() { $('#product-quickview-content').html('
' + $t('Unable to load product details.') + '
'); } }); }); // Close modal handlers $(document).on('click', '.close-modal', function() { $('#product-quickview-modal').modal('closeModal'); history.replaceState(null, '', window.location.pathname + window.location.search); }); // Handle browser back button window.onpopstate = function(event) { if (event.state && event.state.productId) { // If coming back to a product, keep modal open return; } // Close modal if going back from product view if ($('#product-quickview-modal').is(':visible')) { $('#product-quickview-modal').modal('closeModal'); } }; // Close modal on ESC key $(document).keyup(function(e) { if (e.keyCode === 27 && $('#product-quickview-modal').is(':visible')) { $('#product-quickview-modal').modal('closeModal'); history.replaceState(null, '', window.location.pathname + window.location.search); } }); }; });