Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
b79b5098
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
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,体验更适合开发者的 AI 搜索 >>
提交
b79b5098
编写于
11月 04, 2016
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
产品的custom_option在前端页面的展示
上级
8edc1ed7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
327 addition
and
33 deletion
+327
-33
app/appfront/modules/Catalog/block/product/CustomOption.php
app/appfront/modules/Catalog/block/product/CustomOption.php
+109
-0
app/appfront/modules/Catalog/block/product/Index.php
app/appfront/modules/Catalog/block/product/Index.php
+1
-0
app/appfront/theme/base/front/assets/css/style.css
app/appfront/theme/base/front/assets/css/style.css
+19
-7
app/appfront/theme/base/front/catalog/product/index.php
app/appfront/theme/base/front/catalog/product/index.php
+4
-3
app/appfront/theme/base/front/catalog/product/index/custom_option.php
.../theme/base/front/catalog/product/index/custom_option.php
+194
-23
未找到文件。
app/appfront/modules/Catalog/block/product/CustomOption.php
0 → 100644
浏览文件 @
b79b5098
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\app\appfront\modules\Catalog\block\product
;
use
Yii
;
use
fec\helpers\CModule
;
use
fec\helpers\CRequest
;
use
yii\base\InvalidValueException
;
use
fecshop\app\appfront\modules\Catalog\helpers\Review
as
ReviewHelper
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
CustomOption
{
public
$custom_option
;
public
$attr_group
;
protected
$_custom_option_arr
;
public
function
getLastData
(){
$items
=
$this
->
getAllItems
();
//var_dump($items);exit;
return
[
'items'
=>
$items
,
'custom_option_arr'
=>
json_encode
(
$this
->
_custom_option_arr
),
];
}
public
function
getAllItems
(){
$custom_option_attr_info
=
Yii
::
$service
->
product
->
getCustomOptionAttrInfo
(
$this
->
attr_group
);
##########
$my_arr
=
[];
$arr
=
[];
##custom_optionһ
$img_attr
=
''
;
foreach
(
$custom_option_attr_info
as
$attr
=>
$info
){
if
(
isset
(
$info
[
'showAsImg'
])
&&
$info
[
'showAsImg'
]){
$img_attr
=
$attr
;
break
;
}
}
$img_arr
=
[];
if
(
is_array
(
$this
->
custom_option
)
&&
(
!
empty
(
$this
->
custom_option
))){
foreach
(
$this
->
custom_option
as
$option
){
$i
=
0
;
$this
->
_custom_option_arr
[]
=
$option
;
if
(
isset
(
$option
[
$img_attr
])){
$val
=
$option
[
$img_attr
];
$img_arr
[
$val
]
=
$option
[
'image'
];
}
foreach
(
$option
as
$k
=>
$v
){
$my_arr
[
$k
][]
=
$v
;
}
}
}
if
(
is_array
(
$custom_option_attr_info
)
&&
!
empty
(
$custom_option_attr_info
)){
foreach
(
$custom_option_attr_info
as
$attr
=>
$info
){
if
(
isset
(
$info
[
'display'
][
'type'
])
&&
(
$info
[
'display'
][
'type'
]
==
'select'
)){
if
(
isset
(
$info
[
'display'
][
'data'
])
&&
is_array
(
$info
[
'display'
][
'data'
])){
foreach
(
$info
[
'display'
][
'data'
]
as
$key
=>
$val
){
if
(
is_array
(
$my_arr
[
$attr
])
&&
in_array
(
$key
,
$my_arr
[
$attr
])){
$t_arr
=
[
'key'
=>
$key
,
'val'
=>
$val
,
];
$t_arr
[
'require'
]
=
isset
(
$info
[
'require'
])
?
$info
[
'require'
]
:
0
;
if
(
isset
(
$info
[
'showAsImg'
])
&&
$info
[
'showAsImg'
]){
if
(
isset
(
$img_arr
[
$key
])){
$t_arr
[
'image'
]
=
$img_arr
[
$key
];
}
}
$arr
[
$attr
][]
=
$t_arr
;
}
}
}
}
}
}
return
$arr
;
}
}
app/appfront/modules/Catalog/block/product/Index.php
浏览文件 @
b79b5098
...
...
@@ -36,6 +36,7 @@ class Index {
'image'
=>
$this
->
_product
[
'image'
],
'sku'
=>
$this
->
_product
[
'sku'
],
'spu'
=>
$this
->
_product
[
'spu'
],
'attr_group'
=>
$this
->
_product
[
'attr_group'
],
'review_count'
=>
$review_count
,
'reviw_rate_star_average'
=>
$reviw_rate_star_average
,
'price_info'
=>
$this
->
getProductPriceInfo
(),
...
...
app/appfront/theme/base/front/assets/css/style.css
浏览文件 @
b79b5098
...
...
@@ -1803,9 +1803,7 @@ border: solid 1px #adadad;
.product_options
a
.noactive
{
border
:
1px
dashed
#ccc
;
}
.product_options
a
.current
{
border
:
1px
solid
#cc0000
;
}
.product_options
a
.active
{
border
:
1px
solid
#ccc
;
...
...
@@ -1874,8 +1872,7 @@ border: solid 1px #adadad;
.product_qty
{
margin
:
20px
0
0
}
.pg
.rg.chose_color
{
width
:
auto
;}
.pg
.rg.chose_size
{
width
:
auto
;}
.product_options
.pg
.rg
{
width
:
auto
;}
.product_options
.label
{
line-height
:
62px
;}
...
...
@@ -2300,9 +2297,24 @@ a.next_images {
.product_options
a
.no_active
{
border
:
1px
dashed
#ccc
;
cursor
:
not-allowed
;
}
.product_options
a
.noimgshow
{
font-size
:
11px
;
height
:
35px
;
line-height
:
35px
;
width
:
35px
;
}
.product_options
a
.active
{
border
:
1px
solid
#ccc
;
}
.product_options
a
.current
{
border
:
1px
solid
#cc0000
;
}
app/appfront/theme/base/front/catalog/product/index.php
浏览文件 @
b79b5098
...
...
@@ -46,11 +46,12 @@
<div
class=
"product_custom_options"
>
<?php
# custom options部分
$optionsView
=
[
'view'
=>
'catalog/product/index/custom_option.php'
];
$optionsParam
=
[
'class'
=>
'fecshop\app\appfront\modules\Catalog\block\product\CustomOption'
,
'view'
=>
'catalog/product/index/custom_option.php'
,
'custom_option'
=>
$custom_option
,
'attr_group'
=>
$attr_group
,
];
?>
<?=
Yii
::
$service
->
page
->
widget
->
render
(
$optionsView
,
$optionsParam
);
?>
...
...
app/appfront/theme/base/front/catalog/product/index/custom_option.php
浏览文件 @
b79b5098
<?php
$custom_option
=
$parentThis
[
'custom_option'
];
?>
<?php
if
(
is_array
(
$custom_option
)
&&
!
empty
(
$custom_option
)){
?>
<?php
$custom_option
=
\
fec\helpers\CFunc
::
array_sort
(
$custom_option
,
'sort_order'
,
'asc'
);
?>
<?php
foreach
(
$custom_option
as
$one
){
?>
<?php
$option_title
=
$one
[
'title'
];
?>
<?php
$is_require
=
$one
[
'is_require'
];
?>
<?php
$data
=
$one
[
'data'
];
?>
<?php
if
(
is_array
(
$data
)
&&
!
empty
(
$data
)){
?>
<div
class=
"one_option"
>
<div
class=
"one_option_title"
>
<?=
$option_title
?>
:
</div>
<select
class=
"custom_option
<?=
$title
?>
<?=
$is_require
?
'required'
:
''
?>
"
name=
"custom_option[
<?=
$title
?>
]"
>
<?php
$data
=
\
fec\helpers\CFunc
::
array_sort
(
$data
,
'sort_order'
,
'asc'
);
?>
<?php
foreach
(
$data
as
$one
){
?>
<?php
$title
=
$one
[
'title'
];
?>
<?php
$price
=
$one
[
'price'
];
?>
<?php
$val
=
Yii
::
$service
->
store
->
getStoreAttrVal
(
$title
,
'title'
);
?>
<option
value=
"
<?=
$val
?>
"
>
<?=
$val
?>
</option>
<?php
}
?>
</select>
<div
class=
"clear"
></div>
</div>
<?php
}
?>
<?php
//var_dump($items);exit; ?>
<?
php
if
(
is_array
(
$items
)
&&
!
empty
(
$items
)){
?>
<div
class=
"product_options"
>
<?php
foreach
(
$items
as
$attr
=>
$info
){
?>
<div
class=
"pg"
>
<div
class=
"label"
>
<?=
$attr
?>
:
</div>
<div
class=
"chose_
<?=
$attr
?>
rg
<?=
$attr
?>
"
>
<ul
class=
"no_chosen_ul"
attr=
"
<?=
$attr
?>
"
>
<?php
if
(
is_array
(
$info
)
&&
!
empty
(
$info
)){
?>
<?php
foreach
(
$info
as
$one
){
?>
<?php
$val
=
$one
[
'val'
];
?>
<?php
$key
=
$one
[
'key'
];
?>
<?php
$image
=
$one
[
'image'
];
?>
<?php
$require
=
$one
[
'require'
];
?>
<?php
if
(
$image
){
?>
<li>
<a
attr=
"
<?=
$attr
?>
"
class=
"imgshow active"
value=
"
<?=
$key
?>
"
><img
src=
"
<?=
Yii
::
$service
->
product
->
image
->
getResize
(
$image
,[
50
,
55
],
false
)
?>
"
/></a>
<b></b>
</li>
<?php
}
else
{
?>
<li>
<a
attr=
"
<?=
$attr
?>
"
class=
"noimgshow active"
value=
"
<?=
$key
?>
"
>
<?=
$val
?>
</a>
<b></b>
</li>
<?php
}
?>
<?php
}
?>
<?php
}
?>
</ul>
</div>
<div
class=
"clear"
></div>
</div>
<?php
}
?>
<?php
}
?>
\ No newline at end of file
</div>
<?php
}
?>
<script>
</script>
<script>
<?php
$this
->
beginBlock
(
'product_custom_option'
)
?>
$
(
document
).
ready
(
function
(){
custom_option_arr
=
<?=
$custom_option_arr
?>
;
//for(x in custom_option_arr){
// alert(custom_option_arr[x]['sku']);
//}
$
(
"
.product_custom_options ul li a
"
).
click
(
function
(){
if
(
!
$
(
this
).
hasClass
(
'
no_active
'
)){
$chosen_custom_option_arr
=
[];
$
(
this
).
parent
().
parent
().
find
(
"
a
"
).
removeClass
(
"
current
"
);
$
(
this
).
parent
().
parent
().
find
(
"
li
"
).
removeClass
(
"
current
"
);
$
(
this
).
addClass
(
"
current
"
);
$
(
this
).
parent
().
addClass
(
"
current
"
);
$
(
this
).
parent
().
parent
().
removeClass
(
"
no_chosen_ul
"
);
$
(
this
).
parent
().
parent
().
addClass
(
"
chosen_ul
"
);
$chosen_attr
=
[];
// 选择后的部分
$c_arr
=
[];
$c_chosen_custom_option_arr
=
new
Object
();;
$
(
"
.product_custom_options ul li a.current
"
).
each
(
function
(){
attr
=
$
(
this
).
attr
(
'
attr
'
);
val
=
$
(
this
).
attr
(
'
value
'
);
for
(
x
in
custom_option_arr
){
one
=
custom_option_arr
[
x
];
i
=
1
;
$
(
"
.product_custom_options ul li a.current
"
).
each
(
function
(){
attr2
=
$
(
this
).
attr
(
'
attr
'
);
val2
=
$
(
this
).
attr
(
'
value
'
);
//alert(attr+"###"+val);
if
((
attr
!=
attr2
)
&&
(
one
[
attr2
]
!=
val2
)){
i
=
0
;
}
});
if
(
i
){
if
(
$c_chosen_custom_option_arr
[
attr
]
==
undefined
){
$c_chosen_custom_option_arr
[
attr
]
=
[];
}
$c_chosen_custom_option_arr
[
attr
].
push
(
one
);
}
}
});
// 每一个属性对应的允许的值,的出来,譬如 color 允许 red white等
c_my_arr
=
new
Object
();
for
(
attr
in
$c_chosen_custom_option_arr
){
//alert(attr);
if
(
c_my_arr
[
attr
]
==
undefined
){
c_my_arr
[
attr
]
=
new
Object
();;
}
arr
=
$c_chosen_custom_option_arr
[
attr
];
for
(
x
in
arr
){
one
=
arr
[
x
];
for
(
y
in
one
){
//alert(one[y]);
if
(
c_my_arr
[
attr
][
y
]
==
undefined
){
c_my_arr
[
attr
][
y
]
=
[];
}
//alert(attr+"##"+y);
c_my_arr
[
attr
][
y
].
push
(
one
[
y
]);
}
}
}
$
(
"
.product_custom_options ul.chosen_ul
"
).
each
(
function
(){
attr
=
$
(
this
).
attr
(
'
attr
'
);
$
(
this
).
find
(
"
li a
"
).
each
(
function
(){
val
=
$
(
this
).
attr
(
'
value
'
);
//alert(val);
//alert(my_arr[attr]);
if
(
$
.
inArray
(
val
,
c_my_arr
[
attr
][
attr
])
>
-
1
){
$
(
this
).
removeClass
(
'
no_active
'
);
$
(
this
).
addClass
(
'
active
'
);
}
else
{
//alert(val);
//alert(222);
$
(
this
).
addClass
(
'
no_active
'
);
$
(
this
).
removeClass
(
'
active
'
);
}
});
});
///////
for
(
x
in
custom_option_arr
){
one
=
custom_option_arr
[
x
];
i
=
1
;
$
(
"
.product_custom_options ul li a.current
"
).
each
(
function
(){
attr
=
$
(
this
).
attr
(
'
attr
'
);
val
=
$
(
this
).
attr
(
'
value
'
);
//alert(attr+"###"+val);
if
(
one
[
attr
]
!=
val
){
i
=
0
;
}
});
if
(
i
){
$chosen_custom_option_arr
.
push
(
one
);
}
}
//alert(1);
my_arr
=
new
Object
();
for
(
x
in
$chosen_custom_option_arr
){
one
=
$chosen_custom_option_arr
[
x
];
for
(
y
in
one
){
//alert(one[y]+"###"+y);
if
(
my_arr
[
y
]
==
undefined
){
my_arr
[
y
]
=
[];
}
//alert(y+"__"+one[y]);
my_arr
[
y
].
push
(
one
[
y
]);
}
}
$
(
"
.product_custom_options ul.no_chosen_ul
"
).
each
(
function
(){
attr
=
$
(
this
).
attr
(
'
attr
'
);
$
(
this
).
find
(
"
li a
"
).
each
(
function
(){
val
=
$
(
this
).
attr
(
'
value
'
);
//alert(val);
//alert(my_arr[attr]);
if
(
$
.
inArray
(
val
,
my_arr
[
attr
])
>
-
1
){
$
(
this
).
removeClass
(
'
no_active
'
);
$
(
this
).
addClass
(
'
active
'
);
}
else
{
//alert(val);
//alert(222);
$
(
this
).
addClass
(
'
no_active
'
);
$
(
this
).
removeClass
(
'
active
'
);
}
});
});
}
});
});
<?php
$this
->
endBlock
();
?>
</script>
<?php
$this
->
registerJs
(
$this
->
blocks
[
'product_custom_option'
],
\
yii\web\View
::
POS_END
);
//将编写的js代码注册到页面底部 ?>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录