cart-info.js 774 Bytes
/**
 * 购物车信息读取
 * @author: liangzhifeng<zhifeng.liang@yoho.cn>
 * @date: 2015/12/15
 */
var info = window.cookie('cart-info');

// info 必须是 JSON 字符串
try {
    info = JSON.parse(info);
} catch (e) {
    info = {
        deliveryId: null,
        deliveryTimeId: null,
        paymentTypeId: null,
        yohoCoin: null,
        addressId: null,
        couponCode: null,
        couponValue: null,
        invoice: null,
        invoiceText: null,
        invoiceType: null,
        msg: null
    };
    window.setCookie('cart-info', JSON.stringify(info));
}

exports.cartInfo = function(key, value) {
    if (value === undefined) {
        return info[key];
    }
    info[key] = value;
    window.setCookie('cart-info', JSON.stringify(info));
};