現在、『Be Yours』というテーマのストアをセットアップしていますが、バリエーションごとに複数の画像を持つ機能を実装しました。
以下の通りです。
そこで、読み込んだ時点でバリエーションごとの画像が表示されるようにしたいです。
分かる方がいれば教えてほしいです(>_<)
class VariantSelects extends HTMLElement {
constructor() {
super();
this.addEventListener('change', this.onVariantChange);
}
onVariantChange(event) {
this.updateOptions();
this.updateMasterId();
this.toggleAddButton(true, '', false);
this.updatePickupAvailability();
this.removeErrorMessage();
this.validateGang();
if (!this.currentVariant) {
this.toggleAddButton(true, '', true);
this.setUnavailable();
} else {
if(this.gangOption) {
this.updateGangMedia();
} else {
this.updateMedia();
}
this.filterThumbnails();
this.updateURL();
this.updateVariantInput();
this.renderProductInfo();
}
this.handleStickyCart(event.target);
}
...
}
filterThumbnails() {
if (this.currentVariant.featured_media != null && this.currentVariant.featured_media.alt != null) {
$('[data-thumbnail-color]').hide();
const selected_color = this.currentVariant.featured_media.alt;
const thumbnail_selector = '[data-thumbnail-color = "' + selected_color + '"]';
$(thumbnail_selector).show();
} else {
$('[data-thumbnail-color]').show();
}
}