fecshop 关于默认的shipping 物流 快递 货运 方式

技术分享 · Fecmall · 于 5年前 发布 · 1779 次阅读

https://github.com/fecshop/yii2_fecshop/blob/master/services/Shipping.php#L206

/**
     * @proeprty $customShippingMethod 自定义的货运方式,这个一般是通过前端传递过来的shippingMethod
     * @proeprty $cartShippingMethod   购物车中的货运方式,这个是从购物车表中取出来的。
     * @return string 返回当前的货运方式。
     */
    protected function actionGetCurrentShippingMethod($customShippingMethod, $cartShippingMethod, $country, $region, $weight)
    {
        $available_method = $this->getAvailableShippingMethods($country, $region, $weight);
        if ($customShippingMethod) {
            if (isset($available_method[$customShippingMethod])) {
                return $customShippingMethod;
            }
        }
        if ($cartShippingMethod) {
            if (isset($available_method[$cartShippingMethod])) {
                return $cartShippingMethod;
            }
        }
        // 如果都不存在,则将可用物流中的第一个取出来$available_method
        foreach ($available_method as $method => $v) {
            return $method;
        }
    }

可以看到逻辑:

1.如果用户勾选了shipping_method,那么就使用当前用户勾选的shipping method,也就是用户在切换shipping method的时候

2.如果用户没有勾选,那么就使用cart表里面的shipping method,譬如用户在下单选择shipping method,cart存储后,就会使用cart表中的shipping method

3.如果用户上面的都没有操作,也就是第一次下单,那么就会选择shipping method配置中的第一个shipping method作为默认的货运方式

共收到 0 条回复
没有找到数据。
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics