Authored by jinhu.tung

buy removed product

... ... @@ -15,6 +15,7 @@ exports.index = (req, res, next) => {
const uid = req.user.uid || null;
cartModel.getCartData(shoppingKey, uid).then((result) => {
console.log(JSON.stringify(result, '', 4));
if (result.code === 200) {
res.display('cart', _.merge({
module: 'shopping',
... ... @@ -201,3 +202,22 @@ exports.modifyProduct = (req, res, next) => {
}
}).catch(next);
};
// 获取购物车商品信息
exports.getCartData = (req, res, next) => {
const shoppingKey = req.cookies._SPK || null;
const uid = req.user.uid || null;
cartModel.getCartData(shoppingKey, uid).then((result) => {
if (result.code === 200) {
res.json(
_.merge(
cartModel.filterCartData(result, uid),
{code: result.code, message: result.message}
)
);
} else {
res.send(result);
}
}).catch(next);
};
... ...
... ... @@ -23,6 +23,7 @@ router.post('/cart/add', cartCtrl.addToCart);
router.post('/cart/toggleSelectGoods', cartCtrl.toggleSelectGoods);
router.get('/cart/checkStorage', cartCtrl.checkStorage);
router.put('/cart/updateProduct', cartCtrl.modifyProduct);
router.get('/cart/data', cartCtrl.getCartData);
// 结算
router.get('/order', auth, order.index);
... ...
... ... @@ -151,7 +151,7 @@
<li class="total-price-action">
<span class="price item-total-price">¥ \{{round (multiple sales_price buy_number) 2}}</span>
<div class="actions">
<div class="remove-item action" data-product_id=\{{product_id}}><span class="iconfont">&#xe614;</span> &nbsp;删&nbsp;&nbsp;&nbsp;&nbsp;除</div>
<div class="remove-item action" data-product_extra_info='{"goodsId": "\{{goods_id}}", "cnAlphabet": "\{{cn_alphabet}}", "productId": "\{{product_id}}", "salesPrice": "\{{round sales_price 2}}", "productName": "\{{product_name}}", "goodType":"ordinary", "selected": "\{{selected}}"}'><span class="iconfont">&#xe614;</span> &nbsp;删&nbsp;&nbsp;&nbsp;&nbsp;除</div>
<div class="send-to-favorite action" data-product_id=\{{product_id}}>移入收藏夹</div>
</div>
</li>
... ... @@ -218,7 +218,7 @@
<li class="total-price-action">
<span class="price item-total-price">¥ \{{round (multiple sales_price buy_number) 2}}</span>
<div class="actions">
<div class="remove-item action" data-product_id=\{{product_id}}><span class="iconfont">&#xe614;</span> &nbsp;删&nbsp;&nbsp;&nbsp;&nbsp;除</div>
<div class="remove-item action" data-product_extra_info='{"goodsId": "\{{goods_id}}", "cnAlphabet": "\{{cn_alphabet}}", "productId": "\{{product_id}}", "salesPrice": "\{{round sales_price 2}}", "productName": "\{{product_name}}", "goodType":"ordinary", "selected": "\{{selected}}"}'><span class="iconfont">&#xe614;</span> &nbsp;删&nbsp;&nbsp;&nbsp;&nbsp;除</div>
<div class="send-to-favorite action" data-product_id=\{{product_id}}>移入收藏夹</div>
</div>
</li>
... ... @@ -339,7 +339,7 @@
<div class="product-price">¥ \{{salesPrice}}</div>
<div class="bought-num">\{{buyNumber}}</div>
<div class="actions">
<span class="buy-again">重新购买</span>
<span class="buy-again" data-rebuy_info='{"buyNumber": \{{buyNumber}}, "productSku": "\{{productSku}}"}'>重新购买</span>
<span class="send-to-favorite" data-product_info='{"goods_type": "\{{goodType}}", "buy_number": \{{buyNumber}}, "selected": "\{{selected}}", "product_sku": "\{{productSku}}", "promotion_id": 0}'>移入收藏夹</span>
</div>
</li>
... ...
... ... @@ -99,13 +99,28 @@ $(function() {
});
$('#removed_products').delegate('.send-to-favorite', 'click', function() {
var $removedProduct = $(this).parents('.removed-product');
Cart.sendToFavorite([$.parseJSON($(this).attr('data-product_info'))], function() {
if ($('#removed_products .removed-product').length > 1) {
$(this).remove();
$removedProduct.remove();
} else {
$('#removed_products').html('');
}
});
}).delegate('.buy-again', 'click', function() {
var productInfo = $.parseJSON($(this).attr('data-rebuy_info')),
$removedProduct = $(this).parents('.removed-product');
Cart.addToCart(productInfo, function() {
Cart.refreshCart(function() {
if ($('#removed_products .removed-product').length > 1) {
$removedProduct.remove();
} else {
$('#removed_products').html('');
}
});
});
});
// 变动商品数量
... ...
... ... @@ -98,37 +98,20 @@ var Cart = {
/*
* 根据服务端JSON,刷新购物车信息
* @function [refreshCart]
* @params { Object } data 最新购物车数据
* @params { Function } callback 刷新购物车后的回调函数
*/
refreshCart: function(data) {
var template;
hbs.registerHelper('multiple', function(num1, num2) {
num1 = typeof num1 === 'number' ? num1 : parseFloat(num1, 10);
num2 = typeof num2 === 'number' ? num2 : parseFloat(num2, 10);
if (num1 && num2) {
return num1 * num2;
}
});
hbs.registerHelper('isEqual', function(v1, v2, options) {
if (v1 === v2) {
return options.fn(this);
refreshCart: function(callback) {
Util.ajax({
url: '/shopping/cart/data',
success: function(res) {
Util.refreshCart(res, function() {
Stepper.init();
if (callback) {
return callback();
}
});
}
return options.inverse(this);
});
hbs.registerHelper('image', function(url, width, height, mode) {
mode = parseInt(mode, 10) ? mode : 2;
url = url || '';
return url.replace(/{width}/g, width).replace(/{height}/g, height).replace(/{mode}/g, mode);
});
template = hbs.compile($('#cart-content-tpl').html());
$('#cart_content').html(template(data));
Stepper.init();
},
/*
... ... @@ -205,7 +188,7 @@ var Cart = {
var dialog;
if (products.length) {
//Cart.showRemovedProducts(products, extraInfos);
// Cart.showRemovedProducts(products, extraInfos);
dialog = new _confirm({
content: '您确定要从购物车中删除该商品吗?',
... ...