仿淘寶商品詳細頁加入購物車效果
goods.dwt頁面 <a href="網頁特效:addToCart({$goods.goods_id},0,1)"><img src="images/bnt_cat.gif" /></a>和默認的鏈接有點點區別 大家對比添加
要顯示的層添加到這個葉面的底部 <div class="cartSure" id="cartSureBox" style="display:none;">
<div class="btn"><a href="javascript:;">關閉</a></div>
<div class="mesgCon">
<h3>寶貝已成功添加到購物車!</h3>
<div>購物車共有<span id="ECS_GOODS_NUMBER"></span>種商品 合計:<span id="ECS_GOODS_PRICE"></span></div><br>
<input type="image" src="images/btn_pay.gif" /></div>
</div>
復制代碼
我把樣式也貼出來 供大家參考 .cartSure{
position:absolute;
left:0;
top:545px;
width:405px;
height:90px;
z-index:999;
background:url(images/cartSure_bg.gif) 0 0 no-repeat;
font-size:12px;
}.mesgCon{
float:left;
background:url(images/mesg.png) no-repeat 18px 9px;
color:#666;
line-height:21px;
padding:0 0 0 100px;
width:320px;
}.mesgCon h3{
float:left;
width:320px;
color:#333;
font-size:14px;
margin:-1px 0 6px;
height:auto;
line-height:20px;
background:none;
text-align:left;
padding:0;
font-weight:bold;
}.mesgCon input{float:left; margin:0 11px 0 0}
.mesgCon div{float:left; font-size:13px}
.mesgCon div span{font-size:14px; font-weight:bold; color:#F80}
.cartSure .btn{float:left; padding:5px; width:390px}
.cartSure .btn a{
background:url(images/close_bg.gif) no-repeat 0 0;
float:right;
height:13px;
overflow:hidden;
text-indent:-5000px;
width:38px;
}.cartSure .btn a:hover{background-position:0 -12px}
復制代碼
打開js/common.js文件 修改 addToCart函數 修改後:
function addToCart(goodsId, parentId,is_ajax)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
// 檢查是否有商品規格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}quick = 1;
}goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);if(is_ajax == 1){
Ajax.call('flow.php教程?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e_ajax, 'POST', 'JSON');
}else{
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e, 'POST', 'JSON');
}
}
復制代碼
添加幾個js函數 /* *
* 處理添加商品到購物車的反饋信息
*/
function addToCartResp**e_ajax(result)
{
if (result.error > 0)
{
// 如果需要缺貨登記,跳轉
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
}
//opendiv_booking();}
// 沒選規格,彈出屬性選擇框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{
switch(result.confirm_type)
{
case '1' :
if (confirm(result.message)) location.href = cart_url;
break;
case '2' :
if (!confirm(result.message)) location.href = cart_url;
break;
case '3' :
divTipmiddle(result);
//refresh_cart();
document.getElementById('jdiv').innerHTML = result.cj;
break;
default :
break;
}
}
}
}
//購物車提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
function divTipmiddle(result){
openTipBox(result);
var a = document.getElementById("cartSureBox");
a.style.left=(document.body.clientWidth/2-a.clientWidth/2+245)+"px";
}
function openTipBox(result){
document.getElementById('ECS_GOODS_PRICE').innerHTML = result.goods_price;
document.getElementById('ECS_GOODS_NUMBER').innerHTML = result.goods_number;
document.getElementById('cartSureBox').style.display="block";
}
function opendiv_booking()
{
document.getElementById('buyTip2').style.display="block";}
//購物車提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
復制代碼
打開flow.php 167行左右添加 /* 取得商品列表,計算合計 */
$cart_goods = get_cart_goods();
//$smarty->assign('total', $cart_goods['total']);
$result['goods_price'] = $cart_goods['total']['goods_price'];
$result['goods_number'] = $cart_goods['total']['real_goods_count'];
復制代碼
根據以上操作可實現 效果大家應該都知道 如圖:實現方法:
goods.dwt頁面 <a href="javascript:addToCart({$goods.goods_id},0,1)"><img src="images/bnt_cat.gif" /></a>和默認的鏈接有點點區別 大家對比添加
要顯示的層添加到這個葉面的底部 <div class="cartSure" id="cartSureBox" style="display:none;">
<div class="btn"><a href="javascript:;">關閉</a></div>
<div class="mesgCon">
<h3>寶貝已成功添加到購物車!</h3>
<div>購物車共有<span id="ECS_GOODS_NUMBER"></span>種商品 合計:<span id="ECS_GOODS_PRICE"></span></div><br>
<input type="image" src="images/btn_pay.gif" /></div>
</div>
復制代碼
我把樣式也貼出來 供大家參考 .cartSure{
position:absolute;
left:0;
top:545px;
width:405px;
height:90px;
z-index:999;
background:url(images/cartSure_bg.gif) 0 0 no-repeat;
font-size:12px;
}.mesgCon{
float:left;
background:url(images/mesg.png) no-repeat 18px 9px;
color:#666;
line-height:21px;
padding:0 0 0 100px;
width:320px;
}.mesgCon h3{
float:left;
width:320px;
color:#333;
font-size:14px;
margin:-1px 0 6px;
height:auto;
line-height:20px;
background:none;
text-align:left;
padding:0;
font-weight:bold;
}.mesgCon input{float:left; margin:0 11px 0 0}
.mesgCon div{float:left; font-size:13px}
.mesgCon div span{font-size:14px; font-weight:bold; color:#F80}
.cartSure .btn{float:left; padding:5px; width:390px}
.cartSure .btn a{
background:url(images/close_bg.gif) no-repeat 0 0;
float:right;
height:13px;
overflow:hidden;
text-indent:-5000px;
width:38px;
}.cartSure .btn a:hover{background-position:0 -12px}
復制代碼
打開js/common.js文件 修改 addToCart函數 修改後:
function addToCart(goodsId, parentId,is_ajax)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
// 檢查是否有商品規格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}quick = 1;
}goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);if(is_ajax == 1){
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e_ajax, 'POST', 'JSON');
}else{
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e, 'POST', 'JSON');
}
}
復制代碼
添加幾個js函數 /* *
* 處理添加商品到購物車的反饋信息
*/
function addToCartResp**e_ajax(result)
{
if (result.error > 0)
{
// 如果需要缺貨登記,跳轉
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
}
//opendiv_booking();}
// 沒選規格,彈出屬性選擇框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{
switch(result.confirm_type)
{
case '1' :
if (confirm(result.message)) location.href = cart_url;
break;
case '2' :
if (!confirm(result.message)) location.href = cart_url;
break;
case '3' :
divTipmiddle(result);
//refresh_cart();
document.getElementById('jdiv').innerHTML = result.cj;
break;
default :
break;
}
}
}
}
//購物車提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
function divTipmiddle(result){
openTipBox(result);
var a = document.getElementById("cartSureBox");
a.style.left=(document.body.clientWidth/2-a.clientWidth/2+245)+"px";
}
function openTipBox(result){
document.getElementById('ECS_GOODS_PRICE').innerHTML = result.goods_price;
document.getElementById('ECS_GOODS_NUMBER').innerHTML = result.goods_number;
document.getElementById('cartSureBox').style.display="block";
}
function opendiv_booking()
{
document.getElementById('buyTip2').style.display="block";}
//購物車提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
復制代碼
打開flow.php 167行左右添加 /* 取得商品列表,計算合計 */
$cart_goods = get_cart_goods();
//$smarty->assign('total', $cart_goods['total']);
$result['goods_price'] = $cart_goods['total']['goods_price'];
$result['goods_number'] = $cart_goods['total']['real_goods_count'];
復制代碼
根據以上操作可實現
實現方法:
goods.dwt頁面 <a href="javascript:addToCart({$goods.goods_id},0,1)"><img src="images/bnt_cat.gif" /></a>和默認的鏈接有點點區別 大家對比添加
要顯示的層添加到這個葉面的底部 <div class="cartSure" id="cartSureBox" style="display:none;">
<div class="btn"><a href="javascript:;">關閉</a></div>
<div class="mesgCon">
<h3>寶貝已成功添加到購物車!</h3>
<div>購物車共有<span id="ECS_GOODS_NUMBER"></span>種商品 合計:<span id="ECS_GOODS_PRICE"></span></div><br>
<input type="image" src="images/btn_pay.gif" /></div>
</div>
復制代碼
我把樣式也貼出來 供大家參考 .cartSure{
position:absolute;
left:0;
top:545px;
width:405px;
height:90px;
z-index:999;
background:url(images/cartSure_bg.gif) 0 0 no-repeat;
font-size:12px;
}.mesgCon{
float:left;
background:url(images/mesg.png) no-repeat 18px 9px;
color:#666;
line-height:21px;
padding:0 0 0 100px;
width:320px;
}.mesgCon h3{
float:left;
width:320px;
color:#333;
font-size:14px;
margin:-1px 0 6px;
height:auto;
line-height:20px;
background:none;
text-align:left;
padding:0;
font-weight:bold;
}.mesgCon input{float:left; margin:0 11px 0 0}
.mesgCon div{float:left; font-size:13px}
.mesgCon div span{font-size:14px; font-weight:bold; color:#F80}
.cartSure .btn{float:left; padding:5px; width:390px}
.cartSure .btn a{
background:url(images/close_bg.gif) no-repeat 0 0;
float:right;
height:13px;
overflow:hidden;
text-indent:-5000px;
width:38px;
}.cartSure .btn a:hover{background-position:0 -12px}
復制代碼
打開js/common.js文件 修改 addToCart函數 修改後:
function addToCart(goodsId, parentId,is_ajax)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
// 檢查是否有商品規格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}quick = 1;
}goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);if(is_ajax == 1){
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e_ajax, 'POST', 'JSON');
}else{
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e, 'POST', 'JSON');
}
}
復制代碼
添加幾個js函數 /* *
* 處理添加商品到購物車的反饋信息
*/
function addToCartResp**e_ajax(result)
{
if (result.error > 0)
{
// 如果需要缺貨登記,跳轉
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
}
//opendiv_booking();}
// 沒選規格,彈出屬性選擇框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{
switch(result.confirm_type)
{
case '1' :
if (confirm(result.message)) location.href = cart_url;
break;
case '2' :
if (!confirm(result.message)) location.href = cart_url;
break;
case '3' :
divTipmiddle(result);
//refresh_cart();
document.getElementById('jdiv').innerHTML = result.cj;
break;
default :
break;
}
}
}
}
//購物車提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
function divTipmiddle(result){
openTipBox(result);
var a = document.getElementById("cartSureBox");
a.style.left=(document.body.clientWidth/2-a.clientWidth/2+245)+"px";
}
function openTipBox(result){
document.getElementById('ECS_GOODS_PRICE').innerHTML = result.goods_price;
document.getElementById('ECS_GOODS_NUMBER').innerHTML = result.goods_number;
document.getElementById('cartSureBox').style.display="block";
}
function opendiv_booking()
{
document.getElementById('buyTip2').style.display="block";}
//購物車提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
復制代碼
打開flow.php 167行左右添加 /* 取得商品列表,計算合計 */
$cart_goods = get_cart_goods();
//$smarty->assign('total', $cart_goods['total']);
$result['goods_price'] = $cart_goods['total']['goods_price'];
$result['goods_number'] = $cart_goods['total']['real_goods_count'];
復制代碼
根據以上操作可實現
實現方法:
goods.dwt頁面 <a href="javascript:addToCart({$goods.goods_id},0,1)"><img src="images/bnt_cat.gif" /></a>和默認的鏈接有點點區別 大家對比添加
要顯示的層添加到這個葉面的底部 <div class="cartSure" id="cartSureBox" style="display:none;">
<div class="btn"><a href="javascript:;">關閉</a></div>
<div class="mesgCon">
<h3>寶貝已成功添加到購物車!</h3>
<div>購物車共有<span id="ECS_GOODS_NUMBER"></span>種商品 合計:<span id="ECS_GOODS_PRICE"></span></div><br>
<input type="image" src="images/btn_pay.gif" /></div>
</div>
復制代碼
我把樣式也貼出來 供大家參考 .cartSure{
position:absolute;
left:0;
top:545px;
width:405px;
height:90px;
z-index:999;
background:url(images/cartSure_bg.gif) 0 0 no-repeat;
font-size:12px;
}.mesgCon{
float:left;
background:url(images/mesg.png) no-repeat 18px 9px;
color:#666;
line-height:21px;
padding:0 0 0 100px;
width:320px;
}.mesgCon h3{
float:left;
width:320px;
color:#333;
font-size:14px;
margin:-1px 0 6px;
height:auto;
line-height:20px;
background:none;
text-align:left;
padding:0;
font-weight:bold;
}.mesgCon input{float:left; margin:0 11px 0 0}
.mesgCon div{float:left; font-size:13px}
.mesgCon div span{font-size:14px; font-weight:bold; color:#F80}
.cartSure .btn{float:left; padding:5px; width:390px}
.cartSure .btn a{
background:url(images/close_bg.gif) no-repeat 0 0;
float:right;
height:13px;
overflow:hidden;
text-indent:-5000px;
width:38px;
}.cartSure .btn a:hover{background-position:0 -12px}
復制代碼
打開js/common.js文件 修改 addToCart函數 修改後:
function addToCart(goodsId, parentId,is_ajax)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
// 檢查是否有商品規格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}quick = 1;
}goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);if(is_ajax == 1){
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e_ajax, 'POST', 'JSON');
}else{
Ajax.call('flow.php?step=add_to_cart', 'goods=' + goods.toJS**tring(), addToCartResp**e, 'POST', 'JSON');
}
}
復制代碼
添加幾個js函數 /* *
* 處理添加商品到購物車的反饋信息
*/
function addToCartResp**e_ajax(result)
{
if (result.error > 0)
{
// 如果需要缺貨登記,跳轉
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = 'user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
}
//opendiv_booking();}
// 沒選規格,彈出屬性選擇框
else if (result.error == 6)
{
openSpeDiv(result.message, result.goods_id, result.parent);
}
else
{
alert(result.message);
}
}
else
{
var cartInfo = document.getElementById('ECS_CARTINFO');
var cart_url = 'flow.php?step=cart';
if (cartInfo)
{
cartInfo.innerHTML = result.content;
}if (result.one_step_buy == '1')
{
location.href = cart_url;
}
else
{
switch(result.confirm_type)
{
case '1' :
if (confirm(result.message)) location.href = cart_url;
break;
case '2' :
if (!confirm(result.message)) location.href = cart_url;
break;
case '3' :
divTipmiddle(result);
//refresh_cart();
document.getElementById('jdiv').innerHTML = result.cj;
break;
default :
break;
}
}
}
}
//購物車提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
function divTipmiddle(result){
openTipBox(result);
var a = document.getElementById("cartSureBox");
a.style.left=(document.body.clientWidth/2-a.clientWidth/2+245)+"px";
}
function openTipBox(result){
document.getElementById('ECS_GOODS_PRICE').innerHTML = result.goods_price;
document.getElementById('ECS_GOODS_NUMBER').innerHTML = result.goods_number;
document.getElementById('cartSureBox').style.display="block";
}
function opendiv_booking()
{
document.getElementById('buyTip2').style.display="block";}
//購物車提示框JS
function closeTipBox(){
document.getElementById('cartSureBox').style.display="none";
}
復制代碼
打開flow.php 167行左右添加 /* 取得商品列表,計算合計 */
$cart_goods = get_cart_goods();
//$smarty->assign('total', $cart_goods['total']);
$result['goods_price'] = $cart_goods['total']['goods_price'];
$result['goods_number'] = $cart_goods['total']['real_goods_count'];