$(
function()
{
var miniCartServiceUrl = "minicartservice.asp?callback=?";

refreshMiniCart();

function refreshMiniCart()
{
$.login(
{
automatic: false,
complete:
function(result)
{
$.getJSON(
miniCartServiceUrl,
{
method: "GetCart"
},
function(result)
{
if (result.Cart != null && result.GetCart != null)
{
$("#ProductNum").text(result.Cart.Num);
$("#MyCart").html(result.GetCart.process(result));
//alert(result.GetCart.process(result));
}
});
}
});
}

$("#MyCart .MyCart_List a[id][name]").livequery(
"click",
function()
{
var cartId = parseInt($(this).attr("id"));
var cartType = $(this).attr("name");
if (cartId > 0 && cartType != "")
{
$.getJSON(
miniCartServiceUrl,
{
method: cartType,
cartId: cartId
},
function(result)
{
if (result.Result)
{
refreshMiniCart();
}
});
}
});

$("#Product_Intro_Right img[id^=buy], #View_List img[id^=buy], #View_List :image[id^=buy], #p_Button img[id^=buy], :button[name^=buy], .productCompare img[id^=buy], #Fittings img[id^=pt]").livequery(
"click",
function()
{
var productId = parseInt($(this).attr("id").replace("buy", "").replace("pt", ""));
if (isNaN(productId) || productId == 0)
{
var productId = parseInt($(this).attr("name").replace("buy", "").replace("pt", ""));
}
var count = parseInt($("#Product_Intro_Right .Pro_links :text").val(), 10);
count = count > 0 ? count : 1;
if (productId > 0 && count > 0)
{
window.open("InitCart.aspx?pid={0}&pcount={1}&ptype=1".format(productId, count), "_blank");
}
});

$("#saveCart").livequery(
"click",
function()
{
$.login(
{
complete:
function(result)
{
if (result.IsAuthenticated)
{
$.getJSON(
miniCartServiceUrl,
{
method: "SaveCart"
},
function(result)
{
if (result.Result)
{
alert("寄存购物车成功");
}
});
}
}
});
});
});
在id为ProductNum的div上返回的是数量,MyCart返回的是购物车的详情,格式如下<div class="MyCart_List">
{if Cart.ThePacks.length == 0 && Cart.TheGifts.length == 0 && Cart.TheSkus.length == 0}
<div class="MyCart_Tip">您的购物车中暂无商品,赶快选择心爱的商品吧!</div>
{else}
<ul>{for Suit in Cart.ThePacks}
{var Price = 0}
{for Sku in Suit.Skus}
{if Sku.PromotionPrice > Price}
{var ImageUrl = Sku.ImgUrl; var SkuId = Sku.Id; Price = Sku.PromotionPrice;}
{/if}{/for}
<li class="tz">
<dl>
<dt>
<a href="product/${SkuId}.html" target="_blank"><img src="s3/${ImageUrl}" alt="${Suit.Name}" onerror="this.src='images/none/none_50.gif'" /></a>
</dt>
<dd class="p_Name">
<span>[套装]</span>
<a href="product/${SkuId}.html">${Suit.Name}</a>
</dd>
<dd class="p_Price">
<strong>¥${Suit.PromotionPrice.toFixed(2)}×${Suit.Num}</strong><br />
<a id="${Suit.Id}" name="RemoveSuit" href="#none">删除</a></dd></dl></li>{/for}{for Suit in Cart.TheGifts}
<li>
<dl>
<dt><a href="product/${Suit.MainSKU.Id}.html" target="_blank">
<img src="s3/${Suit.MainSKU.ImgUrl}" alt="${Suit.MainSKU.Name}" onerror="this.src='images/none/none_50.gif'" /></a></dt><dd class="p_Name"><a href="product/${Suit.MainSKU.Id}.html">${Suit.MainSKU.Name}</a></dd><dd class="p_Price"><strong>¥${Suit.PromotionPrice.toFixed(2)}×${Suit.Num}</strong><br /><a id="${Suit.Id}" name="RemoveGift" href="#none">删除</a>
</dd>
</dl>
{for Sku in Suit.Skus}
<dl>
<dt>
<a href="#"></a>
</dt>
<dd class="p_Name">
<span>[赠]</span>
<a href="product/${Sku.Id}.html">${Sku.Name}</a></dd>
<dd class="p_Price"></dd>
</dl>
{/for}
</li>{/for}{for Sku in Cart.TheSkus}
<li>
<dl>
<dt>
<a href="product/${Sku.Id}.html" target="_blank">
<img src="s3/${Sku.ImgUrl}" alt="${Sku.Name}" onerror="this.src='images/none/none_50.gif'" /></a>
</dt>
<dd class="p_Name"><a href="product/${Sku.Id}.html">${Sku.Name}</a></dd>
<dd class="p_Price">
<strong>¥${Sku.PromotionPrice.toFixed(2)}×${Sku.Num}</strong><br />
<a id="${Sku.Id}" name="RemoveProduct" href="#none">删除</a>
</dd>
</dl>
</li>
{/for}</ul><div class="Account">共<strong>${Cart.Num}</strong>件商品&nbsp;&nbsp;&nbsp;金额总计:<strong>¥${Cart.TotalPromotionPrice.toFixed(2)}</strong></div>
<div class="CartLog">
<a href="#none"><img id="saveCart" alt="cart" src="/images/save.jpg" class="float_Left" title="点击“寄存购物车”后可以保存购物车内的商品。你下一次登录时,寄存的购物车将自动装载。" /></a>
<a href="http://jd2008.360buy.com/purchase/ShoppingCart.aspx">
<img src="/images/settlement.gif" class="float_Right" /></a>
</div>
{/if}
</div>minicartservice.asp能写吗