[Svn-src-all:1474] [version-2_5-dev 20366] #982([フロント]商品)
nanasess
admin @ mail.ec-cube.net
2011年 2月 24日 (木) 06:00:49 JST
Subversion committed to /home/svn/open 20366
http://svn.ec-cube.net/open_trac/changeset/20366
┌────────────────────────────┐
│更新者 : nanasess │
│更新日時: 2011-02-24 06:00:49 +0900 (木, 24 2月 2011)│
└────────────────────────────┘
Log:
--------------------------------------------------------
#982([フロント]商品)
* 規格プルダウンの JavaScript を抽象化
Changed: [U:修正,A:追加,D:削除]
--------------------------------------------------------
U branches/version-2_5-dev/data/Smarty/templates/default/products/detail.tpl
U branches/version-2_5-dev/data/Smarty/templates/default/products/list.tpl
U branches/version-2_5-dev/data/Smarty/templates/sphone/products/detail.tpl
A branches/version-2_5-dev/html/js/products.js
変更: branches/version-2_5-dev/data/Smarty/templates/default/products/detail.tpl
===================================================================
--- branches/version-2_5-dev/data/Smarty/templates/default/products/detail.tpl 2011-02-23 16:15:13 UTC (rev 20365)
+++ branches/version-2_5-dev/data/Smarty/templates/default/products/detail.tpl 2011-02-23 21:00:49 UTC (rev 20366)
@@ -19,150 +19,18 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*}-->
+<script type="text/javascript" src="<!--{$smarty.const.ROOT_URLPATH}-->js/products.js"></script>
<script type="text/javascript" src="<!--{$smarty.const.ROOT_URLPATH}-->js/jquery.facebox/facebox.js"></script>
<link rel="stylesheet" type="text/css" href="<!--{$smarty.const.ROOT_URLPATH}-->js/jquery.facebox/facebox.css" media="screen" />
<script type="text/javascript">//<![CDATA[
// 規格2に選択肢を割り当てる。
function fnSetClassCategories(form, classcat_id2_selected) {
- sele1 = form.classcategory_id1;
- sele2 = form.classcategory_id2;
-
- if (sele1) {
- if (sele2) {
- // 規格2の選択肢をクリア
- count = sele2.options.length;
- for(i = count; i >= 0; i--) {
- sele2.options[i] = null;
- }
-
- // 規格2に選択肢を割り当てる
- classcats = classCategories[sele1.value];
- i = 0;
- for (var classcat_id2_key in classcats) {
- classcategory_id2 = classcats[classcat_id2_key].classcategory_id2;
- sele2.options[i] = new Option(classcats[classcat_id2_key].name, classcategory_id2);
- if (classcategory_id2 == classcat_id2_selected) {
- sele2.options[i].selected = true;
- }
- i++;
- }
- }
- fnCheckStock(form);
- }
+ var $form = $(form);
+ var product_id = $form.find('input[name=product_id]').val();
+ var $sele1 = $form.find('select[name=classcategory_id1]');
+ var $sele2 = $form.find('select[name=classcategory_id2]');
+ setClassCategories($form, product_id, $sele1, $sele2, classcat_id2_selected);
}
-function fnCheckStock(form) {
- classcat_id1 = form.classcategory_id1.value;
- classcat_id2 = form.classcategory_id2 ? form.classcategory_id2.value : '';
- classcat2 = classCategories[classcat_id1]['#' + classcat_id2];
-
- // 商品コード
- eleDefault = document.getElementById('product_code_default');
- eleDynamic = document.getElementById('product_code_dynamic');
- if (
- classcat2
- && typeof classcat2.product_code != 'undefined'
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.product_code;
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- eleDynamic.style.display = 'none';
- }
-
- // 在庫(品切れ)
- eleDefault = document.getElementById('cartbtn_default');
- eleDynamic = document.getElementById('cartbtn_dynamic');
- if (
- classcat2
- && classcat2.stock_find === false
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = '申し訳ございませんが、只今品切れ中です。';
- eleDynamic.style.display = '';
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- eleDynamic.style.display = 'none';
- }
-
- // 通常価格
- eleDefault = document.getElementById('price01_default');
- eleDynamic = document.getElementById('price01_dynamic');
- if (eleDefault && eleDynamic) {
- if (
- classcat2
- && typeof classcat2.price01 != 'undefined'
- && String(classcat2.price01).length >= 1
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.price01;
- eleDynamic.style.display = '';
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- eleDynamic.style.display = 'none';
- }
- }
-
- // 販売価格
- eleDefault = document.getElementById('price02_default');
- eleDynamic = document.getElementById('price02_dynamic');
- if (
- classcat2
- && typeof classcat2.price02 != 'undefined'
- && String(classcat2.price02).length >= 1
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.price02;
- eleDynamic.style.display = '';
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- eleDynamic.style.display = 'none';
- }
-
- // ポイント
- eleDefault = document.getElementById('point_default');
- eleDynamic = document.getElementById('point_dynamic');
- if (
- classcat2
- && typeof classcat2.point != 'undefined'
- && String(classcat2.point).length >= 1
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.point;
- eleDynamic.style.display = '';
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- eleDynamic.style.display = 'none';
- }
- // 商品規格
- eleDynamic = document.getElementById('product_class_id');
- if (
- classcat2
- && typeof classcat2.product_class_id != 'undefined'
- && String(classcat2.product_class_id).length >= 1
- ) {
- eleDynamic.value = classcat2.product_class_id;
- eleDynamic.style.display = '';
- } else {
- eleDynamic.value = ''
- }
- // 商品種別
- eleDynamic = document.getElementById('product_type');
- if (
- classcat2
- && typeof classcat2.product_type != 'undefined'
- && String(classcat2.product_type).length >= 1
- ) {
- eleDynamic.value = classcat2.product_type;
- eleDynamic.style.display = '';
- } else {
- eleDynamic.value = ''
- }
-}
$(document).ready(function() {
$('a.expansion').facebox({
loadingImage : '<!--{$smarty.const.ROOT_URLPATH}-->js/jquery.facebox/loading.gif',
@@ -174,6 +42,7 @@
<!--▼CONTENTS-->
<div id="undercolumn" class="product product_detail">
+ <form name="form1" id="form1" method="post" action="?">
<div id="detailarea" class="clearfix">
<div id="detailphotobloc">
<div class="photo">
@@ -310,7 +179,6 @@
<div class="cart_area clearfix">
- <form name="form1" id="form1" method="post" action="?">
<input type="hidden" name="mode" value="cart" />
<input type="hidden" name="product_id" value="<!--{$tpl_product_id}-->" />
<input type="hidden" name="product_class_id" value="<!--{$tpl_product_class_id}-->" id="product_class_id" />
@@ -324,7 +192,7 @@
<ul class="clearfix">
<li><!--{$tpl_class_name1|h}-->:</li>
<li>
- <select name="classcategory_id1" style="<!--{$arrErr.classcategory_id1|sfGetErrorColor}-->" onchange="fnSetClassCategories(this.form);">
+ <select name="classcategory_id1" style="<!--{$arrErr.classcategory_id1|sfGetErrorColor}-->">
<!--{html_options options=$arrClassCat1 selected=$arrForm.classcategory_id1.value}-->
</select>
<!--{if $arrErr.classcategory_id1 != ""}-->
@@ -338,7 +206,7 @@
<ul class="clearfix">
<li><!--{$tpl_class_name2|h}-->:</li>
<li>
- <select name="classcategory_id2" style="<!--{$arrErr.classcategory_id2|sfGetErrorColor}-->" onchange="fnCheckStock(this.form);">
+ <select name="classcategory_id2" style="<!--{$arrErr.classcategory_id2|sfGetErrorColor}-->">
</select>
<!--{if $arrErr.classcategory_id2 != ""}-->
<br /><span class="attention">※ <!--{$tpl_class_name2}-->を入力して下さい。</span>
@@ -389,11 +257,11 @@
</div>
<!--{/if}-->
</div>
- </form>
</div>
</div>
<!--▲買い物かご-->
</div>
+ </form>
<!--詳細ここまで-->
変更: branches/version-2_5-dev/data/Smarty/templates/default/products/list.tpl
===================================================================
--- branches/version-2_5-dev/data/Smarty/templates/default/products/list.tpl 2011-02-23 16:15:13 UTC (rev 20365)
+++ branches/version-2_5-dev/data/Smarty/templates/default/products/list.tpl 2011-02-23 21:00:49 UTC (rev 20366)
@@ -19,35 +19,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*}-->
+<script type="text/javascript" src="<!--{$smarty.const.ROOT_URLPATH}-->js/products.js"></script>
<script type="text/javascript">//<![CDATA[
-// 規格2に選択肢を割り当てる。
function fnSetClassCategories(form, classcat_id2_selected) {
- sele1 = form.classcategory_id1;
- sele2 = form.classcategory_id2;
- product_id = form.product_id.value;
-
- if (sele1) {
- if (sele2) {
- // 規格2の選択肢をクリア
- count = sele2.options.length;
- for(i = count; i >= 0; i--) {
- sele2.options[i] = null;
- }
-
- // 規格2に選択肢を割り当てる
- classcats = productsClassCategories[product_id][sele1.value];
- i = 0;
- for (var classcat_id2_key in classcats) {
- classcategory_id2 = classcats[classcat_id2_key].classcategory_id2;
- sele2.options[i] = new Option(classcats[classcat_id2_key].name, classcategory_id2);
- if (classcategory_id2 == classcat_id2_selected) {
- sele2.options[i].selected = true;
- }
- i++;
- }
- }
- fnCheckStock(form);
- }
+ var $form = $(form);
+ var product_id = $form.find('input[name=product_id]').val();
+ var $sele1 = $form.find('select[name=classcategory_id1]');
+ var $sele2 = $form.find('select[name=classcategory_id2]');
+ setClassCategories($form, product_id, $sele1, $sele2, classcat_id2_selected);
}
// 並び順を変更
function fnChangeOrderby(orderby) {
@@ -77,64 +56,6 @@
fnSetVal("product_type", productForm["product_type"].value);
fnSubmit();
}
-function fnCheckStock(form) {
- product_id = form.product_id.value;
- classcat_id1 = form.classcategory_id1.value;
- classcat_id2 = form.classcategory_id2 ? form.classcategory_id2.value : '';
- classcat2 = productsClassCategories[product_id][classcat_id1]['#' + classcat_id2];
-
- // 在庫(品切れ)
- eleDefault = document.getElementById('cartbtn_default_' + product_id);
- eleDynamic = document.getElementById('cartbtn_dynamic_' + product_id);
- if (
- classcat2
- && classcat2.stock_find === false
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = '申し訳ございませんが、只今品切れ中です。';
- } else {
- eleDefault.style.display = '';
- eleDynamic.style.display = 'none';
- eleDynamic.innerHTML = '';
- }
-
- // 販売価格
- eleDefault = document.getElementById('price02_default_' + product_id);
- eleDynamic = document.getElementById('price02_dynamic_' + product_id);
- if (
- classcat2
- && typeof classcat2.price02 != 'undefined'
- && String(classcat2.price02).length >= 1
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.price02;
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- }
- // 商品規格
- eleDynamic = document.getElementById('product_class_id' + product_id);
- if (
- classcat2
- && typeof classcat2.product_class_id != 'undefined'
- && String(classcat2.product_class_id).length >= 1
- ) {
- eleDynamic.value = classcat2.product_class_id;
- } else {
- eleDynamic.value = ''
- }
- // 商品種別
- eleDynamic = document.getElementById('product_type' + product_id);
- if (
- classcat2
- && typeof classcat2.product_type != 'undefined'
- && String(classcat2.product_type).length >= 1
- ) {
- eleDynamic.value = classcat2.product_type;
- } else {
- eleDynamic.value = ''
- }
-}
//]]>
</script>
@@ -225,69 +146,69 @@
<!--{assign var=id value=$arrProduct.product_id}-->
<!--{assign var=arrErr value=$arrProduct.arrErr}-->
<!--▼商品-->
- <div class="list_area clearfix">
- <a name="product<!--{$id|h}-->"></a>
- <div class="listphoto">
- <!--★画像★-->
- <a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrProduct.product_id|u}-->" class="over"><!--商品写真--><img src="<!--{$smarty.const.IMAGE_SAVE_URLPATH|sfTrimURL}-->/<!--{$arrProduct.main_list_image|sfNoImageMainList|h}-->" alt="<!--{$arrProduct.name|h}-->" class="picture" /></a>
- </div>
+ <form name="product_form<!--{$id|h}-->" action="?" onsubmit="return false;">
+ <div class="list_area clearfix">
+ <a name="product<!--{$id|h}-->"></a>
+ <div class="listphoto">
+ <!--★画像★-->
+ <a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrProduct.product_id|u}-->" class="over"><!--商品写真--><img src="<!--{$smarty.const.IMAGE_SAVE_URLPATH|sfTrimURL}-->/<!--{$arrProduct.main_list_image|sfNoImageMainList|h}-->" alt="<!--{$arrProduct.name|h}-->" class="picture" /></a>
+ </div>
- <div class="listrightbloc">
- <!--▼商品ステータス-->
- <!--{if count($productStatus[$id]) > 0}-->
- <ul class="status_icon clearfix">
- <!--{foreach from=$productStatus[$id] item=status}-->
- <li>
- <img src="<!--{$TPL_URLPATH}--><!--{$arrSTATUS_IMAGE[$status]}-->" width="60" height="17" alt="<!--{$arrSTATUS[$status]}-->"/>
- </li>
- <!--{/foreach}-->
- </ul>
- <!--{/if}-->
- <!--▲商品ステータス-->
+ <div class="listrightbloc">
+ <!--▼商品ステータス-->
+ <!--{if count($productStatus[$id]) > 0}-->
+ <ul class="status_icon clearfix">
+ <!--{foreach from=$productStatus[$id] item=status}-->
+ <li>
+ <img src="<!--{$TPL_URLPATH}--><!--{$arrSTATUS_IMAGE[$status]}-->" width="60" height="17" alt="<!--{$arrSTATUS[$status]}-->"/>
+ </li>
+ <!--{/foreach}-->
+ </ul>
+ <!--{/if}-->
+ <!--▲商品ステータス-->
- <!--★商品名★-->
- <h3>
- <a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrProduct.product_id|u}-->" name="product<!--{$arrProduct.product_id}-->"><!--{$arrProduct.name|h}--></a>
- </h3>
- <!--★価格★-->
- <div class="pricebox sale_price">
- <!--{$smarty.const.SALE_PRICE_TITLE}-->(税込):
- <span class="price">
- <span id="price02_default_<!--{$id}-->">
- <!--{if $arrProduct.price02_min == $arrProduct.price02_max}-->
- <!--{$arrProduct.price02_min|sfCalcIncTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
- <!--{else}-->
+ <!--★商品名★-->
+ <h3>
+ <a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrProduct.product_id|u}-->" name="product<!--{$arrProduct.product_id}-->"><!--{$arrProduct.name|h}--></a>
+ </h3>
+ <!--★価格★-->
+ <div class="pricebox sale_price">
+ <!--{$smarty.const.SALE_PRICE_TITLE}-->(税込):
+ <span class="price">
+ <span id="price02_default_<!--{$id}-->">
+ <!--{if $arrProduct.price02_min == $arrProduct.price02_max}-->
+ <!--{$arrProduct.price02_min|sfCalcIncTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
+ <!--{else}-->
<!--{$arrProduct.price02_min|sfCalcIncTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->〜<!--{$arrProduct.price02_max|sfCalcIncTax:$arrSiteInfo.tax:$arrSiteInfo.tax_rule|number_format}-->
- <!--{/if}-->
- </span><span id="price02_dynamic_<!--{$id}-->"></span>
- 円</span>
- </div>
+ <!--{/if}-->
+ </span><span id="price02_dynamic_<!--{$id}-->"></span>
+ 円</span>
+ </div>
- <!--★コメント★-->
- <div class="listcomment"><!--{$arrProduct.main_list_comment|h|nl2br}--></div>
+ <!--★コメント★-->
+ <div class="listcomment"><!--{$arrProduct.main_list_comment|h|nl2br}--></div>
- <!--★商品詳細を見る★-->
- <div class="detail_btn">
- <!--{assign var=name value="detail`$id`"}-->
- <a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrProduct.product_id|u}-->" onmouseover="chgImg('<!--{$TPL_URLPATH}-->img/button/btn_detail_on.jpg','<!--{$name}-->');" onmouseout="chgImg('<!--{$TPL_URLPATH}-->img/button/btn_detail.jpg','<!--{$name}-->');">
- <img src="<!--{$TPL_URLPATH}-->img/button/btn_detail.jpg" alt="商品詳細を見る" name="<!--{$name}-->" id="<!--{$name}-->" /></a>
- </div>
+ <!--★商品詳細を見る★-->
+ <div class="detail_btn">
+ <!--{assign var=name value="detail`$id`"}-->
+ <a href="<!--{$smarty.const.P_DETAIL_URLPATH}--><!--{$arrProduct.product_id|u}-->" onmouseover="chgImg('<!--{$TPL_URLPATH}-->img/button/btn_detail_on.jpg','<!--{$name}-->');" onmouseout="chgImg('<!--{$TPL_URLPATH}-->img/button/btn_detail.jpg','<!--{$name}-->');">
+ <img src="<!--{$TPL_URLPATH}-->img/button/btn_detail.jpg" alt="商品詳細を見る" name="<!--{$name}-->" id="<!--{$name}-->" /></a>
+ </div>
- <!--▼買い物かご-->
- <form name="product_form<!--{$id|h}-->" action="?" onsubmit="return false;">
- <input type="hidden" name="product_id" value="<!--{$id|h}-->" />
- <input type="hidden" name="product_class_id" id="product_class_id<!--{$id|h}-->" value="<!--{$tpl_product_class_id[$id]}-->" />
- <input type="hidden" name="product_type" id="product_type<!--{$id|h}-->" value="<!--{$tpl_product_type[$id]}-->" />
+ <!--▼買い物かご-->
+ <input type="hidden" name="product_id" value="<!--{$id|h}-->" />
+ <input type="hidden" name="product_class_id" id="product_class_id<!--{$id|h}-->" value="<!--{$tpl_product_class_id[$id]}-->" />
+ <input type="hidden" name="product_type" id="product_type<!--{$id|h}-->" value="<!--{$tpl_product_type[$id]}-->" />
- <div class="cart_area clearfix">
- <!--{if $tpl_stock_find[$id]}-->
- <!--{if $tpl_classcat_find1[$id]}-->
- <div class="classlist">
- <dl class="size01 clearfix">
+ <div class="cart_area clearfix">
+ <!--{if $tpl_stock_find[$id]}-->
+ <!--{if $tpl_classcat_find1[$id]}-->
+ <div class="classlist">
+ <dl class="size01 clearfix">
<!--▼規格1-->
<dt><!--{$tpl_class_name1[$id]|h}-->:</dt>
<dd>
- <select name="classcategory_id1" style="<!--{$arrErr.classcategory_id1|sfGetErrorColor}-->" onchange="fnSetClassCategories(this.form);">
+ <select name="classcategory_id1" style="<!--{$arrErr.classcategory_id1|sfGetErrorColor}-->">
<!--{html_options options=$arrClassCat1[$id] selected=$arrProduct.classcategory_id1}-->
</select>
<!--{if $arrErr.classcategory_id1 != ""}-->
@@ -296,24 +217,23 @@
</dd>
<!--▲規格1-->
</dl>
- <dl class="size02 clearfix">
- <!--{if $tpl_classcat_find2[$id]}-->
+ <!--{if $tpl_classcat_find2[$id]}-->
+ <dl class="size02 clearfix">
<!--▼規格2-->
<dt><!--{$tpl_class_name2[$id]|h}-->:</dt>
<dd>
- <select name="classcategory_id2" style="<!--{$arrErr.classcategory_id2|sfGetErrorColor}-->" onchange="fnCheckStock(this.form);">
+ <select name="classcategory_id2" style="<!--{$arrErr.classcategory_id2|sfGetErrorColor}-->">
</select>
<!--{if $arrErr.classcategory_id2 != ""}-->
<p class="attention">※ <!--{$tpl_class_name2[$id]}-->を入力して下さい。</p>
<!--{/if}-->
</dd>
<!--▲規格2-->
- </dl>
- </div>
- <!--{/if}-->
- <!--{/if}-->
-
- <div class="cartin clearfix">
+ </dl>
+ <!--{/if}-->
+ </div>
+ <!--{/if}-->
+ <div class="cartin clearfix">
<div class="quantity">
数量:<input type="text" name="quantity" class="box" value="<!--{$arrProduct.quantity|default:1|h}-->" maxlength="<!--{$smarty.const.INT_LEN}-->" style="<!--{$arrErr.quantity|sfGetErrorColor}-->" />
<!--{if $arrErr.quantity != ""}-->
@@ -328,16 +248,14 @@
<div class="attention" id="cartbtn_dynamic_<!--{$id}-->"></div>
</div>
</div>
-
<!--{else}-->
- <div class="cartbtn attention">申し訳ございませんが、只今品切れ中です。</div>
+ <div class="cartbtn attention">申し訳ございませんが、只今品切れ中です。</div>
<!--{/if}-->
-
- </div>
- </form>
+ </div>
<!--▲買い物かご-->
- </div>
- </div>
+ </div>
+ </div>
+ </form>
<!--▲商品-->
<!--{if $smarty.foreach.arrProducts.last}-->
変更: branches/version-2_5-dev/data/Smarty/templates/sphone/products/detail.tpl
===================================================================
--- branches/version-2_5-dev/data/Smarty/templates/sphone/products/detail.tpl 2011-02-23 16:15:13 UTC (rev 20365)
+++ branches/version-2_5-dev/data/Smarty/templates/sphone/products/detail.tpl 2011-02-23 21:00:49 UTC (rev 20366)
@@ -19,137 +19,16 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*}-->
+<script type="text/javascript" src="<!--{$smarty.const.ROOT_URLPATH}-->js/products.js"></script>
<script type="text/javascript">//<![CDATA[
// 規格2に選択肢を割り当てる。
function fnSetClassCategories(form, classcat_id2_selected) {
- sele1 = form.classcategory_id1;
- sele2 = form.classcategory_id2;
-
- if (sele1) {
- if (sele2) {
- // 規格2の選択肢をクリア
- count = sele2.options.length;
- for(i = count; i >= 0; i--) {
- sele2.options[i] = null;
- }
-
- // 規格2に選択肢を割り当てる
- classcats = classCategories[sele1.value];
- i = 0;
- for (var classcat_id2_key in classcats) {
- classcategory_id2 = classcats[classcat_id2_key].classcategory_id2;
- sele2.options[i] = new Option(classcats[classcat_id2_key].name, classcategory_id2);
- if (classcategory_id2 == classcat_id2_selected) {
- sele2.options[i].selected = true;
- }
- i++;
- }
- }
- fnCheckStock(form);
- }
+ var $form = $(form);
+ var product_id = $form.find('input[name=product_id]').val();
+ var $sele1 = $form.find('select[name=classcategory_id1]');
+ var $sele2 = $form.find('select[name=classcategory_id2]');
+ setClassCategories($form, product_id, $sele1, $sele2, classcat_id2_selected);
}
-function fnCheckStock(form) {
- classcat_id1 = form.classcategory_id1.value;
- classcat_id2 = form.classcategory_id2 ? form.classcategory_id2.value : '';
- classcat2 = classCategories[classcat_id1]['#' + classcat_id2];
-
- // 商品コード
- eleDefault = document.getElementById('product_code_default');
- eleDynamic = document.getElementById('product_code_dynamic');
- if (
- classcat2
- && typeof classcat2.product_code != 'undefined'
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.product_code;
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- }
-
- // 在庫(品切れ)
- eleDefault = document.getElementById('cartbtn_default');
- eleDynamic = document.getElementById('cartbtn_dynamic');
- if (
- classcat2
- && classcat2.stock_find === false
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = '申し訳ございませんが、只今品切れ中です。';
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- }
-
- // 通常価格
- eleDefault = document.getElementById('price01_default');
- eleDynamic = document.getElementById('price01_dynamic');
- if (eleDefault && eleDynamic) {
- if (
- classcat2
- && typeof classcat2.price01 != 'undefined'
- && String(classcat2.price01).length >= 1
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.price01;
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- }
- }
-
- // 販売価格
- eleDefault = document.getElementById('price02_default');
- eleDynamic = document.getElementById('price02_dynamic');
- if (
- classcat2
- && typeof classcat2.price02 != 'undefined'
- && String(classcat2.price02).length >= 1
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.price02;
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- }
-
- // ポイント
- eleDefault = document.getElementById('point_default');
- eleDynamic = document.getElementById('point_dynamic');
- if (
- classcat2
- && typeof classcat2.point != 'undefined'
- && String(classcat2.point).length >= 1
- ) {
- eleDefault.style.display = 'none';
- eleDynamic.innerHTML = classcat2.point;
- } else {
- eleDefault.style.display = '';
- eleDynamic.innerHTML = '';
- }
- // 商品規格
- eleDynamic = document.getElementById('product_class_id');
- if (
- classcat2
- && typeof classcat2.product_class_id != 'undefined'
- && String(classcat2.product_class_id).length >= 1
- ) {
- eleDynamic.value = classcat2.product_class_id;
- } else {
- eleDynamic.value = ''
- }
- // 商品種別
- eleDynamic = document.getElementById('product_type');
- if (
- classcat2
- && typeof classcat2.product_type != 'undefined'
- && String(classcat2.product_type).length >= 1
- ) {
- eleDynamic.value = classcat2.product_type;
- } else {
- eleDynamic.value = ''
- }
-}
//]]>
</script>
追加: branches/version-2_5-dev/html/js/products.js
===================================================================
--- branches/version-2_5-dev/html/js/products.js (rev 0)
+++ branches/version-2_5-dev/html/js/products.js 2011-02-23 21:00:49 UTC (rev 20366)
@@ -0,0 +1,149 @@
+$(function() {
+ // 規格1選択時
+ $('select[name=classcategory_id1]')
+ .change(function() {
+ var $form = $(this).parents('form');
+ var product_id = $form.find('input[name=product_id]').val();
+ var $sele1 = $(this);
+ var $sele2 = $form.find('select[name=classcategory_id2]');
+ setClassCategories($form, product_id, $sele1, $sele2);
+ });
+
+ // 規格2選択時
+ $('select[name=classcategory_id2]')
+ .change(function() {
+ var $form = $(this).parents('form');
+ var product_id = $form.find('input[name=product_id]').val();
+ var $sele1 = $form.find('select[name=classcategory_id1]');
+ var $sele2 = $(this);
+ checkStock($form, product_id, $sele1.val(), $sele2.val());
+ });
+});
+/**
+ * 規格2のプルダウンを設定する.
+ */
+function setClassCategories($form, product_id, $sele1, $sele2, selected_id2) {
+ if ($sele1) {
+ var classcat_id1 = $sele1.val() ? $sele1.val() : '';
+ if ($sele2) {
+ // 規格2の選択肢をクリア
+ $sele2.children().remove();
+
+ var classcat2;
+
+ // 商品一覧時
+ if (typeof productsClassCategories != 'undefined') {
+ classcat2 = productsClassCategories[product_id][classcat_id1];
+ }
+ // 詳細表示時
+ else {
+ classcat2 = classCategories[classcat_id1];
+ }
+
+ // 規格2の要素を設定
+ for (var key in classcat2) {
+ var id = classcat2[key]['classcategory_id2'];
+ var name = classcat2[key]['name'];
+ var option = $('<option />').val(id ? id : '').text(name);
+ if (id == selected_id2) {
+ option.attr('selected', true);
+ }
+ $sele2.append(option);
+ }
+ }
+ if ($sele1.val()) {
+ checkStock($form, product_id, $sele1.val(), $sele2.val());
+ }
+ }
+}
+
+/**
+ * 規格の選択状態に応じて, フィールドを設定する.
+ */
+function checkStock($form, product_id, classcat_id1, classcat_id2) {
+
+ classcat_id2 = classcat_id2 ? classcat_id2 : '';
+
+ var classcat2;
+
+ // 商品一覧時
+ if (typeof productsClassCategories != 'undefined') {
+ classcat2 = productsClassCategories[product_id][classcat_id1]['#' + classcat_id2];
+ }
+ // 詳細表示時
+ else {
+ classcat2 = classCategories[classcat_id1]['#' + classcat_id2];
+ }
+
+ // 商品コード
+ var $product_code_default = $form.find('[id^=product_code_default]');
+ var $product_code_dynamic = $form.find('[id^=product_code_dynamic]');
+ if (classcat2
+ && typeof classcat2['product_code'] != 'undefined') {
+ $product_code_default.hide();
+ $product_code_dynamic.text(classcat2['product_code']);
+ }
+
+ // 在庫(品切れ)
+ var $cartbtn_default = $form.find('[id^=cartbtn_default]');
+ var $cartbtn_dynamic = $form.find('[id^=cartbtn_dynamic]');
+ if (classcat_id2 && classcat2['stock_find'] === false) {
+
+ $cartbtn_dynamic.text('申し訳ございませんが、只今品切れ中です。').show();
+ $cartbtn_default.hide();
+ } else {
+ $cartbtn_dynamic.hide();
+ $cartbtn_default.show();
+ }
+
+ // 通常価格
+ var $price01_default = $form.find('[id^=price01_default]');
+ var $price01_dynamic = $form.find('[id^=price01_dynamic]');
+ if (classcat2
+ && typeof classcat2['price01'] != 'undefined'
+ && String(classcat2['price01']).length >= 1) {
+
+ $price01_dynamic.text(classcat2['price01']).show();
+ $price01_default.hide();
+ } else {
+ $price01_dynamic.hide();
+ $price01_default.show();
+ }
+
+ // 販売価格
+ var $price02_default = $form.find('[id^=price02_default]');
+ var $price02_dynamic = $form.find('[id^=price02_dynamic]');
+ if (classcat2
+ && typeof classcat2['price02'] != 'undefined'
+ && String(classcat2['price02']).length >= 1) {
+
+ $price02_dynamic.text(classcat2['price02']).show();
+ $price02_default.hide();
+ } else {
+ $price02_dynamic.hide();
+ $price02_default.show();
+ }
+
+ // ポイント
+ var $point_default = $form.find('[id^=point_default]');
+ var $point_dynamic = $form.find('[id^=point_dynamic]');
+ if (classcat2
+ && typeof classcat2['point'] != 'undefined'
+ && String(classcat2['point']).length >= 1) {
+
+ $point_dynamic.text(classcat2['point']).show();
+ $point_default.hide();
+ } else {
+ $point_dynamic.hide();
+ $point_default.show();
+ }
+
+ // 商品規格
+ var $product_class_id_dynamic = $form.find('[id^=product_class_id]');
+ if (classcat2
+ && typeof classcat2['product_type'] != 'undefined'
+ && String(classcat2['product_type']).length >= 1) {
+
+ $product_class_id_dynamic.val(classcat2['product_class_id']);
+ }
+}
Svn-src-all メーリングリストの案内