Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
cede4043
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 搜索 >>
提交
cede4043
编写于
3月 03, 2019
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
购物车,增加产品的active个数和所有购物车产品总数数据
上级
bcf136ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
10 deletion
+43
-10
services/cart/Quote.php
services/cart/Quote.php
+17
-9
services/cart/QuoteItem.php
services/cart/QuoteItem.php
+26
-1
未找到文件。
services/cart/Quote.php
浏览文件 @
cede4043
...
...
@@ -26,6 +26,9 @@ use Yii;
*/
class
Quote
extends
Service
{
/**
* 购物车的个数计算,是否仅仅计算active状态的产品个数总和,如果设置false,则将购物车中所有的产品个数累加。
*/
const
SESSION_CART_ID
=
'current_session_cart_id'
;
protected
$_cart_id
;
...
...
@@ -203,17 +206,20 @@ class Quote extends Service
/**
* @param $item_qty | Int
* 当$item_qty为null时,从cart items表中查询产品总数。
* 当$item_qty 不等于null时,代表已经知道购物车中产品的个数,不需要去cart_item表中查询,譬如清空购物车操作,直接就知道产品个数肯定为零。
* 当$
active_
item_qty为null时,从cart items表中查询产品总数。
* 当$item_qty 不等于null时,代表已经知道购物车中
active
产品的个数,不需要去cart_item表中查询,譬如清空购物车操作,直接就知道产品个数肯定为零。
* 当购物车的产品变动后,会调用该函数,更新cart表的产品总数
*/
public
function
computeCartInfo
(
$item_qty
=
null
)
public
function
computeCartInfo
(
$
active_
item_qty
=
null
)
{
if
(
$item_qty
===
null
)
{
$item_qty
=
Yii
::
$service
->
cart
->
quoteItem
->
getItemQty
();
$items_all_count
=
0
;
if
(
$active_item_qty
===
null
)
{
$active_item_qty
=
Yii
::
$service
->
cart
->
quoteItem
->
getActiveItemQty
();
}
$items_all_count
=
Yii
::
$service
->
cart
->
quoteItem
->
getItemAllQty
();
$cart
=
$this
->
getCart
();
$cart
->
items_count
=
$item_qty
;
$cart
->
items_all_count
=
$items_all_count
;
$cart
->
items_count
=
$active_item_qty
;
$cart
->
save
();
return
true
;
...
...
@@ -360,9 +366,11 @@ class Quote extends Service
return
false
;
}
$cart
=
$this
->
getCart
();
$items_qty
=
$cart
[
'items_count'
];
if
(
$items_qty
<=
0
)
{
// 购物车中所有的产品个数
$items_all_count
=
$cart
[
'items_all_count'
];
// 购物车中active状态的产品个数
$items_count
=
$cart
[
'items_count'
];
if
(
$items_count
<=
0
&&
$items_all_count
<=
0
)
{
return
false
;
}
$coupon_code
=
$cart
[
'coupon_code'
];
...
...
services/cart/QuoteItem.php
浏览文件 @
cede4043
...
...
@@ -175,7 +175,7 @@ class QuoteItem extends Service
* 在购物车中产品有变动后,使用这个函数得到产品总数,更新购物车中
* 的产品总数。
*/
public
function
getItemQty
()
public
function
getItem
All
Qty
()
{
$cart_id
=
Yii
::
$service
->
cart
->
quote
->
getCartId
();
$item_qty
=
0
;
...
...
@@ -192,6 +192,31 @@ class QuoteItem extends Service
return
$item_qty
;
}
/**
* 通过quoteItem表,计算得到所有产品的总数
* 得到购物车中产品的总数,不要使用这个函数,这个函数的作用:
* 在购物车中产品有变动后,使用这个函数得到产品总数,更新购物车中
* 的产品总数。
*/
public
function
getActiveItemQty
()
{
$cart_id
=
Yii
::
$service
->
cart
->
quote
->
getCartId
();
$item_qty
=
0
;
if
(
$cart_id
)
{
$data
=
$this
->
_itemModel
->
find
()
->
asArray
()
->
where
([
'cart_id'
=>
$cart_id
,
'active'
=>
$this
->
activeStatus
,
])
->
all
();
if
(
is_array
(
$data
)
&&
!
empty
(
$data
))
{
foreach
(
$data
as
$one
)
{
$item_qty
+=
$one
[
'qty'
];
}
}
}
return
$item_qty
;
}
/**
* @param $activeProduct | boolean , 是否只要active的产品
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录