fecshop代码的重用

文档问题 · fecshoper · 于 6年前 发布 · 1740 次阅读

1、比如发货地址 我在管理后台和下订单处都要获取发货地址列表,怎么重用代码,但是目前很难重用

共收到 1 条回复
Fecmall#16年前 0 个赞

很简单的事情,直接从order services 查询就行了:

https://github.com/fecshop/yii2_fecshop/blob/master/services/Order.php

/**
     * @property $primaryKey | Int
     * @return Object($this->_orderModel)
     * 通过主键值,返回Order Model对象
     */
    protected function actionGetByPrimaryKey($primaryKey)
    {
        $one = $this->_orderModel->findOne($primaryKey);
        $primaryKey = $this->getPrimaryKey();
        if ($one[$primaryKey]) {
            return $one;
        } else {
            return new $this->_orderModelName();
        }
    }
    
    /**
     * @property $increment_id | String , 订单号
     * @return object ($this->_orderModel),返回 $this->_orderModel model
     * 通过订单号incrementId,得到订单Model对象。
     */
    protected function actionGetByIncrementId($increment_id)
    {
        $one = $this->_orderModel->findOne(['increment_id' => $increment_id]);
        $primaryKey = $this->getPrimaryKey();
        if ($one[$primaryKey]) {
            return $one;
        } else {
            return false;
        }
    }
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics