diff --git a/common/models/Support.php b/common/models/Support.php new file mode 100644 index 0000000..2fe9381 --- /dev/null +++ b/common/models/Support.php @@ -0,0 +1,90 @@ + null, + ], + [ + [ + 'book_id', + 'sum', + 'status', + ], + 'integer', + ], + ['email', 'email'], + [ + [ 'email', 'name' ], + 'string', + 'max' => 255, + ], + [ + [ 'book_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Book::className(), + 'targetAttribute' => [ 'book_id' => 'id' ], + ], + [ + ['email', 'sum'], 'required' + ] + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'book_id' => Yii::t('app', 'Book ID'), + 'email' => Yii::t('app', 'Email'), + 'sum' => Yii::t('app', 'Sum'), + 'status' => Yii::t('app', 'Status'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getBook() + { + return $this->hasOne(Book::className(), [ 'id' => 'book_id' ]); + } + } diff --git a/console/migrations/m180614_103157_create_support_table.php b/console/migrations/m180614_103157_create_support_table.php new file mode 100644 index 0000000..9988443 --- /dev/null +++ b/console/migrations/m180614_103157_create_support_table.php @@ -0,0 +1,41 @@ +createTable('support', [ + 'id' => $this->primaryKey(), + 'book_id' => $this->integer(), + 'name' => $this->string(), + 'email' => $this->string(), + 'sum' => $this->integer(), + 'status' => $this->integer() + ]); + + $this->addForeignKey('support_book_fk', + 'support', + 'book_id', + 'book', + 'id', + 'CASCADE', + 'CASCADE'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('support_book_fk', 'support'); + $this->dropTable('support'); + } +} diff --git a/frontend/controllers/SupportController.php b/frontend/controllers/SupportController.php new file mode 100644 index 0000000..3621d53 --- /dev/null +++ b/frontend/controllers/SupportController.php @@ -0,0 +1,32 @@ + $book_id, + 'status' => 0 + ]); + $book = Book::find()->with('author')->where(['id' => $book_id])->one(); + if ($model->load(\Yii::$app->request->post()) and $model->save()){ + \Yii::$app->session->setFlash('success', 'Дякуємо за ваш запит. Найближчим часом, наш менеджер зв\'яжеться з Вами для уточнення деталей'); + return $this->redirect(['site/index']); + } + return $this->render('index', [ + 'model' => $model, + 'book' => $book + ]); + } + } \ No newline at end of file diff --git a/frontend/views/book/_book.php b/frontend/views/book/_book.php index ad29a8f..15b25a2 100644 --- a/frontend/views/book/_book.php +++ b/frontend/views/book/_book.php @@ -19,7 +19,7 @@ price == null){?>
460 підтримувачів
поділитися в соціальних мережах
diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 638e6ee..129ccf2 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -47,6 +47,14 @@ ] ); $module = \Yii::$app->getModule('feedback'); + + if (\Yii::$app->session->hasFlash('success')) { + $message = \Yii::$app->session->getFlash('success'); + $js = <<