Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
4289b214
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,发现更多精彩内容 >>
提交
4289b214
编写于
10月 20, 2016
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
product page: relate product by color and size in product page
上级
0a62cc15
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
248 addition
and
2 deletion
+248
-2
app/appfront/modules/Catalog/block/product/Index.php
app/appfront/modules/Catalog/block/product/Index.php
+156
-0
app/appfront/theme/base/front/assets/css/style.css
app/appfront/theme/base/front/assets/css/style.css
+17
-0
app/appfront/theme/base/front/catalog/product/index.php
app/appfront/theme/base/front/catalog/product/index.php
+22
-2
services/Product.php
services/Product.php
+12
-0
services/product/ProductMongodb.php
services/product/ProductMongodb.php
+41
-0
未找到文件。
app/appfront/modules/Catalog/block/product/Index.php
浏览文件 @
4289b214
...
...
@@ -27,9 +27,13 @@ class Index {
$productImgMagnifier
=
Yii
::
$app
->
controller
->
module
->
params
[
'productImgMagnifier'
];
$this
->
initProduct
();
return
[
'name'
=>
Yii
::
$service
->
store
->
getStoreAttrVal
(
$this
->
_product
[
'name'
],
'name'
),
'image'
=>
$this
->
_product
[
'image'
],
'sku'
=>
$this
->
_product
[
'sku'
],
'price_info'
=>
$this
->
getProductPriceInfo
(),
'tier_price'
=>
$this
->
_product
[
'tier_price'
],
'media_size'
=>
[
...
...
@@ -38,10 +42,150 @@ class Index {
'middle_img_width'
=>
$productImgSize
[
'middle_img_width'
],
],
'productImgMagnifier'
=>
$productImgMagnifier
,
'options'
=>
$this
->
getSameSpuInfo
(),
];
}
protected
function
getSpuData
(){
$spu
=
$this
->
_product
[
'spu'
];
$filter
=
[
'select'
=>
[
'name'
,
'image'
,
'color'
,
'size'
,
'url_key'
],
'where'
=>
[
[
'spu'
=>
$spu
],
],
'asArray'
=>
true
,
];
$coll
=
Yii
::
$service
->
product
->
coll
(
$filter
);
return
$coll
[
'coll'
];
}
protected
function
getColorAndSizeInfo
(
$data
,
$current_size
,
$current_color
){
$all_color
=
[];
$all_size
=
[];
$color_2_size
=
[];
$size_2_color
=
[];
foreach
(
$data
as
$one
){
$color
=
$one
[
'color'
];
$size
=
$one
[
'size'
];
//echo $color;
//echo $size;
//echo '##';
$image
=
$one
[
'image'
];
$name
=
$one
[
'name'
];
$url_key
=
$one
[
'url_key'
];
if
(
$color
||
$size
){
$all_color
[
$color
]
=
[
'name'
=>
$name
,
'image'
=>
$image
,
'url_key'
=>
$url_key
,
];
$all_size
[
$size
]
=
[
'name'
=>
$name
,
'image'
=>
$image
,
'url_key'
=>
$url_key
,
];
//echo $size.'#'.$current_size;
//echo '<br/>';
if
(
$current_size
==
$size
){
$color_2_size
[
$color
]
=
[
'name'
=>
$name
,
'image'
=>
$image
,
'url_key'
=>
$url_key
,
];
}
if
(
$current_color
==
$color
){
$size_2_color
[
$size
]
=
[
'name'
=>
$name
,
'image'
=>
$image
,
'url_key'
=>
$url_key
,
];
}
}
}
return
[
$all_color
,
$all_size
,
$color_2_size
,
$size_2_color
];
}
protected
function
getSameSpuInfo
(){
//echo $this->_product['sku'];
//var_dump($this->_product);
$current_color
=
isset
(
$this
->
_product
[
'color'
])
?
$this
->
_product
[
'color'
]
:
''
;
$current_size
=
isset
(
$this
->
_product
[
'size'
])
?
$this
->
_product
[
'size'
]
:
''
;
if
(
!
$current_size
&&
!
$current_color
){
return
;
}
$data
=
$this
->
getSpuData
();
list
(
$all_color
,
$all_size
,
$color_2_size
,
$size_2_color
)
=
$this
->
getColorAndSizeInfo
(
$data
,
$current_size
,
$current_color
);
//var_dump($color_2_size);
//var_dump($data);
$str
=
''
;
$all_size
=
$this
->
sortSizeArr
(
$all_size
);
//var_dump($color_2_size);
//var_dump($all_color);
if
(
is_array
(
$all_color
)
&&
!
empty
(
$all_color
)){
$str
.
=
'<div class="chose_color">'
;
foreach
(
$all_color
as
$color
=>
$info
){
$main_img
=
isset
(
$info
[
'image'
][
'main'
][
'image'
])
?
$info
[
'image'
][
'main'
][
'image'
]
:
''
;
$url
=
''
;
$active
=
'class="active"'
;
if
(
isset
(
$color_2_size
[
$color
])){
$url
=
Yii
::
$service
->
url
->
getUrl
(
$color_2_size
[
$color
][
'url_key'
]);
}
else
{
$url
=
Yii
::
$service
->
url
->
getUrl
(
$info
[
'url_key'
]);
}
if
(
$color
==
$current_color
){
$active
=
'class="current"'
;
}
$str
.
=
'<a '
.
$active
.
' href="javascript:void(0)" rel="'
.
$url
.
'"><img src="'
.
Yii
::
$service
->
product
->
image
->
getResize
(
$main_img
,[
50
,
55
],
false
)
.
'"/></a>'
;
}
$str
.
=
'<div class="clear"></div>'
;
$str
.
=
'</div>'
;
}
if
(
is_array
(
$all_size
)
&&
!
empty
(
$all_size
)){
$str
.
=
'<div class="chose_size">'
;
foreach
(
$all_size
as
$size
=>
$info
){
$url
=
''
;
$active
=
'class="noactive"'
;
if
(
isset
(
$size_2_color
[
$size
])){
$url
=
Yii
::
$service
->
url
->
getUrl
(
$size_2_color
[
$size
][
'url_key'
]);
$active
=
'class="active"'
;
}
if
(
$size
==
$current_size
){
$active
=
'class="current"'
;
}
$str
.
=
'<a '
.
$active
.
' href="javascript:void(0)" rel="'
.
$url
.
'"><span>'
.
$size
.
'</span></a>'
;
}
$str
.
=
'<div class="clear"></div>'
;
$str
.
=
'</div>'
;
}
//echo $str;exit;
return
$str
;
}
protected
function
sortSizeArr
(
$data
){
# 对size排序一下
$size
=
[];
$attr_group
=
$this
->
_product
[
'attr_group'
];
$attrInfo
=
Yii
::
$service
->
product
->
getGroupAttrInfo
(
$attr_group
);
$size_arr
=
isset
(
$attrInfo
[
'size'
][
'display'
][
'data'
])
?
$attrInfo
[
'size'
][
'display'
][
'data'
]
:
''
;
$d_arr
=
[];
if
(
is_array
(
$size_arr
)
&&
!
empty
(
$size_arr
)){
foreach
(
$size_arr
as
$size
){
if
(
isset
(
$data
[
$size
])){
$d_arr
[
$size
]
=
$data
[
$size
];
}
}
return
$d_arr
;
}
return
$data
;
}
protected
function
getProductPriceInfo
(){
$price
=
$this
->
_product
[
'price'
];
...
...
@@ -73,6 +217,18 @@ class Index {
$this
->
_title
=
$this
->
_title
?
$this
->
_title
:
$name
;
Yii
::
$app
->
view
->
title
=
$this
->
_title
;
//$this->_where = $this->initWhere();
# 通过上面查询的属性组,得到属性组对应的属性列表
# 然后重新查询产品
$attr_group
=
$this
->
_product
[
'attr_group'
];
$attrInfo
=
Yii
::
$service
->
product
->
getGroupAttrInfo
(
$attr_group
);
if
(
is_array
(
$attrInfo
)
&&
!
empty
(
$attrInfo
)){
$attrs
=
array_keys
(
$attrInfo
);
\
fecshop\models\mongodb\Product
::
addCustomProductAttrs
(
$attrs
);
}
# 重新查询产品信息。
$product
=
Yii
::
$service
->
product
->
getByPrimaryKey
(
$primaryVal
);
$this
->
_product
=
$product
;
}
# 面包屑导航
...
...
app/appfront/theme/base/front/assets/css/style.css
浏览文件 @
4289b214
...
...
@@ -1790,8 +1790,25 @@ padding: 0 0 0 20px;
.tier_price_info
table
tr
{}
.tier_price_info
table
tr
td
{
height
:
25px
;
width
:
50px
;}
.chose_size
a
{
border
:
1px
solid
#ccc
;
padding
:
2px
10px
;
margin
:
2px
4px
;
;
}
.chose_color
{
margin
:
2px
0
20px
;}
.product_options
{
margin
:
40px
0
0
;}
.product_options
a
{
display
:
block
;
float
:
left
;
margin
:
0
5px
;
}
.product_options
a
.noactive
{
border
:
1px
dashed
#ccc
;
}
.product_options
a
.current
{
border
:
1px
solid
#cc0000
;
}
.product_options
a
.active
{
border
:
1px
solid
#ccc
;
}
app/appfront/theme/base/front/catalog/product/index.php
浏览文件 @
4289b214
...
...
@@ -18,6 +18,7 @@
</div>
<div
class=
"product_info"
>
<h1>
<?=
$name
;
?>
</h1>
<div>
<?=
$sku
;
?>
</div>
<div
class=
"price_info"
>
<?php
# 价格部分
$priceView
=
[
...
...
@@ -31,8 +32,27 @@
</div>
<div
style=
"height:300px;"
>
<div
class=
"product_options"
>
<?=
$options
;
?>
</div>
<script>
<?php
$this
->
beginBlock
(
'product_options'
)
?>
$
(
document
).
ready
(
function
(){
$
(
"
.product_options a
"
).
click
(
function
(){
$url
=
$
(
this
).
attr
(
"
rel
"
);
if
(
$url
){
window
.
location
.
href
=
$url
;
}
else
{
}
});
});
<?php
$this
->
endBlock
();
?>
</script>
<?php
$this
->
registerJs
(
$this
->
blocks
[
'product_options'
],
\
yii\web\View
::
POS_END
);
//将编写的js代码注册到页面底部 ?>
</
div
>
...
...
services/Product.php
浏览文件 @
4289b214
...
...
@@ -76,7 +76,19 @@ class Product extends Service
return
$this
->
_product
->
getByPrimaryKey
(
$primaryKey
);
}
/**
* 通过sku查询产品
*/
protected
function
actionGetBySku
(
$sku
){
return
$this
->
_product
->
getBySku
(
$sku
);
}
/**
* 通过spu查询产品
*/
protected
function
actionGetBySpu
(
$spu
){
return
$this
->
_product
->
getBySpu
(
$spu
);
}
/**
* @property $filter|Array
...
...
services/product/ProductMongodb.php
浏览文件 @
4289b214
...
...
@@ -30,6 +30,47 @@ class ProductMongodb implements ProductInterface
return
new
Product
;
}
}
/**
* @property $sku|Array
* @property $returnArr|boolean 返回的数据是否是数组格式,如果设置为
* false,则返回的是对象数据
* @return Array or Object
* 通过sku 获取产品,一个产品
*/
public
function
getBySku
(
$sku
,
$returnArr
=
true
){
if
(
$sku
){
if
(
$returnArr
){
return
Product
::
find
()
->
asArray
()
->
where
([
'sku'
=>
$sku
])
->
one
()
;
}
else
{
return
Product
::
findOne
([
'sku'
=>
$sku
]);
}
}
}
/**
* @property $spu|Array
* @property $returnArr|boolean 返回的数据是否是数组格式,如果设置为
* false,则返回的是对象数据
* @return Array or Object
* 通过spu 获取产品数组
*/
public
function
getBySpu
(
$spu
,
$returnArr
=
true
){
if
(
$spu
){
if
(
$returnArr
){
return
Product
::
find
()
->
asArray
()
->
where
([
'spu'
=>
$spu
])
->
all
();
}
else
{
return
Product
::
find
()
->
where
([
'spu'
=>
$spu
])
->
all
();
}
}
}
/*
* example filter:
* [
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录