質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Shopify

Shopifyとは、ECサイト向けのプラットフォームを提供している企業。さらに、その企業が提供するオンラインストアやPOSシステムを指します。高いデザイン性とカスタマイズ性が評価され、世界各国のネットショップで使用されています。

HTML5

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

Webサイト

一つのドメイン上に存在するWebページの集合体をWebサイトと呼びます。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

Q&A

解決済

1回答

2202閲覧

shopify商品ページFORMのselect出力に関して

pasomtr

総合スコア20

Shopify

Shopifyとは、ECサイト向けのプラットフォームを提供している企業。さらに、その企業が提供するオンラインストアやPOSシステムを指します。高いデザイン性とカスタマイズ性が評価され、世界各国のネットショップで使用されています。

HTML5

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

Webサイト

一つのドメイン上に存在するWebページの集合体をWebサイトと呼びます。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

0グッド

0クリップ

投稿2020/10/06 11:11

編集2020/10/06 11:43

お世話になります。

今回shopifyテーマの開発でご質問があり、投稿させて頂きました。

product-template.liquidの
formの箇所でradioボタンで選択し、選択したバリエーションがカートに入るというテーマをベースに開発しています。

しかし、このFORMの部分でradioボタンを選択すると、selectの内容が変わってその内容がカートに受け渡されるのかと思うのですが、
テーマをカスタマイズしていたところradioボタンを選択してもselectの内容が切り替わらずカートに情報が一番初めに表示されている商品情報しか受け渡されなくなりました。

このradioボタンを選択してselectの内容を変更させるには、どの様にすればよいのでしょうか?
radioボタンで選択

!イメージ説明明](07808c6221e6eb47cccd6081974c99bc.png)

本来は、sizeやColorのradioボタンをクリックすると
M/ブラックと記述されている箇所が、切り替わります。

中にはバリエーションが格納されています。
イメージ説明

この切り替わるselectのHTML出力は以下です。

<select name="id" id="ProductSelect--product-template" class="product-single__variants no-js"> <option selected="selected" data-sku="100005-120-200" value="36"> M / ブラック </option> <option data-sku="100005-120-250" value="32"> M / ベージュ </option> <option data-sku="100005-120-320" value="38"> M / グリーン </option> <option data-sku="100005-130-200" value="36"> L / ブラック </option> <option data-sku="100005-130-250" value="34"> L / ベージュ </option> <option data-sku="100005-130-320" value="32"> L / グリーン </option> </select>

以下がselectの部分のliquidの記述です。

<select name="id" id="ProductSelect--{{ section.id }}" class="product-single__variants no-js"> {% for variant in product.variants %} {% if variant.available %} <option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}"> {{ variant.title }} </option> {% else %} <option disabled="disabled"> {{ variant.title }} - {{ 'products.product.sold_out' | t }} </option> {% endif %} {% endfor %} </select>

FORMの全体は以下です

{% form 'product', product, class:form_classes, id:form_id %} {% unless product.has_only_default_variant %} {% for option in product.options_with_values %} <div class="radio-wrapper js product-form__item"> <label class="single-option-radio__label{% if option.name == 'Default' or option.name == 'Title' %} hidden-label{% endif %}" for="ProductSelect-option-{{ forloop.index0 }}"> {{ option.name | escape }} </label> {% if section.settings.product_selector == 'radio' %} <fieldset class="single-option-radio" name="line_item.properties{{ option.name | handleize }}" id="ProductSelect-option-{{ forloop.index0 }}"> {% assign option_index = forloop.index %} {% for value in option.values %} {% assign variant_label_state = true %} {% if product.options.size == 1 %} {% unless product.variants[forloop.index0].available %} {% assign variant_label_state = false %} {% endunless %} {% endif %} <input type="radio" {% if option.selected_value == value %} checked="checked"{% endif %} {% unless variant_label_state %} disabled="disabled"{% endunless %} value="{{ value | escape }}" data-index="option{{ option_index }}" name="option{{ option.position }}" class="single-option-selector__radio{% unless variant_label_state %} disabled{% endunless %}" id="ProductSelect-option-{{ option.name | handleize }}-{{ value | escape }}"> <label for="ProductSelect-option-{{ option.name | handleize }}-{{ value | escape }}"{% unless variant_label_state %} class="disabled"{% endunless %}>{{ value | escape }}</label> {% endfor %} </fieldset> {% else %} <select class="single-option-selector__radio single-option-selector-{{ section.id }} product-form__input" id="SingleOptionSelector-{{ forloop.index0 }}" data-index="option{{ forloop.index }}"> {% for value in option.values %} <option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value | escape }}</option> {% endfor %} </select> {% endif %} </div> {% endfor %} {% endunless %} <select name="id" id="ProductSelect--{{ section.id }}" class="product-single__variants no-js"> {% for variant in product.variants %} {% if variant.available %} <option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}"> {{ variant.title }} </option> {% else %} <option disabled="disabled"> {{ variant.title }} - {{ 'products.product.sold_out' | t }} </option> {% endif %} {% endfor %} </select> {% if section.settings.quantity_enabled %} <div class="product-single__quantity"> <label for="Quantity" class="product-single__quantity-label js-quantity-selector">{{ 'products.product.quantity' | t }}</label> <input type="number" hidden="hidden" id="Quantity" name="quantity" value="1" min="1" class="js-quantity-selector"> </div> {% endif %} <div class="product-single__add-to-cart{% if section.settings.add_to_cart_button_size == 'large' %} product-single__add-to-cart--full-width{% endif %}"> <button type="submit" name="add" id="AddToCart--{{ section.id }}" class="btn btn--add-to-cart{% if section.settings.enable_payment_button %} btn--secondary-accent{% endif %}"{% unless current_variant.available %} disabled="disabled"{% endunless %}> <span class="btn__text"> {% if current_variant.available %} {{ 'products.product.add_to_cart' | t }} {% else %} {{ 'products.product.sold_out' | t }} {% endif %} </span> </button> {% if section.settings.enable_payment_button %} {{ form | payment_button }} {% endif %} </div> {% endform %}

FORMの基本的な仕組みを理解していないから問題なのかも知れませんが、何卒お力添え頂けますと幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

product.variants
この値がポイントになっていると思いますので、
それぞれ選択したときに上記に何が格納されているか
{{product.variants | json}}
こんな感じで確認できないでしょうか?

投稿2020/10/06 12:35

firegrape

総合スコア902

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

pasomtr

2020/10/18 10:45

ご連絡が遅くなり申し訳ございません。 ありがとうございます!! 中身を確認してスクリプト書き直しました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問