Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
bc54cb26
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 搜索 >>
提交
bc54cb26
编写于
2月 25, 2018
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
appfront: 购物车勾选产品切换active状态
上级
ebd0ec87
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
218 addition
and
5 deletion
+218
-5
app/appfront/modules/Checkout/controllers/CartController.php
app/appfront/modules/Checkout/controllers/CartController.php
+50
-0
app/appfront/theme/base/front/checkout/cart/index.php
app/appfront/theme/base/front/checkout/cart/index.php
+76
-5
services/Cart.php
services/Cart.php
+28
-0
services/cart/QuoteItem.php
services/cart/QuoteItem.php
+64
-0
未找到文件。
app/appfront/modules/Checkout/controllers/CartController.php
浏览文件 @
bc54cb26
...
...
@@ -221,4 +221,54 @@ class CartController extends AppfrontController
$innerTransaction
->
rollBack
();
}
}
public
function
actionSelectone
()
{
$item_id
=
Yii
::
$app
->
request
->
get
(
'item_id'
);
$checked
=
Yii
::
$app
->
request
->
get
(
'checked'
);
$checked
=
$checked
==
1
?
true
:
false
;
$innerTransaction
=
Yii
::
$app
->
db
->
beginTransaction
();
try
{
$status
=
Yii
::
$service
->
cart
->
selectOneItem
(
$item_id
,
$checked
);
if
(
$status
)
{
echo
json_encode
([
'status'
=>
'success'
,
]);
$innerTransaction
->
commit
();
}
else
{
echo
json_encode
([
'status'
=>
'fail'
,
'content'
=>
Yii
::
$service
->
helper
->
errors
->
get
(
','
)
]);
$innerTransaction
->
rollBack
();
}
}
catch
(
Exception
$e
)
{
$innerTransaction
->
rollBack
();
}
}
public
function
actionSelectall
()
{
$checked
=
Yii
::
$app
->
request
->
get
(
'checked'
);
$checked
=
$checked
==
1
?
true
:
false
;
$innerTransaction
=
Yii
::
$app
->
db
->
beginTransaction
();
try
{
$status
=
Yii
::
$service
->
cart
->
selectAllItem
(
$checked
);
if
(
$status
)
{
echo
json_encode
([
'status'
=>
'success'
,
]);
$innerTransaction
->
commit
();
}
else
{
echo
json_encode
([
'status'
=>
'fail'
,
'content'
=>
Yii
::
$service
->
helper
->
errors
->
get
(
','
)
]);
$innerTransaction
->
rollBack
();
}
}
catch
(
Exception
$e
)
{
$innerTransaction
->
rollBack
();
}
}
}
app/appfront/theme/base/front/checkout/cart/index.php
浏览文件 @
bc54cb26
...
...
@@ -68,7 +68,7 @@ use fecshop\app\appfront\helper\Format;
<tr
class=
"first last odd"
>
<td>
<input
<?=
(
$product_one
[
'active'
]
==
Yii
::
$service
->
cart
->
quoteItem
->
activeStatus
)
?
'checked="checked"'
:
''
?>
type=
"checkbox"
name=
"cart_select_item"
class=
"cart_select cart_select_item"
>
<input
rel=
"
<?=
$product_one
[
'item_id'
];
?>
"
<?=
(
$product_one
[
'active'
]
==
Yii
::
$service
->
cart
->
quoteItem
->
activeStatus
)
?
'checked="checked"'
:
''
?>
type=
"checkbox"
name=
"cart_select_item"
class=
"cart_select cart_select_item"
>
</td>
...
...
@@ -285,8 +285,31 @@ use fecshop\app\appfront\helper\Format;
// add to cart js
<?php
$this
->
beginBlock
(
'changeCartInfo'
)
?>
$
(
document
).
ready
(
function
(){
currentUrl
=
"
<?=
Yii
::
$service
->
url
->
getUrl
(
'checkout/cart'
)
?>
"
updateCartInfoUrl
=
"
<?=
Yii
::
$service
->
url
->
getUrl
(
'checkout/cart/updateinfo'
)
?>
"
// set select all checkbox
selectall
=
"
<?=
Yii
::
$app
->
request
->
get
(
'selectall'
)
?>
"
;
selectAllChecked
=
false
;
if
(
selectall
==
1
)
{
selectAllChecked
=
true
;
}
else
{
item_select_all
=
1
;
$
(
"
.cart_select_item
"
).
each
(
function
(){
checked
=
$
(
this
).
is
(
'
:checked
'
);
if
(
checked
==
false
)
{
item_select_all
=
0
;
}
});
if
(
item_select_all
==
1
)
{
selectAllChecked
=
true
;
}
}
$
(
"
.cart_select_all
"
).
attr
(
"
checked
"
,
selectAllChecked
);
currentUrl
=
"
<?=
Yii
::
$service
->
url
->
getUrl
(
'checkout/cart'
)
?>
"
;
updateCartInfoUrl
=
"
<?=
Yii
::
$service
->
url
->
getUrl
(
'checkout/cart/updateinfo'
)
?>
"
;
selectOneProductUrl
=
"
<?=
Yii
::
$service
->
url
->
getUrl
(
'checkout/cart/selectone'
)
?>
"
;
selectAllProductUrl
=
"
<?=
Yii
::
$service
->
url
->
getUrl
(
'checkout/cart/selectall'
)
?>
"
;
$
(
"
.cartqtydown
"
).
click
(
function
(){
$item_id
=
$
(
this
).
attr
(
"
rel
"
);
num
=
$
(
this
).
attr
(
"
num
"
);
...
...
@@ -334,8 +357,8 @@ $(document).ready(function(){
});
});
$
(
"
.btn-remove
"
).
click
(
function
(){
$
(
"
.btn-remove
"
).
click
(
function
(){
$item_id
=
$
(
this
).
attr
(
"
rel
"
);
$data
=
{
...
...
@@ -359,6 +382,54 @@ $(document).ready(function(){
});
$
(
"
.cart_select_item
"
).
click
(
function
(){
$item_id
=
$
(
this
).
attr
(
"
rel
"
);
checked
=
$
(
this
).
is
(
'
:checked
'
);
checked
=
checked
?
1
:
0
;
$data
=
{
item_id
:
$item_id
,
checked
:
checked
};
jQuery
.
ajax
({
async
:
true
,
timeout
:
6000
,
dataType
:
'
json
'
,
type
:
'
get
'
,
data
:
$data
,
url
:
selectOneProductUrl
,
success
:
function
(
data
,
textStatus
){
if
(
data
.
status
==
'
success
'
){
window
.
location
.
href
=
currentUrl
;
}
},
error
:
function
(
XMLHttpRequest
,
textStatus
,
errorThrown
){}
});
});
$
(
"
.cart_select_all
"
).
click
(
function
(){
checked
=
$
(
this
).
is
(
'
:checked
'
);
checked
=
checked
?
1
:
0
;
$data
=
{
checked
:
checked
};
selectCurrentUrl
=
currentUrl
+
'
?selectall=
'
+
checked
;
jQuery
.
ajax
({
async
:
true
,
timeout
:
6000
,
dataType
:
'
json
'
,
type
:
'
get
'
,
data
:
$data
,
url
:
selectAllProductUrl
,
success
:
function
(
data
,
textStatus
){
if
(
data
.
status
==
'
success
'
){
window
.
location
.
href
=
selectCurrentUrl
;
}
},
error
:
function
(
XMLHttpRequest
,
textStatus
,
errorThrown
){}
});
});
$
(
"
.add_coupon_submit
"
).
click
(
function
(){
coupon_code
=
$
(
"
#coupon_code
"
).
val
();
coupon_type
=
$
(
"
.couponType
"
).
val
();
...
...
services/Cart.php
浏览文件 @
bc54cb26
...
...
@@ -141,6 +141,34 @@ class Cart extends Service
return
true
;
}
/**
* @property $item_id | Int 购物车产品表的id字段
* 通过item id 将购物车中的某个产品的个数加一
*/
protected
function
actionSelectOneItem
(
$item_id
,
$checked
)
{
$status
=
Yii
::
$service
->
cart
->
quoteItem
->
selectOneItem
(
$item_id
,
$checked
);
if
(
!
$status
)
{
return
false
;
}
Yii
::
$service
->
cart
->
quote
->
computeCartInfo
();
return
true
;
}
/**
* @property $item_id | Int 购物车产品表的id字段
* 通过item id 将购物车中的某个产品的个数加一
*/
protected
function
actionSelectAllItem
(
$checked
)
{
$status
=
Yii
::
$service
->
cart
->
quoteItem
->
selectAllItem
(
$checked
);
if
(
!
$status
)
{
return
false
;
}
Yii
::
$service
->
cart
->
quote
->
computeCartInfo
();
return
true
;
}
/**
* 购物车合并:对应的是用户登录前后购物车的合并
...
...
services/cart/QuoteItem.php
浏览文件 @
bc54cb26
...
...
@@ -369,6 +369,70 @@ class QuoteItem extends Service
return
false
;
}
/**
* @property $item_id | Int , quoteItem表的id
* @return bool
* 将这个item_id对应的产品个数+1.
*/
public
function
selectOneItem
(
$item_id
,
$checked
)
{
$cart_id
=
Yii
::
$service
->
cart
->
quote
->
getCartId
();
if
(
$cart_id
)
{
$one
=
$this
->
_itemModel
->
find
()
->
where
([
'cart_id'
=>
$cart_id
,
'item_id'
=>
$item_id
,
])
->
one
();
$product_id
=
$one
[
'product_id'
];
if
(
$one
[
'item_id'
]
&&
$product_id
)
{
//$product = Yii::$service->product->getByPrimaryKey($product_id);
//$changeQty = Yii::$service->cart->getCartQty($product['package_number'], 1);
//$one['qty'] = $one['qty'] + $changeQty;
if
(
$checked
==
true
)
{
$one
->
active
=
$this
->
activeStatus
;
}
else
{
$one
->
active
=
$this
->
noActiveStatus
;
}
$one
->
save
();
// 重新计算购物车的数量
Yii
::
$service
->
cart
->
quote
->
computeCartInfo
();
return
true
;
}
}
return
false
;
}
/**
* @property $item_id | Int , quoteItem表的id
* @return bool
* 将这个item_id对应的产品个数+1.
*/
public
function
selectAllItem
(
$checked
)
{
$cart_id
=
Yii
::
$service
->
cart
->
quote
->
getCartId
();
if
(
$cart_id
)
{
$active
=
$this
->
noActiveStatus
;
if
(
$checked
==
true
)
{
$active
=
$this
->
activeStatus
;
}
$updateCount
=
$this
->
_itemModel
->
updateAll
(
[
'active'
=>
$active
],
[
'cart_id'
=>
$cart_id
]
);
if
(
$updateCount
>
0
)
{
Yii
::
$service
->
cart
->
quote
->
computeCartInfo
();
}
return
true
;
}
return
false
;
}
/**
* @property $cart_id | int 购物车id
* 删除购物车中的所有的active产品。对于noActive产品保留
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录