| 1 | $(function() { |
|---|
| 2 | // 規格1選択時 |
|---|
| 3 | $('select[name=classcategory_id1]') |
|---|
| 4 | .change(function() { |
|---|
| 5 | var $form = $(this).parents('form'); |
|---|
| 6 | var product_id = $form.find('input[name=product_id]').val(); |
|---|
| 7 | var $sele1 = $(this); |
|---|
| 8 | var $sele2 = $form.find('select[name=classcategory_id2]'); |
|---|
| 9 | |
|---|
| 10 | // 規格1のみの場合 |
|---|
| 11 | if (!$sele2.length) { |
|---|
| 12 | checkStock($form, product_id, $sele1.val(), '0'); |
|---|
| 13 | // 規格2ありの場合 |
|---|
| 14 | } else { |
|---|
| 15 | setClassCategories($form, product_id, $sele1, $sele2); |
|---|
| 16 | } |
|---|
| 17 | }); |
|---|
| 18 | |
|---|
| 19 | // 規格2選択時 |
|---|
| 20 | $('select[name=classcategory_id2]') |
|---|
| 21 | .change(function() { |
|---|
| 22 | var $form = $(this).parents('form'); |
|---|
| 23 | var product_id = $form.find('input[name=product_id]').val(); |
|---|
| 24 | var $sele1 = $form.find('select[name=classcategory_id1]'); |
|---|
| 25 | var $sele2 = $(this); |
|---|
| 26 | checkStock($form, product_id, $sele1.val(), $sele2.val()); |
|---|
| 27 | }); |
|---|
| 28 | }); |
|---|
| 29 | /** |
|---|
| 30 | * 規格2のプルダウンを設定する. |
|---|
| 31 | */ |
|---|
| 32 | function setClassCategories($form, product_id, $sele1, $sele2, selected_id2) { |
|---|
| 33 | if ($sele1 && $sele1.length) { |
|---|
| 34 | var classcat_id1 = $sele1.val() ? $sele1.val() : ''; |
|---|
| 35 | if ($sele2 && $sele2.length) { |
|---|
| 36 | // 規格2の選択肢をクリア |
|---|
| 37 | $sele2.children().remove(); |
|---|
| 38 | |
|---|
| 39 | var classcat2; |
|---|
| 40 | |
|---|
| 41 | // 商品一覧時 |
|---|
| 42 | if (typeof productsClassCategories != 'undefined') { |
|---|
| 43 | classcat2 = productsClassCategories[product_id][classcat_id1]; |
|---|
| 44 | } |
|---|
| 45 | // 詳細表示時 |
|---|
| 46 | else { |
|---|
| 47 | classcat2 = classCategories[classcat_id1]; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | // 規格2の要素を設定 |
|---|
| 51 | for (var key in classcat2) { |
|---|
| 52 | var id = classcat2[key]['classcategory_id2']; |
|---|
| 53 | var name = classcat2[key]['name']; |
|---|
| 54 | var option = $('<option />').val(id ? id : '').text(name); |
|---|
| 55 | if (id == selected_id2) { |
|---|
| 56 | option.attr('selected', true); |
|---|
| 57 | } |
|---|
| 58 | $sele2.append(option); |
|---|
| 59 | } |
|---|
| 60 | checkStock($form, product_id, $sele1.val() ? $sele1.val() : '__unselected2', |
|---|
| 61 | $sele2.val() ? $sele2.val() : ''); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * 規格の選択状態に応じて, フィールドを設定する. |
|---|
| 68 | */ |
|---|
| 69 | function checkStock($form, product_id, classcat_id1, classcat_id2) { |
|---|
| 70 | |
|---|
| 71 | classcat_id2 = classcat_id2 ? classcat_id2 : ''; |
|---|
| 72 | |
|---|
| 73 | var classcat2; |
|---|
| 74 | |
|---|
| 75 | // 商品一覧時 |
|---|
| 76 | if (typeof productsClassCategories != 'undefined') { |
|---|
| 77 | classcat2 = productsClassCategories[product_id][classcat_id1]['#' + classcat_id2]; |
|---|
| 78 | } |
|---|
| 79 | // 詳細表示時 |
|---|
| 80 | else { |
|---|
| 81 | classcat2 = classCategories[classcat_id1]['#' + classcat_id2]; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | // 商品コード |
|---|
| 85 | var $product_code_default = $form.find('[id^=product_code_default]'); |
|---|
| 86 | var $product_code_dynamic = $form.find('[id^=product_code_dynamic]'); |
|---|
| 87 | if (classcat2 |
|---|
| 88 | && typeof classcat2['product_code'] != 'undefined') { |
|---|
| 89 | $product_code_default.hide(); |
|---|
| 90 | $product_code_dynamic.show(); |
|---|
| 91 | $product_code_dynamic.text(classcat2['product_code']); |
|---|
| 92 | } else { |
|---|
| 93 | $product_code_default.show(); |
|---|
| 94 | $product_code_dynamic.hide(); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | // 在庫(品切れ) |
|---|
| 98 | var $cartbtn_default = $form.find('[id^=cartbtn_default]'); |
|---|
| 99 | var $cartbtn_dynamic = $form.find('[id^=cartbtn_dynamic]'); |
|---|
| 100 | if (classcat2 && classcat2['stock_find'] === false) { |
|---|
| 101 | |
|---|
| 102 | $cartbtn_dynamic.text(fnT('j_products_001')).show(); |
|---|
| 103 | $cartbtn_default.hide(); |
|---|
| 104 | } else { |
|---|
| 105 | $cartbtn_dynamic.hide(); |
|---|
| 106 | $cartbtn_default.show(); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | // 通常価格 |
|---|
| 110 | var $price01_default = $form.find('[id^=price01_default]'); |
|---|
| 111 | var $price01_dynamic = $form.find('[id^=price01_dynamic]'); |
|---|
| 112 | if (classcat2 |
|---|
| 113 | && typeof classcat2['price01'] != 'undefined' |
|---|
| 114 | && String(classcat2['price01']).length >= 1) { |
|---|
| 115 | |
|---|
| 116 | $price01_dynamic.text(classcat2['price01']).show(); |
|---|
| 117 | $price01_default.hide(); |
|---|
| 118 | } else { |
|---|
| 119 | $price01_dynamic.hide(); |
|---|
| 120 | $price01_default.show(); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | // 販売価格 |
|---|
| 124 | var $price02_default = $form.find('[id^=price02_default]'); |
|---|
| 125 | var $price02_dynamic = $form.find('[id^=price02_dynamic]'); |
|---|
| 126 | if (classcat2 |
|---|
| 127 | && typeof classcat2['price02'] != 'undefined' |
|---|
| 128 | && String(classcat2['price02']).length >= 1) { |
|---|
| 129 | |
|---|
| 130 | $price02_dynamic.text(classcat2['price02']).show(); |
|---|
| 131 | $price02_default.hide(); |
|---|
| 132 | } else { |
|---|
| 133 | $price02_dynamic.hide(); |
|---|
| 134 | $price02_default.show(); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | // ポイント |
|---|
| 138 | var $point_default = $form.find('[id^=point_default]'); |
|---|
| 139 | var $point_dynamic = $form.find('[id^=point_dynamic]'); |
|---|
| 140 | if (classcat2 |
|---|
| 141 | && typeof classcat2['point'] != 'undefined' |
|---|
| 142 | && String(classcat2['point']).length >= 1) { |
|---|
| 143 | |
|---|
| 144 | $point_dynamic.text(classcat2['point']).show(); |
|---|
| 145 | $point_default.hide(); |
|---|
| 146 | } else { |
|---|
| 147 | $point_dynamic.hide(); |
|---|
| 148 | $point_default.show(); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | // 商品規格 |
|---|
| 152 | var $product_class_id_dynamic = $form.find('[id^=product_class_id]'); |
|---|
| 153 | if (classcat2 |
|---|
| 154 | && typeof classcat2['product_class_id'] != 'undefined' |
|---|
| 155 | && String(classcat2['product_class_id']).length >= 1) { |
|---|
| 156 | |
|---|
| 157 | $product_class_id_dynamic.val(classcat2['product_class_id']); |
|---|
| 158 | } else { |
|---|
| 159 | $product_class_id_dynamic.val(''); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|