Authored by 郭成尧

category-url

... ... @@ -632,6 +632,7 @@ const shopCategory = (req, res, next) => {
req.ctx(listModel).getShopCategory({
shopId: req.query.shop_id,
domain: req.query.domain,
channel: req.yoho.channel,
gender: req.query.gender || '1,3'
}).then(result => {
... ...
... ... @@ -235,6 +235,7 @@ const shop = {
*/
redShop(req, res, next) {
let shopId = req.shopInfo.shops_id;
let domain = req.shopInfo.shop_domain || req.shopInfo.brandDomain || 'shop';
let channel = req.yoho.channel || 'boys';
let uid = req.user.uid || 0;
let udid = req.cookies.udid || 'yoho';
... ... @@ -256,7 +257,10 @@ const shop = {
let shopInfo = req.shopInfo;
let favCount = _.get(favCountData, 'data[0].approximateCount', '2.1w');
let decoratorsAll = shopPrcs.floor(_.get(decoratorsData, 'data.modules', []));
let category = shopPrcs.category(_.get(categoryData, 'data', []), shopId);
let category = shopPrcs.category(_.get(categoryData, 'data', []), {
shopId: shopId,
domain: domain
});
let goodsListBySkn = yield req.ctx(searchModel).searchProductBySkn(decoratorsAll.skns);
let decorators = shopPrcs.pushGoodsInfo(decoratorsAll.decorators, goodsListBySkn);
... ... @@ -268,7 +272,8 @@ const shop = {
shopPage: {
text: '分类',
url: helpers.urlFormat('/product/index/category', {
shop_id: shopId
shop_id: shopId,
domain: domain
})
}
}, headerModel.setNav({
... ... @@ -291,15 +296,11 @@ const shop = {
banner, shopInfo, favCount, decorators, category
};
let domain = req.shopInfo.shop_domain || req.shopInfo.brandDomain || null;
if (domain) {
_.assign(finalResult, {
canonical: {
currentHref: `https://www.yohobuy.com${req.originalUrl}`
}
});
}
_.assign(finalResult, {
canonical: {
currentHref: `https://www.yohobuy.com${req.originalUrl}`
}
});
// 店铺收藏开关
let shppFavHide = _.get(req.app.locals.wap, 'shop.removeCollect', false);
... ...
... ... @@ -10,6 +10,7 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const searchModel = require('./search');
const productProcess = require(`${utils}/product-process`);
const listParamsProcess = require(`${utils}/list-params-process`);
const stringProcess = require(`${global.utils}/string-process`);
/**
... ... @@ -771,23 +772,21 @@ module.exports = class extends global.yoho.BaseModel {
});
_.forEach(value.sub, (subValue, subKey) => {
value.sub[subKey].url = helpers.urlFormat('', {
value.sub[subKey].url = listParamsProcess.generatePathUrl({
shop_id: params.shopId,
sort: _.get(subValue, 'relation_parameter.sort', ''),
title: subValue.category_name,
query: subValue.category_name
}, 'search');
title: subValue.category_name
}, `shop/${params.domain}-${params.shopId}`);
});
let subCategory = [
{
category_name: '全部' + value.category_name,
url: helpers.urlFormat('', {
url: listParamsProcess.generatePathUrl({
shop_id: params.shopId,
sort: _.get(value, 'relation_parameter.sort', ''),
title: '全部' + value.category_name,
query: value.category_name
}, 'search')
title: '全部' + value.category_name
}, `shop/${params.domain}-${params.shopId}`)
}
];
... ... @@ -798,9 +797,9 @@ module.exports = class extends global.yoho.BaseModel {
});
});
finalResult.allProduct = helpers.urlFormat('', {
shop_id: params.shopId
}, 'search');
finalResult.allProduct = listParamsProcess.generatePathUrl({
title: '全部商品'
}, `shop/${params.domain}-${params.shopId}`);
return finalResult;
});
... ...
... ... @@ -67,8 +67,9 @@ const getParams = (pathParams) => {
/**
* 生成链接
* @param {参数} queryParams
* @param {path} path
*/
const generatePathUrl = (queryParams) => {
const generatePathUrl = (queryParams, path) => {
let pathUrlParams = []; // 可以找到对应关系的参数
let noFindParams = []; // 没有找到对应关系的
let pathUrl = '';
... ... @@ -89,7 +90,7 @@ const generatePathUrl = (queryParams) => {
pathUrl += noFindParams.length ? '?' + noFindParams.join('&') : '';
pathUrl = (pathUrl && !_.startsWith(pathUrl, '?')) ? `/${pathUrl}` : pathUrl;
return `${config.subDomains.default}/list${pathUrl}`;
return `${config.subDomains.default}/${path || 'list'}${pathUrl}`;
};
module.exports = {
... ...
... ... @@ -10,6 +10,7 @@
const _ = require('lodash');
const helpers = global.yoho.helpers;
const productPrcs = require('./product-process');
const listParamsProcess = require('./list-params-process');
const GENDER = {
1: '男',
2: '女',
... ... @@ -293,7 +294,7 @@ const shopIntro = (params) => {
* 店铺分类处理
* @param {*} params
*/
const category = (params, shopId) => {
const category = (params, shopParams) => {
let categoryData = {
list: [],
url: ''
... ... @@ -305,16 +306,16 @@ const category = (params, shopId) => {
if (params.length > 6) {
categoryData.url = helpers.urlFormat('/product/index/category', {
shop_id: shopId
shop_id: shopParams.shopId
});
} else {
_.forEach(params, value => {
categoryData.list.push({
url: helpers.urlFormat('', {
shop_id: shopId,
sort: (value.relation_parameter && value.relation_parameter.sort) || ''
}, 'search'),
categoryId: value.category_id,
url: listParamsProcess.generatePathUrl({
shop_id: shopParams.shopId,
sort: (value.relation_parameter && value.relation_parameter.sort) || '',
title: value.category_name
}, `shop/${shopParams.domain}-${shopParams.shopId}`),
name: value.category_name
});
});
... ...