Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
5ef59381
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
18
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5ef59381
编写于
7月 14, 2017
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
手机端产品详细页面,显示产品组属性
上级
56e90409
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
118 addition
and
44 deletion
+118
-44
app/apphtml5/modules/Catalog/block/product/Index.php
app/apphtml5/modules/Catalog/block/product/Index.php
+97
-40
app/apphtml5/theme/base/html5/catalog/product/index.php
app/apphtml5/theme/base/html5/catalog/product/index.php
+21
-4
未找到文件。
app/apphtml5/modules/Catalog/block/product/Index.php
浏览文件 @
5ef59381
...
...
@@ -18,11 +18,20 @@ use Yii;
*/
class
Index
{
// 当前产品
protected
$_product
;
// 产品页面的title
protected
$_title
;
// 产品的主键对应的值
protected
$_primaryVal
;
// 产品的spu属性数组。
protected
$_productSpuAttrArr
;
// 以图片方式显示的spu属性
protected
$_spuAttrShowAsImg
;
// 在产品详细页面,在橱窗图部分,以放大镜的方式显示的产品图片列表
protected
$_image_thumbnails
;
// 在产品详细页面,在产品描述部分显示的产品图片列表
protected
$_image_detail
;
public
function
getLastData
()
{
...
...
@@ -32,10 +41,14 @@ class Index
ReviewHelper
::
initReviewConfig
();
$ReviewAndStarCount
=
ReviewHelper
::
getReviewAndStarCount
(
$this
->
_product
);
list
(
$review_count
,
$reviw_rate_star_average
)
=
$ReviewAndStarCount
;
$this
->
filterProductImg
(
$this
->
_product
[
'image'
]);
$groupAttr
=
Yii
::
$service
->
product
->
getGroupAttr
(
$this
->
_product
[
'attr_group'
]);
$groupAttrArr
=
$this
->
getGroupAttrArr
(
$groupAttr
);
return
[
'groupAttrArr'
=>
$groupAttrArr
,
'name'
=>
Yii
::
$service
->
store
->
getStoreAttrVal
(
$this
->
_product
[
'name'
],
'name'
),
'image'
=>
$this
->
_product
[
'image'
],
'image_thumbnails'
=>
$this
->
_image_thumbnails
,
'image_detail'
=>
$this
->
_image_detail
,
'sku'
=>
$this
->
_product
[
'sku'
],
'spu'
=>
$this
->
_product
[
'spu'
],
'attr_group'
=>
$this
->
_product
[
'attr_group'
],
...
...
@@ -43,7 +56,7 @@ class Index
'reviw_rate_star_average'
=>
$reviw_rate_star_average
,
'price_info'
=>
$this
->
getProductPriceInfo
(),
'tier_price'
=>
$this
->
_product
[
'tier_price'
],
'media_size'
=>
[
'media_size'
=>
[
'small_img_width'
=>
$productImgSize
[
'small_img_width'
],
'small_img_height'
=>
$productImgSize
[
'small_img_height'
],
'middle_img_width'
=>
$productImgSize
[
'middle_img_width'
],
...
...
@@ -56,7 +69,49 @@ class Index
'buy_also_buy'
=>
$this
->
getProductBySkus
(
$skus
),
];
}
public
function
getGroupAttrArr
(
$groupAttr
){
$gArr
=
[];
if
(
is_array
(
$groupAttr
)){
foreach
(
$groupAttr
as
$attr
){
if
(
isset
(
$this
->
_product
[
$attr
])
&&
$this
->
_product
[
$attr
]){
$gArr
[
$attr
]
=
$this
->
_product
[
$attr
];
}
}
}
//var_dump($gArr);
return
$gArr
;
}
/**
* @property $product_images | Array ,产品的图片属性
* 根据图片数组,得到橱窗图,和描述图
* 橱窗图:在产品详细页面顶部,放大镜显示部分的产品列表
* 描述图,在产品description文字描述后面显示的产品图片。
*/
public
function
filterProductImg
(
$product_images
){
$this
->
_image_thumbnails
=
$product_images
;
//$this->_image_detail['gallery'] = $product_images['gallery'];
if
(
isset
(
$product_images
[
'gallery'
])
&&
is_array
(
$product_images
[
'gallery'
])){
$thumbnails_arr
=
[];
$detail_arr
=
[];
foreach
(
$product_images
[
'gallery'
]
as
$one
){
$is_thumbnails
=
$one
[
'is_thumbnails'
];
$is_detail
=
$one
[
'is_detail'
];
if
(
$is_thumbnails
==
1
){
$thumbnails_arr
[]
=
$one
;
}
if
(
$is_detail
==
1
){
$detail_arr
[]
=
$one
;
}
}
$this
->
_image_thumbnails
[
'gallery'
]
=
$thumbnails_arr
;
$this
->
_image_detail
=
$detail_arr
;
}
if
(
isset
(
$product_images
[
'main'
][
'is_detail'
])
&&
$product_images
[
'main'
][
'is_detail'
]
==
1
){
$this
->
_image_detail
[]
=
$product_images
[
'main'
];
}
}
/**废弃
* @property $data | Array 和当前产品的spu相同,但sku不同的产品 数组。
* @property $current_size | String 当前产品的size值
...
...
@@ -80,38 +135,38 @@ class Index
//echo $attr1_val;
//echo $size;
//echo '##';
$image
=
$one
[
'image'
];
$name
=
$one
[
'name'
];
$image
=
$one
[
'image'
];
$name
=
$one
[
'name'
];
$url_key
=
$one
[
'url_key'
];
if
(
$attr1_val
||
$attr2_val
)
{
if
(
$attr1_val
)
{
$all_attr1
[
$attr1_val
]
=
[
'name'
=>
$name
,
'name'
=>
$name
,
'image'
=>
$image
,
'url_key'
=>
$url_key
,
'url_key'
=>
$url_key
,
];
}
if
(
$attr2_val
)
{
$all_attr2
[
$attr2_val
]
=
[
'name'
=>
$name
,
'name'
=>
$name
,
'image'
=>
$image
,
'url_key'
=>
$url_key
,
'url_key'
=>
$url_key
,
];
}
//echo $attr2_val.'#'.$current_attr2;
//echo '<br/>';
if
(
$attr2_val
&&
$current_attr2
==
$attr2_val
)
{
$attr1_2_attr2
[
$attr1_val
]
=
[
'name'
=>
$name
,
'name'
=>
$name
,
'image'
=>
$image
,
'url_key'
=>
$url_key
,
'url_key'
=>
$url_key
,
];
}
if
(
$attr1_val
&&
$current_attr1
==
$attr1_val
)
{
$attr2_2_attr1
[
$attr2_val
]
=
[
'name'
=>
$name
,
'name'
=>
$name
,
'image'
=>
$image
,
'url_key'
=>
$url_key
,
'url_key'
=>
$url_key
,
];
}
}
...
...
@@ -127,12 +182,12 @@ class Index
*/
protected
function
getSpuData
(
$select
)
{
$spu
=
$this
->
_product
[
'spu'
];
$spu
=
$this
->
_product
[
'spu'
];
$select
=
array_merge
(
$select
,
$this
->
_productSpuAttrArr
);
$filter
=
[
'select'
=>
$select
,
'where'
=>
[
'select'
=>
$select
,
'where'
=>
[
[
'spu'
=>
$spu
],
],
'asArray'
=>
true
,
...
...
@@ -150,10 +205,11 @@ class Index
*/
protected
function
getSameSpuInfo
()
{
$groupAttr
=
Yii
::
$service
->
product
->
getGroupAttr
(
$this
->
_product
[
'attr_group'
]);
// 当前的产品对应的spu属性组的属性,譬如 ['color','size','myyy']
$this
->
_productSpuAttrArr
=
Yii
::
$service
->
product
->
getSpuAttr
(
$this
->
_product
[
'attr_group'
]);
$this
->
_spuAttrShowAsImg
=
Yii
::
$service
->
product
->
getSpuImgAttr
(
$this
->
_product
[
'attr_group'
]);
//var_dump($this->_productSpuAttrArr);exit;
$this
->
_spuAttrShowAsImg
=
Yii
::
$service
->
product
->
getSpuImgAttr
(
$this
->
_product
[
'attr_group'
]);
if
(
!
is_array
(
$this
->
_productSpuAttrArr
)
||
empty
(
$this
->
_productSpuAttrArr
))
{
return
;
}
...
...
@@ -170,8 +226,8 @@ class Index
}
}
// 得到当前的spu下面的所有的值
$select
=
[
'name'
,
'image'
,
'url_key'
];
$data
=
$this
->
getSpuData
(
$select
);
$select
=
[
'name'
,
'image'
,
'url_key'
];
$data
=
$this
->
getSpuData
(
$select
);
$spuValColl
=
[];
// 通过值,找到spu。
$reverse_val_spu
=
[];
...
...
@@ -185,9 +241,9 @@ class Index
//$active = 'class="active"';
$one
[
'main_img'
]
=
isset
(
$one
[
'image'
][
'main'
][
'image'
])
?
$one
[
'image'
][
'main'
][
'image'
]
:
''
;
$one
[
'url'
]
=
Yii
::
$service
->
url
->
getUrl
(
$one
[
'url_key'
]);
$one
[
'url'
]
=
Yii
::
$service
->
url
->
getUrl
(
$one
[
'url_key'
]);
$reverse_val_spu
[
$reverse_key
]
=
$one
;
$showAsImgVal
=
$one
[
$this
->
_spuAttrShowAsImg
];
$showAsImgVal
=
$one
[
$this
->
_spuAttrShowAsImg
];
if
(
$showAsImgVal
)
{
if
(
!
isset
(
$this
->
_spuAttrShowAsImgArr
[
$this
->
_spuAttrShowAsImg
]))
{
$this
->
_spuAttrShowAsImgArr
[
$showAsImgVal
]
=
$one
;
...
...
@@ -232,10 +288,10 @@ class Index
$active
=
true
;
}
}
$reverse_key
=
$this
->
generateSpuReverseKey
(
$current
);
$return
=
[];
$reverse_key
=
$this
->
generateSpuReverseKey
(
$current
);
$return
=
[];
$return
[
'attr_val'
]
=
$attrVal
;
$return
[
'active'
]
=
'noactive'
;
$return
[
'active'
]
=
'noactive'
;
//echo $reverse_key."<br/>";
if
(
isset
(
$reverse_val_spu
[
$reverse_key
])
&&
is_array
(
$reverse_val_spu
[
$reverse_key
]))
{
...
...
@@ -289,8 +345,8 @@ class Index
// 对size排序一下
$size
=
[];
$attr_group
=
$this
->
_product
[
'attr_group'
];
$attrInfo
=
Yii
::
$service
->
product
->
getGroupAttrInfo
(
$attr_group
);
$size_arr
=
isset
(
$attrInfo
[
$spuAttr
][
'display'
][
'data'
])
?
$attrInfo
[
$spuAttr
][
'display'
][
'data'
]
:
''
;
$attrInfo
=
Yii
::
$service
->
product
->
getGroupAttrInfo
(
$attr_group
);
$size_arr
=
isset
(
$attrInfo
[
$spuAttr
][
'display'
][
'data'
])
?
$attrInfo
[
$spuAttr
][
'display'
][
'data'
]
:
''
;
$d_arr
=
[];
if
(
is_array
(
$size_arr
)
&&
!
empty
(
$size_arr
))
{
foreach
(
$size_arr
as
$size
)
{
...
...
@@ -312,10 +368,10 @@ class Index
*/
protected
function
getProductPriceInfo
()
{
$price
=
$this
->
_product
[
'price'
];
$price
=
$this
->
_product
[
'price'
];
$special_price
=
$this
->
_product
[
'special_price'
];
$special_from
=
$this
->
_product
[
'special_from'
];
$special_to
=
$this
->
_product
[
'special_to'
];
$special_from
=
$this
->
_product
[
'special_from'
];
$special_to
=
$this
->
_product
[
'special_to'
];
return
Yii
::
$service
->
product
->
price
->
getCurrentCurrencyProductPriceInfo
(
$price
,
$special_price
,
$special_from
,
$special_to
);
}
...
...
@@ -331,17 +387,17 @@ class Index
*/
protected
function
initProduct
()
{
$primaryKey
=
Yii
::
$service
->
product
->
getPrimaryKey
();
$primaryVal
=
Yii
::
$app
->
request
->
get
(
$primaryKey
);
$primaryKey
=
Yii
::
$service
->
product
->
getPrimaryKey
();
$primaryVal
=
Yii
::
$app
->
request
->
get
(
$primaryKey
);
$this
->
_primaryVal
=
$primaryVal
;
$product
=
Yii
::
$service
->
product
->
getByPrimaryKey
(
$primaryVal
);
$this
->
_product
=
$product
;
$product
=
Yii
::
$service
->
product
->
getByPrimaryKey
(
$primaryVal
);
$this
->
_product
=
$product
;
Yii
::
$app
->
view
->
registerMetaTag
([
'name'
=>
'keywords'
,
'name'
=>
'keywords'
,
'content'
=>
Yii
::
$service
->
store
->
getStoreAttrVal
(
$product
[
'meta_keywords'
],
'meta_keywords'
),
]);
Yii
::
$app
->
view
->
registerMetaTag
([
'name'
=>
'description'
,
'name'
=>
'description'
,
'content'
=>
Yii
::
$service
->
store
->
getStoreAttrVal
(
$product
[
'meta_description'
],
'meta_description'
),
]);
$this
->
_title
=
Yii
::
$service
->
store
->
getStoreAttrVal
(
$product
[
'meta_title'
],
'meta_title'
);
...
...
@@ -370,7 +426,7 @@ class Index
if
(
is_array
(
$parent_info
)
&&
!
empty
(
$parent_info
))
{
foreach
(
$parent_info
as
$info
)
{
$parent_name
=
Yii
::
$service
->
store
->
getStoreAttrVal
(
$info
[
'name'
],
'name'
);
$parent_url
=
Yii
::
$service
->
url
->
getUrl
(
$info
[
'url_key'
]);
$parent_url
=
Yii
::
$service
->
url
->
getUrl
(
$info
[
'url_key'
]);
Yii
::
$service
->
page
->
breadcrumbs
->
addItems
([
'name'
=>
$parent_name
,
'url'
=>
$parent_url
]);
}
}
...
...
@@ -393,8 +449,9 @@ class Index
'url_key'
,
'score'
,
];
$filter
[
'where'
]
=
[
'in'
,
'sku'
,
$skus
];
$products
=
Yii
::
$service
->
product
->
getProducts
(
$filter
);
$products
=
Yii
::
$service
->
category
->
product
->
convertToCategoryInfo
(
$products
);
$products
=
Yii
::
$service
->
product
->
getProducts
(
$filter
);
//var_dump($products);
$products
=
Yii
::
$service
->
category
->
product
->
convertToCategoryInfo
(
$products
);
return
$products
;
}
...
...
app/apphtml5/theme/base/html5/catalog/product/index.php
浏览文件 @
5ef59381
...
...
@@ -19,10 +19,10 @@
'view'
=>
'catalog/product/index/image.php'
];
$imageParam
=
[
'media_size'
=>
$media_size
,
'image'
=>
$image
,
'productImgMagnifier'
=>
$productImgMagnifier
,
];
'media_size'
=>
$media_size
,
'image'
=>
$image_thumbnails
,
'productImgMagnifier'
=>
$productImgMagnifier
,
];
?>
<?=
Yii
::
$service
->
page
->
widget
->
render
(
$imageView
,
$imageParam
);
?>
</div>
...
...
@@ -152,7 +152,24 @@
<div
id=
"tab1"
class=
"tab active"
>
<div
class=
"content-block"
>
<div
class=
"text-description"
style=
""
>
<?php
if
(
is_array
(
$groupAttrArr
))
:
?>
<table>
<?php
foreach
(
$groupAttrArr
as
$k
=>
$v
)
:
?>
<tr><td>
<?=
$k
?>
</td><td>
<?=
$v
?>
</td></tr>
<?php
endforeach
;
?>
</table>
<br/>
<?php
endif
;
?>
<?=
$description
;
?>
<div
class=
"img-section"
>
<?php
if
(
is_array
(
$image_detail
))
:
?>
<?php
foreach
(
$image_detail
as
$image_detail_one
)
:
?>
<br/>
<img
class=
"lazy"
src=
"
<?=
Yii
::
$service
->
image
->
getImgUrl
(
'images/lazyload.gif'
);
?>
"
data-src=
"
<?=
Yii
::
$service
->
product
->
image
->
getUrl
(
$image_detail_one
[
'image'
]);
//->getResize($image_detail_one['image'],550,false) ?>" />
<?
php
endforeach
;
?>
<?php
endif
;
?>
</div>
</div>
</div>
</div>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录