I have a doubt, in my filters I need that, when clicking on a color, for example BLUE, it opens the variations of BLUE below (Navy Blue, Dark Blue..) I thought about making 2 attributes, one as master color, and another as a secondary color, however, I can't figure out how to display this. So that when you click on the color, it displays the secondary colors below. How can I do this? Is there a search engine that can help me, or something similar?
Hello @viniaraujo493a
Master Color Attribute:
Secondary Color Attribute:
Override Attribute PHTML Files:
Add JavaScript Logic:
// Sample JavaScript (replace with actual implementation) require([ 'jquery', 'underscore', 'Magento_Swatches/js/swatch-renderer' ], function ($, _, swatchRenderer) { // Listen for changes in the master color dropdown $('.swatch-attribute.master_color').on('click', '.swatch-option', function () { var selectedMasterColor = $(this).attr('option-id'); // Use AJAX to fetch and update the secondary color swatches // Example: You might have an endpoint that returns secondary colors based on the master color $.ajax({ url: '/getSecondaryColors/' + selectedMasterColor, type: 'GET', dataType: 'json', success: function (data) { // Update the secondary color swatches swatchRenderer.clear(); swatchRenderer.updateBaseImage(data); swatchRenderer.updateSelect(data); }, error: function () { console.error('Failed to fetch secondary colors.'); } }); }); });
Create a Controller/Endpoint:
Return JSON Response: