Authored by htoooth

fix product detail

... ... @@ -38,6 +38,9 @@ const helpers = global.yoho.helpers;
// NOTE: 这里修改了图片质量的参数
helpers.image = _.flow(helpers.image, fp.replace(/\/quality\/\d*$/, '/quality/90'));
// NOTE:这里修改了参数的个数
helpers.getUrlBySkc = pid => `//item.yohobuy.com/product_${pid}.html`;
global.middleware = path.resolve('./doraemon/middleware');
global.utils = path.resolve('./utils');
global.appRoot = path.resolve(__dirname);
... ...
'use strict';
const helpers = global.yoho.helpers;
const mRoot = '../models';
const service = require(`${mRoot}/erp2goods-service`);
... ... @@ -14,7 +12,7 @@ const find = (req, res, next) => {
sku: sku
}).then((result) => {
if (result.url) {
return res.redirect(helpers.urlFormat(result.url, null, 'item'));
return res.redirect(result.url);
}
return next();
... ...
... ... @@ -8,12 +8,13 @@ const api = require('./erp2goods-api');
const _ = require('lodash');
const url = require('url');
const helpers = global.yoho.helpers;
const findBySkn = (skn) => {
return api.getProductBySknAsync(skn).then((result) => {
if (result && result.code && result.code === 200 && result.data.product_url) {
return {
url: url.parse(_.get(result, 'data.product_url', '')).path
url: helpers.getUrlBySkc(result.data.product_id)
};
} else {
return {};
... ...
... ... @@ -295,6 +295,10 @@ const getPackage = (req, res, next) => {
.catch(next);
};
const redirectNewProduct = (req, res) => {
return res.status(301).redirect(helpers.urlFormat(`/product_${req.params[0]}${req.params[2]}`, null, 'item'));
};
module.exports = {
showMain,
indexHotArea,
... ... @@ -306,5 +310,6 @@ module.exports = {
recommend,
getPackage,
likeConsult,
usefulConsult
usefulConsult,
redirectNewProduct
};
... ...
... ... @@ -1394,7 +1394,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
}
// 分享相关,产品的链接
result.weixinUrl = propOrigin('product_url');
result.weixinUrl = helpers.getUrlBySkc(propOrigin('product_id'));
result.shareTitle = result.name;
result.shareImg = helpers.getForceSourceUrl(result.img);
result.shareDesc = result.phrase;
... ... @@ -1414,8 +1414,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
result.salePrice :
(result.marketPrice || result.presalePrice)).replace('¥', ''); // 数字
statGoodsInfo.imageUrl = helpers.getForceSourceUrl(result.img);
statGoodsInfo.productUrl = 'http:' +
helpers.urlFormat(url.parse(propOrigin('product_url')).pathname, null, 'item');
statGoodsInfo.productUrl = 'http:' + helpers.getUrlBySkc(propOrigin('product_id'));
statGoodsInfo.smallSortId = result.smallSortId;
statGoodsInfo.soldOut = soldOut ? 1 : 0;
... ...
... ... @@ -62,7 +62,8 @@ router.get('/outlets/:channel', outlets.channel); // 奥莱频道页
// 商品分类列表页
router.get('/list', outletsList.index);
router.get(/\/pro_([\d]+)_([\d]+)\/(.*)/, detail.showMain); // 商品详情routers
router.get(/\/pro_([\d]+)_([\d]+)\/(.*)/, detail.redirectNewProduct);
router.get(/\/product_([\d]+)(.*)/, detail.showMain); // 商品详情routers
router.get('/detail/comment', detail.indexComment); // 商品评论
router.get('/detail/consult', detail.indexConsult); // 商品咨询
router.post('/detail/consult', auth, detail.createConsult); // 创建咨询
... ...
... ... @@ -22,6 +22,9 @@ module.exports = () => {
case 'new': // 原新版
case 'shop': // 商家入驻
case 'item':// 商品详情页
if (/\/product_([\d]+)(.*)/.exec(req.url) !== null) {
req.url = `/product/product_${RegExp.$1}${RegExp.$2}`;
}
break;
case 'guang': // 逛
case 'cdnsrcguang': // 逛CDN回源解析
... ...
... ... @@ -44,9 +44,7 @@ const handleGoodsListData = (origin) => {
if (!_.isEmpty(value.goods_list)) {
_.forEach(value.goods_list, (subValue, subKey) => {
origin[key].goods_list[subKey].url =
helpers.urlFormat(
`/product/pro_${value.product_id}_${subValue.goods_id}` +
`/${value.cn_alphabet}.html`);
helpers.getUrlBySkc(value.product_id, subValue.goods_id, value.cn_alphabet);
});
}
});
... ... @@ -198,7 +196,7 @@ exports.processProductList = (list, options) => {
product.cn_alphabet = procCnAlphabetName(product.cn_alphabet);
product.is_few = product.is_soon_sold_out === 'Y';
product.url = helpers.urlFormat(`/product/pro_${product.product_id}_${_.get(product, 'goods_list[0].goods_id', 0)}/${product.cn_alphabet}.html`, '', 'item'); // eslint-disable-line
product.url = helpers.getUrlBySkc(product.product_id, _.get(product, 'goods_list[0].goods_id'), product.cn_alphabet);// eslint-disable-line
// tar add 1606071146 品牌链接处理
product.brandUrl = helpers.urlFormat('', '', product.brand_domain);
... ... @@ -446,8 +444,7 @@ exports.processProduct = (productData, options) => {
}
result.is_soon_sold_out = (productData.is_soon_sold_out === 'Y');
result.url = helpers.urlFormat(`/product/pro_${productData.product_id}_${productData.goods_list[0].goods_id}/${productData.cn_alphabet}.html`, null, 'item'); // eslint-disable-line
result.url = helpers.getUrlBySkc(productData.product_id, _.get(productData, "goods_list[0].goods_id"), productData.cn_alphabet);// eslint-disable-line
if (options.showTags) {
result.tags = {};
... ...