HelperHome.js 1.32 KB
'use strict';

const helpers = global.yoho.helpers;
const Images = require('../../../utils/Images');

const formatFavBrand = ($brandInfo, $i)=>{
    $i = $i || 10;
    let $hotBrands = [];
    if ($brandInfo.length > 0) {
        for (let i = 0; i < $brandInfo.length; i++) {
            let $value = $brandInfo[i];
            if ($value.is_hot && $value.is_hot == 'Y') {
                $hotBrands.push({
                    'href': helpers.urlFormat('', '', $value['brand_domain']),
                    'logo': Images.getSourceUrl($value['brand_ico'], 'brandLogo'),
                    'name': $value.brand_name
                });
                $i--;
            }
            if ($i <= 0) {
                break;
            }
        }
    }
    return $hotBrands;
};
const formatNew = ($product)=>{
    let $result = [];
    $product.forEach(function($val, $key) {
        $result[$key] = {};
        $result[$key]['href'] = helpers.getUrlBySkc($val['product_id'], $val['goods_list'][0]['product_skc'], $val['cn_alphabet']);
        $result[$key]['thumb'] = $val['default_images'] ? Images.getImageUrl($val['default_images'], 400, 500) : '';
        $result[$key]['name'] = $val['product_name'];
        $result[$key]['price'] = $val['sales_price'];
    });
    return $result;
};

module.exports = {
    formatFavBrand,
    formatNew
};