//カートに商品を登録
function addCart(itemCode, priceDiv, priceRank, quantity, ccode){
switch(arguments.length){
case 1:
addCartCampaign(arguments[0]);
break;
case 3:
addCartOne(itemCode, priceDiv, priceRank);
break;
case 4:
addCartNormal(itemCode, priceDiv, priceRank, quantity);
break;
case 5:
addCartWithCampaign(itemCode, priceDiv, priceRank, quantity, ccode);
break;
default:
break;
}
}
function addCartNormal(itemCode, priceDiv, priceRank, quantity){
var src_val='/cart/cart.html?itemCode=' + itemCode + '&priceDiv=' + priceDiv + '&priceRank=' + priceRank + '&quantity=' + quantity;
location.href = src_val;
}
function addCartWithCampaign(itemCode, priceDiv, priceRank, quantity, ccode){
var src_val='/cart/cart.html?itemCode=' + itemCode + '&priceDiv=' + priceDiv + '&priceRank=' + priceRank + '&quantity=' + quantity + '&ccode=' + ccode;
location.href = src_val;
}
function addCartOne(itemCode, priceDiv, priceRank){
var src_val='/cart/cart.html?itemCode=' + itemCode + '&priceDiv=' + priceDiv + '&priceRank=' + priceRank + '&quantity=1';
location.href = src_val;
}
function addCartCampaign(ccode){
var src_val='/cart/cart.html?ccode=' + ccode;
location.href = src_val;
}
var cartProgress = false;
var cartHeaderInnerHtmlDone = function(res){
if(res.Status === 0){
var html = '';
if(res.CartDetail.length == 0){
html += '
5,000円以上で送料無料
';
html += '';
}
else {
if(res.Carriage == 0){
html += '送料無料!
';
}
else {
html += '5,000円以上で送料無料
';
}
html += '- 計 ';
html += res.Quantity;
html += ' 点
- 合計 ';
html += res.Total.toLocaleString();
html += ' 円
';
}
html += '';
$('#header .wrap .nav_right .cart_area').html(html);
$.toast({
text:'カートに商品が追加されました。'
,showHideTransition:'slide'
,allowToastClose:true
,hideAfter:3000
,loader:false
,stack:false
,position:'bottom-left'
,bgColor:"#000"
,textColor:'#fff'
,textAlign:'center'
,afterHidden: function(){cartProgress = false;$("#cart_loading").fadeOut();}
});
}
else if(res.Status === 1){
var text = "";
res.MessageList.forEach(function(msg){
text += msg + '
';
})
$.toast({
text: '' + text + ''
,showHideTransition:'slide'
,allowToastClose:true
,hideAfter:3000
,loader:false
,stack:false
,position:'bottom-left'
,bgColor:"#000"
,textColor:'#fff'
,textAlign:'center'
,afterHidden: function(){cartProgress = false;$("#cart_loading").fadeOut();}
});
}
}
var cartHeaderInnerHtmlFail = function(){
$.toast({
text:'カートへの商品追加に失敗しました。'
,showHideTransition:'slide'
,allowToastClose:true
,hideAfter:3000
,loader:false
,stack:false
,position:'bottom-left'
,bgColor:"#000"
,textColor:'#fff'
,textAlign:'center'
,afterHidden: function(){cartProgress = false;$("#cart_loading").fadeOut();}
});
}
function addCartAs(token, itemCode, priceDiv, priceRank, quantity, ccode){
if(cartProgress) return;
cartProgress = true;
// カート画面の場合は同期処理
if($('input[name=cartPage]').val() == '1'){
addCart(itemCode, priceDiv, priceRank, quantity);
return;
}
var cartReq = {};
switch(arguments.length){
case 2:
cartReq = {
ccode:arguments[1]
,cartToken:arguments[0]};
break;
case 4:
cartReq = {
itemCode:itemCode
,priceDiv:priceDiv
,priceRank:priceRank
,cartToken:token
};
break;
case 5:
cartReq = {
itemCode:itemCode
,priceDiv:priceDiv
,priceRank:priceRank
,quantity:quantity
,cartToken:token
};
break;
case 6:
cartReq = {
itemCode:itemCode
,priceDiv:priceDiv
,priceRank:priceRank
,quantity:quantity
,ccode:ccode
,cartToken:token
};
break;
default:
break;
}
$.ajax({
url: '/service_template/cart/cart.html',
type: 'POST',
dataType: 'json',
data: cartReq,
})
.done(function(res) {
cartHeaderInnerHtmlDone(res);
})
.fail(function() {
cartHeaderInnerHtmlFail();
});
}
// 商品数量変更
function chgQuantity(itemCode, priceDiv, priceRank, quantity, id) {
location.href="/cart/cart.html?itemCode=" + itemCode + "&priceDiv=" + priceDiv + "&priceRank=" + priceRank + "&quantity=" + quantity + "&c_d_id=" + id;
}
// 定期契約へ変更
function chgRegular(itemCode, priceRank, interval, id) {
location.href="/cart/cart.html?itemCode=" + itemCode + "&priceDiv=2" + "&priceRank=" + priceRank + "&interval=" + interval + "&c_d_id=" + id;
}
// 配送間隔変更
function updRegular(itemCode, priceDiv, priceRank, quantity, interval, id){
location.href="/cart/cart.html?itemCode=" + itemCode + "&priceDiv=" + priceDiv + "&priceRank=" + priceRank + "&quantity=" + quantity + "&interval=" + interval + "&c_d_id=" + id;
}
// カート明細変更
function chgDetail(itemCode, priceDiv, priceRank, quantity, interval, id){
location.href="/cart/cart.html?itemCode=" + itemCode + "&priceDiv=" + priceDiv + "&priceRank=" + priceRank + "&quantity=" + quantity + "&interval=" + interval + "&c_d_id=" + id;
}
/***
* 郵便番号検索
***/
var SearchZip = function(){
var regex1 = /^[0-9]{3}$/;
var regex2 = /^[0-9]{4}$/;
var processing = false;
this.run = function(zipCode1, zipCode2, token, cb){
if(processing){
return;
}
processing = true;
if(zipCode1.match(regex1) == null || zipCode2.match(regex2) == null){
alert('郵便番号の指定に誤りがあります。');
processing = false;
}
else {
$.ajax({
url:'/service_template/cart/search_zip.html',
type:'POST',
dataType:'json',
data:{
'zipCode1':zipCode1,
'zipCode2':zipCode2,
'zipToken':token
},
}).done(function(res) {
cb(res);
processing = false;
}).fail(function() {
alert('エラーが発生しました。');
processing = false;
});
}
};
}
// お気に入り追加
function addFav(itemCode){
location.href='/mypage/favorite.html?itemCode=' + itemCode;
}
// 商品詳細
var SyncProductForm = function(){
// フォーム連動
var $radioObj = $('input[type=radio]');
$('input[type=radio]').change(function(){
var thisVal = $(this).prop('checked');
var thisItemInfo = (new Function("return " + $(this).data('item')))();
$radioObj.each(function(){
var eachItemInfo = (new Function("return " + $(this).data('item')))();
if(thisItemInfo.name == eachItemInfo.name){
if(thisItemInfo.code == eachItemInfo.code
&& thisItemInfo.div == eachItemInfo.div
&& thisItemInfo.rank == eachItemInfo.rank
&& thisItemInfo.quan == eachItemInfo.quan){
$(this).prop('checked', thisVal);
}
else{
$(this).prop('checked', !thisVal);
}
}
});
});
var $checkObj = $('input[type=checkbox]');
$('input[type=checkbox]').change(function(){
var thisVal = $(this).prop('checked');
var thisItemInfo = (new Function("return " + $(this).data('item')))();
$checkObj.each(function(){
var eachItemInfo = (new Function("return " + $(this).data('item')))();
if(thisItemInfo.code == eachItemInfo.code
&& thisItemInfo.div == eachItemInfo.div
&& thisItemInfo.rank == eachItemInfo.rank
&& thisItemInfo.quan == eachItemInfo.quan){
$(this).prop('checked', thisVal);
}
});
});
var $numberObj = $('input[type=number]');
$('input[type=number]').change(function(){
var thisVal = $(this).val();
var thisItemInfo = (new Function("return " + $(this).data('item')))();
$numberObj.each(function(){
var eachItemInfo = (new Function("return " + $(this).data('item')))();
if(thisItemInfo.code == eachItemInfo.code
&& thisItemInfo.div == eachItemInfo.div
&& thisItemInfo.rank == eachItemInfo.rank){
$(this).val(thisVal);
}
});
});
var $selectObj = $('select');
$('select').change(function(){
var thisVal = $(this).val();
var thisItemInfo = (new Function("return " + $(this).data('item')))();
$selectObj.each(function(){
var eachItemInfo = (new Function("return " + $(this).data('item')))();
if(thisItemInfo.code == eachItemInfo.code
&& thisItemInfo.div == eachItemInfo.div
&& thisItemInfo.rank == eachItemInfo.rank){
$(this).val(thisVal);
}
});
});
var btnCartProcessing = false; // 購入ボタン連打対策
// 次のページに遷移しようとした瞬間にフラグを戻す
// memo: safariではpageshowは1度しか動作しない場合があるので、別の手段も設ける https://bugs.webkit.org/show_bug.cgi?id=156356
// 同じくsafariでは、unloadは動作しなかった。
var initBtnCartProcessingFlag = function() { btnCartProcessing = false; };
$(window).on('unload pageshow pagehide', initBtnCartProcessingFlag);
// 購入ボタン
$('.btn_cart').click(function(e){
e.preventDefault();
if (btnCartProcessing) return;
var itemArr = [];
var str = '';
if($(this).data("type") == 'single'){
// 商品パラメタを持ってくる
var target = $(this).data("target").split(',')
var $targetObj = $(this);
for(var i=0; i 1){
for(var i=0; i= 1){
str += '&';
}
else {
str += '?';
}
str += 'itemCode'+ i +'=' + itemArr[i].code + '&priceDiv'+ i +'=' + itemArr[i].div + '&priceRank'+ i +'=' + itemArr[i].rank + '&quantity'+ i +'=' + itemArr[i].quan;
}
str += typeof itemArr[0].ccode === "undefined" ? "" : "&ccode=" + itemArr[0].ccode;
btnCartProcessing = true;
location.href = '/cart/cart.html' + str;
}
}
});
};
// 商品詳細(カート非同期対応版)
var SyncProductFormCartAsync = function(){
// フォーム連動
var $radioObj = $('input[type=radio]');
$('input[type=radio]').change(function(){
var thisVal = $(this).prop('checked');
var thisItemInfo = (new Function("return " + $(this).data('item')))();
$radioObj.each(function(){
var eachItemInfo = (new Function("return " + $(this).data('item')))();
if(thisItemInfo.name == eachItemInfo.name){
if(thisItemInfo.code == eachItemInfo.code
&& thisItemInfo.div == eachItemInfo.div
&& thisItemInfo.rank == eachItemInfo.rank
&& thisItemInfo.quan == eachItemInfo.quan){
$(this).prop('checked', thisVal);
}
else{
$(this).prop('checked', !thisVal);
}
}
});
});
var $checkObj = $('input[type=checkbox]');
$('input[type=checkbox]').change(function(){
var thisVal = $(this).prop('checked');
var thisItemInfo = (new Function("return " + $(this).data('item')))();
$checkObj.each(function(){
var eachItemInfo = (new Function("return " + $(this).data('item')))();
if(thisItemInfo.code == eachItemInfo.code
&& thisItemInfo.div == eachItemInfo.div
&& thisItemInfo.rank == eachItemInfo.rank
&& thisItemInfo.quan == eachItemInfo.quan){
$(this).prop('checked', thisVal);
}
});
});
var $numberObj = $('input[type=number]');
$('input[type=number]').change(function(){
var thisVal = $(this).val();
var thisItemInfo = (new Function("return " + $(this).data('item')))();
$numberObj.each(function(){
var eachItemInfo = (new Function("return " + $(this).data('item')))();
if(thisItemInfo.code == eachItemInfo.code
&& thisItemInfo.div == eachItemInfo.div
&& thisItemInfo.rank == eachItemInfo.rank){
$(this).val(thisVal);
}
});
});
var $selectObj = $('select');
$('select').change(function(){
var thisVal = $(this).val();
var thisItemInfo = (new Function("return " + $(this).data('item')))();
$selectObj.each(function(){
var eachItemInfo = (new Function("return " + $(this).data('item')))();
if(thisItemInfo.code == eachItemInfo.code
&& thisItemInfo.div == eachItemInfo.div
&& thisItemInfo.rank == eachItemInfo.rank){
$(this).val(thisVal);
}
});
});
// 購入ボタン
$('.btn_cart').click(function(e){
e.preventDefault();
var itemArr = [];
var str = '';
var token = $('input[name=cartToken]').val();
if($(this).data("type") == 'single'){
// 商品パラメタを持ってくる
var target = $(this).data("target").split(',')
var $targetObj = $(this);
for(var i=0; i 1){
var cartReq = {};
if(itemArr[0].ccode != "")
{
cartReq['ccode'] = itemArr[0].ccode;
}
itemArr.forEach(function(item, index){
cartReq['itemCode_'+index] = item.code;
cartReq['priceDiv_'+index] = item.div;
cartReq['priceRank_'+index] = item.rank;
cartReq['quantity_'+index] = item.quan;
});
cartReq.cartToken = token;
if(cartProgress)
return;
cartProgress = true;
$.ajax({
url: '/service_template/cart/cart.html',
type: 'POST',
dataType: 'json',
data: cartReq,
})
.done(function(res) {
cartHeaderInnerHtmlDone(res);
})
.fail(function() {
cartHeaderInnerHtmlFail();
});
}
}
});
};
// キャンペーン番号ボタン
$(document).ready(function(){
$('input[name=ccode_next]').click(function(e){
e.preventDefault();
var ccode = $('input[name=ccode]').val();
var cpnToken = $('input[name=campaign_token]').val();
var regex1 = /[^0-9a-zA-Z-]+/;
if(ccode.length === 0){
alert("キャンペーン番号を入力してください。");
}
else if(ccode.match(regex1) !== null){
alert("キャンペーン番号が不正です。");
}
else{
$.ajax({
url: '/service_template/campaign/campaign.html',
type: 'POST',
dataType: 'json',
data:{
'ccode': ccode,
'campaignToken': cpnToken
},
}).done(function(res) {
if(res.Status === 0){
if(res.lpUrl !== null){
location.href = res.lpUrl;
}
else {
var cartPara = '';
cartPara += '?ccode=' + ccode;
for(var i=0; i