Skip to content

Instantly share code, notes, and snippets.

@maxout
Last active November 13, 2023 09:24
Show Gist options
  • Save maxout/2ab036d233c033186416 to your computer and use it in GitHub Desktop.
Save maxout/2ab036d233c033186416 to your computer and use it in GitHub Desktop.
jQuery sort clothing sizes in select box for shopware configurator articles
$(function() {
var sizes = ["XS", "S", "M", "L", "XL", "2XL", "3XL", "4XL"],
select = $('.configurator--form select[name="group[2]"]');
$('option', select).sort(function (a, b) {
if(isNaN($(a).text().trim())){
return sizes.indexOf($(a).text().trim()) - sizes.indexOf($(b).text().trim());
}else{
return $(a).text() > $(b).text() ? 1 : $(a).text() < $(b).text() ? -1 : 0;
}
}).appendTo(select);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment