Ejemplo n.º 1
0
 protected function findModel($id)
 {
     if (($model = Payment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 2
0
 public function search($params)
 {
     $query = Payment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'order_id' => $this->order_id, 'amount' => $this->amount, 'payment_type_id' => $this->payment_type_id]);
     $query->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 public function getPayment()
 {
     return $this->hasOne(Payment::className(), ['order_id' => 'id']);
 }
Ejemplo n.º 4
0
 public function actionCustomerCreate()
 {
     $model = new Order(['scenario' => 'customer']);
     if ($model->load(yii::$app->request->post())) {
         $model->date = date('Y-m-d');
         $model->time = date('H:i:s');
         $model->timestamp = time();
         $model->status = $this->module->defaultStatus;
         $model->payment = 'no';
         $model->user_id = yii::$app->user->id;
         if ($model->save()) {
             if ($ordersEmail = yii::$app->getModule('order')->ordersEmail) {
                 $sender = yii::$app->getModule('order')->mail->compose('admin_notification', ['model' => $model])->setTo($ordersEmail)->setFrom(yii::$app->getModule('order')->robotEmail)->setSubject(Yii::t('order', 'New order') . " #{$model->id} ({$model->client_name})")->send();
             }
             $module = $this->module;
             $orderEvent = new OrderEvent(['model' => $model]);
             $this->module->trigger($module::EVENT_ORDER_CREATE, $orderEvent);
             if ($paymentType = $model->paymentType) {
                 $payment = new Payment();
                 $payment->order_id = $model->id;
                 $payment->payment_type_id = $paymentType->id;
                 $payment->date = date('Y-m-d H:i:s');
                 $payment->amount = $model->getCost();
                 $payment->description = yii::t('order', 'Order #' . $model->id);
                 $payment->user_id = yii::$app->user->id;
                 $payment->ip = yii::$app->getRequest()->getUserIP();
                 $payment->save();
                 if ($widget = $paymentType->widget) {
                     return $widget::widget(['autoSend' => true, 'orderModel' => $model, 'description' => yii::t('order', 'Order #' . $model->id)]);
                 }
             }
             return $this->redirect([yii::$app->getModule('order')->successUrl, 'id' => $model->id, 'payment' => $model->payment_type_id]);
         } else {
             yii::$app->session->setFlash('orderError', yii::t('order', 'Error (check required fields)'));
             return $this->redirect(yii::$app->request->referrer);
         }
     } else {
         yii::$app->session->setFlash('orderError', yii::t('order', 'Error (check required fields)'));
         return $this->redirect(yii::$app->request->referrer);
     }
 }