Authored by hf

code review by hf: do product detail page add to cart package data

... ... @@ -73,7 +73,6 @@ class DetailData
$param['limit'] = $pageSize;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
... ... @@ -94,7 +93,6 @@ class DetailData
$param['limit'] = $pageSize;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
... ...
... ... @@ -142,7 +142,7 @@ class DetailModel
$result['feedbacks']['comments'][] = $build;
}
$result['feedbacks']['commentsUrl'] = Helpers::url('/product/detail/comments', array('product_id' => $productId, 'total' => $result['feedbacks']['commentsNum']));
}
}
// 品牌信息
if (!empty($baseInfo['brand'])) {
... ... @@ -157,41 +157,59 @@ class DetailModel
// 商品信息
if (!empty($baseInfo['goodsList'])) {
// $colorGroup = array();
// $sizeGroup = array();
$goodsList = array();
$colorGroup = array();
$sizeList = array();
$goodsGroup = array();
$colorId = 0;
foreach ($baseInfo['goodsList'] as $value) {
$colorId = intval($value['colorId']);
// 商品按颜色进行分类分组
$coverImage = '';
$colorStorageNum = 0; // 颜色的库存总数
$totalStorageNum = 0; // 总库存数
foreach ($baseInfo['goodsList'] as $i => $value) {
$sizeList = array();
$colorStorageNum = 0;
// 获取默认的封面图
if ($i === 0) {
$coverImage = Helpers::getImageUrl($value['colorImage'], 60, 60);
}
// 商品分组
if (isset($value['goodsImagesList'])) {
foreach ($value['goodsImagesList'] as $goods) {
$goodsList[$goods['goodsId']] = $colorId;
$goodsGroup[] = array(
'goodsId' => $goods['goodsId'],
'img' => $goods['imageUrl'],
);
// $colorGroup[$colorId] = array(
// 'colorId' => $colorId,
// 'colorName' => $value['colorName'],
// 'colorImage' => Helpers::getImageUrl($value['colorImage'], 60, 60),
// );
}
}
// // 商品的尺码列表
// if (isset($value['goodsSizeBoList'])) {
// foreach ($value['goodsSizeBoList'] as $size) {
// $sizeGroup[$colorId] = array(
// 'sizeName' => $size['sizeName'],
// 'sizeSku' => $size['goodsSizeSkuId'],
// 'sizeStorage' => $size['goodsSizeStorageNum'],
// );
// }
// }
// 商品的尺码列表
if (isset($value['goodsSizeBoList'])) {
foreach ($value['goodsSizeBoList'] as $size) {
$sizeList[] = array(
'id' => $size['id'],
'skuId' => $size['goodsSizeSkuId'],
'goodsId' => $size['goodsId'],
'name' => $size['sizeName'],
'sizeNum' => $size['goodsSizeStorageNum'],
);
$colorStorageNum += intval($size['goodsSizeStorageNum']);
}
}
// 颜色分组
$colorGroup[] = array(
'id' => $value['colorId'],
'skcId' => $value['productSkc'],
'name' => $value['colorName'],
'goodsName' => $value['goodsName'],
'shortUrl' => Helpers::getImageUrl($value['colorImage'], 60, 60),
'colorNum' => $colorStorageNum,
'sizes' => $sizeList,
);
$totalStorageNum += $colorStorageNum;
}
// 商品图: 多个
if (isset($goodsGroup[1])) {
foreach ($goodsGroup as $value) {
... ... @@ -214,11 +232,19 @@ class DetailModel
'numInCart' => 0,
'goodsInstore' => $baseInfo['storage'], // 库存量
);
$soldOut = $baseInfo['storage'] == 0;
$soldOut = $totalStorageNum === 0;
$notForSale = $baseInfo['attribute'] == 2;
// 显示加入购物车链接
if (!$soldOut && !$notForSale) {
$result['cartInfo']['addToCartUrl'] = Helpers::url('/product/buy_' . $productId . '_' . $goodsId . '.html'); //
$result['cartInfo']['addToCartUrl'] = Helpers::url('/product/buy_' . $productId . '_' . $goodsId . '.html');
$result['cartInfo']['productId'] = $productId;
$result['cartInfo']['thumb'] = $coverImage;
$result['cartInfo']['name'] = isset($result['goodsName']) ? $result['goodsName'] : '';
$result['cartInfo']['price'] = isset($result['goodsPrice']['currentPrice']) ? $result['goodsPrice']['currentPrice'] : '';
$result['cartInfo']['salePrice'] = isset($result['goodsPrice']['previousPrice']) ? $result['goodsPrice']['previousPrice'] : '';
$result['cartInfo']['totalNum'] = $totalStorageNum;
$result['cartInfo']['colors'] = $colorGroup;
}
// 非卖品
elseif ($notForSale) {
... ... @@ -251,11 +277,11 @@ class DetailModel
*/
public static function getSizeInfo($productSkn)
{
$result = array();
$result = array();
if (is_numeric($productSkn)) {
// 调用服务
$sizeInfo = DetailData::sizeInfo($productSkn);
$sizeInfo = DetailData::sizeInfo($productSkn);
// 商品信息
if (isset($sizeInfo['productDescBo']['erpProductId'])) {
... ... @@ -345,7 +371,6 @@ class DetailModel
} else {
$result['sizeInfo']['detail']['list'][0]['params'] = array(0 => array('param' => ''));
}
}
// 测量方式
... ...