Authored by jinhu.tung

init shopping cart

/**
* 购物车 controller
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/07/04
*/
'use strict';
const cartModel = require('../models/cart');
const _ = require('lodash');
exports.index = (req, res) => {
cartModel.getCartInfo().then((result) => {
res.render('cart', _.merge({
module: 'shopping',
page: 'cart'
}, result[0], result[1], result[2]));
}).catch((err) => {
res.send(err);
});
};
... ...
/**
* 订单 controller
* @author: TODO
* @date: 2016/07/04
*/
... ...
/**
* 订单支付 controller
* @author: TODO
* @date: 2016/07/04
*/
... ...
/**
* sub app shopping
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/07/04
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
var app = express();
// set view engin
var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: 'helpers'
}));
// router
app.use(require('./router'));
module.exports = app;
... ...
/**
* 购物车模型 model
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/07/04
*/
'use strict';
var Promise = require('bluebird');
// const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
// const sign = require(`${global.library}/sign`);
// const logger = require(`${global.library}/logger`);
// const headerModel = require('../../../doraemon/models/header');
// var api = new ServiceAPI();
// 获取预售商品
const getPreSaleProducts = () => {
return Promise.resolve({
preSalePros: [{
productName: 'Alle nove 小方领长袖衬衫【哥本哈根】'
}]
});
};
// 获取普通商品
const getNormalProducts = () => {
return Promise.resolve({
commonPros: [{ gender: '1',
tags: ['Object'],
status: 1,
smallSortId: 115,
vip1Price: 379.04999999999995,
isGlobal: 'N',
vip3Price: 351.12,
isOutlets: 2,
isDiscount: 'Y',
brandDomain: 'allenove',
isSpecial: 'N',
goodsList: ['Object'],
isAdvance: 'N',
productId: 286137,
vipDiscountType: 1,
salesNum: 0,
cnAlphabet: 'ALLENOVE95S12SaiWeiLiYa',
productSkn: 51160999,
shelveTime: 1455616165,
vip2Price: 359.1,
editTime: 1455616165,
isNew: 'N',
isLimited: 'N',
brandName: 'Alle nove',
maxSortId: 1,
productName: 'Alle nove 暗扣领长袖衬衫【塞维利亚】',
brandId: 1007,
defaultImages: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/03/01d7c265b0fa3fe1a582a73ad9175eab69.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
stockNumber: 23,
storageNum: 23,
isSoonSoldOut: false,
middleSortId: 12,
salesPrice: 399,
isPromotion: 101,
marketPrice: 1299,
vipPrice: 0,
id: 51160999,
thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/10/21/03/01d7c265b0fa3fe1a582a73ad9175eab69.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
url: 'http://www.yohobuy.com/product/pro_286137_367987/ALLENOVE95S12SaiWeiLiYa.html',
brandUrl: '//allenove.yohobuy.com' }]
});
};
// 获取失效商品
const getInvalidProducts = () => {
return Promise.resolve({
invalidPros: [{ gender: '1',
tags: ['Object'],
status: 1,
smallSortId: 115,
vip1Price: 379.04999999999995,
isGlobal: 'N',
vip3Price: 351.12,
isOutlets: 2,
isDiscount: 'Y',
brandDomain: 'allenove',
isSpecial: 'N',
goodsList: ['Object'],
isAdvance: 'N',
productId: 286139,
vipDiscountType: 1,
salesNum: 0,
cnAlphabet: 'ALLENOVE95S13PuLuoWangSi',
productSkn: 51161000,
shelveTime: 1455616165,
vip2Price: 359.1,
editTime: 1455616165,
isNew: 'N',
isLimited: 'N',
brandName: 'Alle nove',
maxSortId: 1,
productName: 'Alle nove 复古圆领长袖衬衫【普罗旺斯】',
brandId: 1007,
defaultImages: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/03/02705334cacca0a06edec049918290f7b3.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
stockNumber: 12,
storageNum: 12,
isSoonSoldOut: false,
middleSortId: 12,
salesPrice: 399,
isPromotion: 101,
marketPrice: 1299,
vipPrice: 0,
id: 51161000,
thumb: 'http://img12.static.yhbimg.com/goodsimg/2015/10/21/03/02705334cacca0a06edec049918290f7b3.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/80',
url: 'http://www.yohobuy.com/product/pro_286139_367989/ALLENOVE95S13PuLuoWangSi.html',
brandUrl: '//allenove.yohobuy.com' }]
});
};
// 移入收藏夹
exports.transferToFavorite = () => {
// TODO
};
// 获取购物车信息
exports.getCartInfo = () => {
return Promise.all([
getPreSaleProducts(),
getNormalProducts(),
getInvalidProducts()
]);
};
... ...
/**
* router of sub app shopping
* @author: jinhu.dong<jinhu.dong@yoho.cn>
* @date: 2016/07/04
*/
'use strict';
const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
// cart related controllers
const cartCtrl = require(`${cRoot}/cart`);
router.get('/cart', cartCtrl.index);
module.exports = router;
... ...
<div class="home-page">
<div class="center-content">
{{> common/bc-nav}}
{{> common/info}}
</div>
</div>
... ...
<div class="cart-bc">
<ul class="breadcrumb">
<li class="level-1 current"><a href="/">我的购物袋<em></em><i></i></a></li>
<li class="level-2"><a href="/vehicles/">填写核对订单信息<em></em><i></i></a></li>
<li class="level-3"><a href="/vehicles/vans/">成功提交订单<em></em><i></i></a></li>
</ul>
</div>
\ No newline at end of file
... ...
<div class="not-login-info">
<div class="info-bar">
<p>温馨提示: 亲爱的顾客,您还没有登录哦, 所有的商品价购、活动信息以登录后显示为准。</p>
<span class="iconfont pull-right">&#xe608;</span>
</div>
<div>
\ No newline at end of file
... ...
... ... @@ -10,5 +10,7 @@ module.exports = app => {
app.use('/partial', require('./apps/partial')); // 组件demo
// 业务模块
//app.use('/passport', require('./apps/passport'));
// app.use('/passport', require('./apps/passport'));
app.use('/shopping', require('./apps/shopping')); // 购物车
};
... ...
... ... @@ -7,3 +7,7 @@
@import "base";
@import "components/index";
@import "channel/index";
/* 购物车 */
@import "shopping/index";
... ...
.cart-bc {
width: 100%;
position: relative;
background: #999;
}
.breadcrumb {
list-style: none;
overflow: hidden;
margin: 0;
padding: 0;
height: 34px;
.current {
background: #1b1b1b;
color: #fff;
z-index: 1;
i {
border-color: #fff transparent #fff #1b1b1b;
}
}
li {
float: left;
width: 365px;
text-align: center;
position: relative;
z-index: 2;
font-weight: bold;
font-size: 14px;
line-height: 32px;
&:last-child {
i {
right: -17px;
}
}
a {
color: #fff;
width: 100%;
display: inline-block;
position: relative;
z-index: 0;
}
em {
position: absolute;
right: -24px;
top: -8px;
width: 0;
height: 0;
line-height: 0;
border-width: 24px 0 24px 24px;
border-color: transparent transparent transparent #fff;
border-style: dashed dashed dashed solid;
}
i {
position: absolute;
right: -6px;
top: 0;
width: 0;
height: 0;
line-height: 0;
border-width: 17px 0 17px 17px;
border-color: #fff transparent #fff #999;
border-style: dashed dashed dashed solid;
z-index: 1000;
}
}
.level-1 {
width: 375px;
}
.level-2 {
width: 400px;
}
.level-3 {
width: 375px;
}
}
... ...
@import "breadcrumb"; /* 导航 */
@import "info_bar"; /* 信息提示 */
... ...