Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
64637acb
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 搜索 >>
提交
64637acb
编写于
1月 15, 2018
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
shipping method部分加入国家,重量,以及csv表格里面的限制,不可用的shipping method不显示
上级
f84e6e27
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
315 addition
and
194 deletion
+315
-194
app/appfront/modules/Checkout/block/onepage/Index.php
app/appfront/modules/Checkout/block/onepage/Index.php
+23
-32
app/appfront/modules/Checkout/block/onepage/Placeorder.php
app/appfront/modules/Checkout/block/onepage/Placeorder.php
+5
-5
services/Shipping.php
services/Shipping.php
+276
-144
services/cart/Quote.php
services/cart/Quote.php
+11
-13
未找到文件。
app/appfront/modules/Checkout/block/onepage/Index.php
浏览文件 @
64637acb
...
...
@@ -31,9 +31,7 @@ class Index
public
function
getLastData
()
{
//echo 1;exit;
$cartInfo
=
Yii
::
$service
->
cart
->
getCartInfo
();
if
(
!
isset
(
$cartInfo
[
'products'
])
||
!
is_array
(
$cartInfo
[
'products'
])
||
empty
(
$cartInfo
[
'products'
]))
{
return
Yii
::
$service
->
url
->
redirectByUrlKey
(
'checkout/cart'
);
}
...
...
@@ -333,37 +331,33 @@ class Index
/**
* @property $current_shipping_method | String 当前选择的货运方式
* @return Array,数据格式为:
*
[
*
'method'=> $method,
*
'label' => $label,
*
'name' => $name,
*
'cost' => $symbol.$currentCurrencyCost,
*
'check' => $check,
*
'shipping_i' => $shipping_i,
*
]
*
根据选择的货运方式,得到费用等信息
。
* [
* 'method'=> $method,
* 'label' => $label,
* 'name' => $name,
* 'cost' => $symbol.$currentCurrencyCost,
* 'check' => $check,
* 'shipping_i' => $shipping_i,
* ]
*
得到所有的,有效shipping method数组
。
*/
public
function
getShippings
(
$custom_shipping_method
=
''
)
{
$country
=
$this
->
_country
;
if
(
!
$this
->
_state
)
{
$region
=
'
*
'
;
$region
=
''
;
}
else
{
$region
=
$this
->
_state
;
}
$cartProductInfo
=
Yii
::
$service
->
cart
->
quoteItem
->
getCartProductInfo
();
//echo $country ;
$product_weight
=
$cartProductInfo
[
'product_weight'
];
// 传递当前的货运方式,这个需要从cart中选取,
// 如果cart中没有shipping_method,那么该值为空
//var_dump($this->_cart_info);
$cartShippingMethod
=
$this
->
_cart_info
[
'shipping_method'
];
//echo "$custom_shipping_method,$cartShippingMethod";
$current_shipping_method
=
Yii
::
$service
->
shipping
->
getCurrentShippingMethod
(
$custom_shipping_method
,
$cartShippingMethod
);
// 当前的货运方式
$current_shipping_method
=
Yii
::
$service
->
shipping
->
getCurrentShippingMethod
(
$custom_shipping_method
,
$cartShippingMethod
,
$country
,
$region
,
$product_weight
);
$this
->
_shipping_method
=
$current_shipping_method
;
// 得到所有,有效的shipping method
$shippingArr
=
$this
->
getShippingArr
(
$product_weight
,
$current_shipping_method
,
$country
,
$region
);
return
$shippingArr
;
}
...
...
@@ -420,22 +414,18 @@ class Index
* @property $country | String 国家
* @return array , 通过上面的三个参数,得到各个运费方式对应的运费等信息。
*/
public
function
getShippingArr
(
$weight
,
$current_shipping_method
,
$country
,
$region
=
'*'
)
public
function
getShippingArr
(
$weight
,
$current_shipping_method
,
$country
,
$region
)
{
$a
llshipping
=
Yii
::
$service
->
shipping
->
getActiveShippingMethods
(
$country
,
$region
);
$a
vailable_shipping
=
Yii
::
$service
->
shipping
->
getAvailableShippingMethods
(
$country
,
$region
,
$weight
);
$sr
=
''
;
$shipping_i
=
1
;
$arr
=
[];
if
(
is_array
(
$a
llshipping
)
&&
!
empty
(
$all
shipping
))
{
foreach
(
$a
ll
shipping
as
$method
=>
$shipping
)
{
if
(
is_array
(
$a
vailable_shipping
)
&&
!
empty
(
$available_
shipping
))
{
foreach
(
$a
vailable_
shipping
as
$method
=>
$shipping
)
{
$label
=
$shipping
[
'label'
];
$name
=
$shipping
[
'name'
];
// 得到运费的金额
//echo "$method,$weight,$country,$region";
// getShippingCostWithSymbols
$cost
=
Yii
::
$service
->
shipping
->
getShippingCost
(
$method
,
$weight
,
$country
,
$region
);
//var_dump($cost);
//echo "##"
$cost
=
Yii
::
$service
->
shipping
->
getShippingCost
(
$method
,
$shipping
,
$weight
,
$country
,
$region
);
$currentCurrencyCost
=
$cost
[
'currCost'
];
$symbol
=
Yii
::
$service
->
page
->
currency
->
getCurrentSymbol
();
if
(
$current_shipping_method
==
$method
)
{
...
...
@@ -456,7 +446,6 @@ class Index
$shipping_i
++
;
}
}
return
$arr
;
}
...
...
@@ -531,9 +520,11 @@ class Index
*/
$quoteItem
=
Yii
::
$service
->
cart
->
quoteItem
->
getCartProductInfo
();
$product_weight
=
$quoteItem
[
'product_weight'
];
$shippingCost
=
Yii
::
$service
->
shipping
->
getShippingCost
(
$shipping_method
,
$product_weight
,
$country
,
$state
);
// 计算运费。
$avaiable_method
=
Yii
::
$service
->
shipping
->
getAvailableShippingMethods
(
$country
,
$region
,
$product_weight
);
$shippingInfo
=
$avaiable_method
[
$shipping_method
];
$shippingCost
=
Yii
::
$service
->
shipping
->
getShippingCost
(
$shipping_method
,
$shippingInfo
,
$product_weight
,
$country
,
$state
);
Yii
::
$service
->
cart
->
quote
->
setShippingCost
(
$shippingCost
);
/**
* 下面通过当前的货币,购物车信息等数组数据,+上view文件
* 返回order部分的html内容。
...
...
app/appfront/modules/Checkout/block/onepage/Placeorder.php
浏览文件 @
64637acb
...
...
@@ -268,11 +268,11 @@ class Placeorder
return
false
;
}
else
{
if
(
!
Yii
::
$service
->
shipping
->
ifIsCorrect
(
$shipping_method
))
{
Yii
::
$service
->
helper
->
errors
->
add
(
'shipping method is not correct'
);
return
false
;
}
//
if (!Yii::$service->shipping->ifIsCorrect($shipping_method)) {
//
Yii::$service->helper->errors->add('shipping method is not correct');
//
//
return false;
//
}
}
// 验证支付方式
if
(
!
$payment_method
)
{
...
...
services/Shipping.php
浏览文件 @
64637acb
此差异已折叠。
点击以展开。
services/cart/Quote.php
浏览文件 @
64637acb
...
...
@@ -243,9 +243,9 @@ class Quote extends Service
}
$myCart
->
remote_ip
=
\
fec\helpers\CFunc
::
get_real_ip
();
$myCart
->
app_name
=
Yii
::
$service
->
helper
->
getAppName
();
if
(
$defaultShippingMethod
=
Yii
::
$service
->
shipping
->
getDefaultShippingMethod
())
{
$myCart
->
shipping_method
=
$defaultShippingMethod
;
}
//
if ($defaultShippingMethod = Yii::$service->shipping->getDefaultShippingMethod()) {
//
$myCart->shipping_method = $defaultShippingMethod;
//
}
$myCart
->
save
();
$cart_id
=
$myCart
[
'cart_id'
];
$this
->
setCartId
(
$cart_id
);
...
...
@@ -338,12 +338,7 @@ class Quote extends Service
if
(
$items_qty
<=
0
)
{
return
false
;
}
//var_dump($cart);
//echo "########".$cart['shipping_method'];
$coupon_code
=
$cart
[
'coupon_code'
];
if
(
!
$shipping_method
)
{
$shipping_method
=
$cart
[
'shipping_method'
];
}
$cart_product_info
=
Yii
::
$service
->
cart
->
quoteItem
->
getCartProductInfo
();
if
(
is_array
(
$cart_product_info
))
{
$product_weight
=
$cart_product_info
[
'product_weight'
];
...
...
@@ -351,10 +346,13 @@ class Quote extends Service
$products
=
$cart_product_info
[
'products'
];
$product_total
=
$cart_product_info
[
'product_total'
];
$base_product_total
=
$cart_product_info
[
'base_product_total'
];
//if (!$shipping_method) {
// $shipping_method = Yii::$service->shipping->getDefaultShippingMethod($country,$region,$product_weight);
//}
if
(
$products
&&
$product_total
)
{
$currShippingCost
=
0
;
$baseShippingCost
=
0
;
if
(
$shipping_method
&&
$product_weight
&&
$country
)
{
if
(
$shipping_method
&&
$product_weight
)
{
$shippingCost
=
$this
->
getShippingCost
(
$shipping_method
,
$product_weight
,
$country
,
$region
);
$currShippingCost
=
$shippingCost
[
'currCost'
];
$baseShippingCost
=
$shippingCost
[
'baseCost'
];
...
...
@@ -420,11 +418,11 @@ class Quote extends Service
*/
public
function
getShippingCost
(
$shipping_method
=
''
,
$weight
=
''
,
$country
=
''
,
$region
=
''
)
{
if
(
!
$region
)
{
$region
=
'*'
;
}
if
(
!
$this
->
_shipping_cost
)
{
$shippingCost
=
Yii
::
$service
->
shipping
->
getShippingCost
(
$shipping_method
,
$weight
,
$country
,
$region
);
$available_method
=
Yii
::
$service
->
shipping
->
getAvailableShippingMethods
(
$country
,
$region
,
$weight
);
$shippingInfo
=
$available_method
[
$shipping_method
];
$shippingCost
=
Yii
::
$service
->
shipping
->
getShippingCost
(
$shipping_method
,
$shippingInfo
,
$weight
,
$country
,
$region
);
$this
->
_shipping_cost
=
$shippingCost
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录