backend\models\CancelOrderForm::cancel PHP Method

cancel() public method

public cancel ( $runValidation = true )
    public function cancel($runValidation = true)
    {
        if ($runValidation && !$this->validate()) {
            return false;
        }
        if ($this->_order->status !== Order::STATUS_UNSHIPPED) {
            return false;
        }
        if ($this->_order->payment !== Order::PAYMENT_OFFLINE) {
            return false;
        }
        return $this->_order->cancel($this->msg);
    }

Usage Example

 public function actionCancel($id)
 {
     try {
         $cancelOrderForm = new CancelOrderForm($id);
     } catch (InvalidParamException $e) {
         throw new BadRequestHttpException($e->getMessage());
     }
     if ($cancelOrderForm->load(Yii::$app->request->post()) && $cancelOrderForm->cancel()) {
         Yii::$app->session->setFlash('success', '取消成功!');
     } else {
         Yii::$app->session->setFlash('danger', '取消失败!');
     }
     return $this->redirect(['view', 'id' => $id]);
 }