diff --git a/backend/controllers/BuyController.php b/backend/controllers/BuyController.php
new file mode 100644
index 0000000..26780e1
--- /dev/null
+++ b/backend/controllers/BuyController.php
@@ -0,0 +1,143 @@
+ [
+ 'class' => VerbFilter::className(),
+ 'actions' => [
+ 'delete' => [ 'POST' ],
+ ],
+ ],
+ 'access' => [
+ 'class' => AccessControl::className(),
+ 'rules' => [
+ [
+ 'allow' => true,
+ 'roles' => [ '@' ],
+ ],
+ ],
+ ],
+ ];
+ }
+ public function actions()
+ {
+ return [
+ 'index' => [
+ 'class' => Index::className(),
+ 'columns' => [
+ 'name' => [
+ 'type' => Index::ACTION_COL,
+ ],
+ 'email' => [
+ 'type' => Index::STRING_COL
+ ],
+ 'status' => [
+ 'type' => Index::STATUS_COL,
+ ],
+ 'created_at' => [
+ 'type' => Index::DATETIME_COL,
+ ]
+ ],
+ 'model' => Buy::className(),
+ 'hasLanguage' => false,
+ 'enableMassDelete' => true,
+ 'modelPrimaryKey' => 'id',
+ 'defaultSort' => [
+ 'created_at' => 'DESC',
+ ],
+ 'create' => false
+ ],
+ 'view' => [
+ 'class' => View::className(),
+ 'model' => Buy::className(),
+ 'hasAlias' => false,
+ 'hasGallery' => false,
+ 'languageFields' => [
+ ],
+ 'fields' => [
+ [
+ 'name' => 'name',
+ 'type' => Form::STRING,
+ ],
+ [
+ 'name' => 'email',
+ 'type' => Form::STRING,
+ ],
+ [
+ 'name' => 'created_at',
+ 'type' => Form::STRING,
+ ],
+
+ ],
+ ],
+ 'delete' => [
+ 'class' => Delete::className(),
+ ],
+ ];
+ }
+
+ public function findModel($id)
+ {
+
+ $model = Buy::find()
+ ->where([ 'id' => $id ])
+ ->one();
+ if ($model !== null) {
+ return $model;
+ } else {
+ throw new NotFoundHttpException('The requested page does not exist.');
+ }
+ }
+
+ public function deleteModel($id)
+ {
+ $category = Buy::find()
+ ->where(
+ [
+ 'id' => $id,
+ ]
+ )
+ ->one();
+
+
+ return $category->delete();
+ }
+
+ public function actionUpdate($id)
+ {
+ $model = $this->findModel($id);
+ if ($model->load(\Yii::$app->request->post()) && $model->save()) {
+ return $this->redirect('index');
+ } else {
+ return $this->render(
+ 'update',
+ [
+ 'model' => $model,
+ ]
+ );
+ }
+ }
+ }
\ No newline at end of file
diff --git a/backend/views/buy/_form.php b/backend/views/buy/_form.php
new file mode 100644
index 0000000..c3587b1
--- /dev/null
+++ b/backend/views/buy/_form.php
@@ -0,0 +1,57 @@
+registerJs($js, View::POS_READY);
+
+?>
+
+
diff --git a/backend/views/buy/update.php b/backend/views/buy/update.php
new file mode 100644
index 0000000..0188871
--- /dev/null
+++ b/backend/views/buy/update.php
@@ -0,0 +1,45 @@
+title = Yii::t(
+ 'app',
+ 'Update {modelClass}: ',
+ [
+ 'modelClass' => 'Comment',
+ ]
+ ) . $model->name;
+ $this->params[ 'breadcrumbs' ][] = [
+ 'label' => Yii::t('app', 'Comments'),
+ 'url' => [ 'index' ],
+ ];
+ $this->params[ 'breadcrumbs' ][] = [
+ 'label' => $model->name,
+ 'url' => [
+ 'view',
+ 'id' => $model->id,
+ ],
+ ];
+ $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update');
+?>
+
+ $this->title,
+ 'options' => [
+ 'class' => 'x_panel comment-update',
+ ],
+ ]
+) ?>
+
+= $this->render(
+ '_form',
+ [
+ 'model' => $model,
+ ]
+) ?>
+
+
diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php
index 5279742..7f0686e 100755
--- a/backend/views/layouts/menu_items.php
+++ b/backend/views/layouts/menu_items.php
@@ -65,6 +65,11 @@
'url' => [ '/support/index' ],
],
+ [
+ 'label' => \Yii::t('app', 'Buyers'),
+ 'url' => [ '/buy/index' ],
+
+ ],
],
],
diff --git a/common/models/Book.php b/common/models/Book.php
index df99341..cdcbf6f 100644
--- a/common/models/Book.php
+++ b/common/models/Book.php
@@ -74,7 +74,8 @@
'author_id',
'created_at',
'status',
- 'alias_id'
+ 'alias_id',
+ 'price'
],
'integer',
],
diff --git a/common/models/Buy.php b/common/models/Buy.php
new file mode 100644
index 0000000..2a368b3
--- /dev/null
+++ b/common/models/Buy.php
@@ -0,0 +1,104 @@
+ TimestampBehavior::className(),
+ 'updatedAtAttribute' => false,
+ ],
+ ];
+
+ }
+ /**
+ * {@inheritdoc}
+ */
+ public function rules()
+ {
+ return [
+ [
+ [
+ 'book_id',
+ 'created_at',
+ 'status',
+ ],
+ 'default',
+ 'value' => null,
+ ],
+ [
+ [
+ 'book_id',
+ 'created_at',
+ 'status',
+ ],
+ 'integer',
+ ],
+ [
+ [
+ 'name',
+ 'email',
+ ],
+ 'string',
+ 'max' => 255,
+ ],
+ [
+ [ 'book_id' ],
+ 'exist',
+ 'skipOnError' => true,
+ 'targetClass' => Book::className(),
+ 'targetAttribute' => [ 'book_id' => 'id' ],
+ ],
+ [
+ ['email'], 'required'
+ ]
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id' => Yii::t('app', 'ID'),
+ 'book_id' => Yii::t('app', 'Book ID'),
+ 'name' => Yii::t('app', 'Name'),
+ 'email' => Yii::t('app', 'Email'),
+ 'created_at' => Yii::t('app', 'Created At'),
+ '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/m180704_105641_create_buy_table.php b/console/migrations/m180704_105641_create_buy_table.php
new file mode 100644
index 0000000..0dd72c2
--- /dev/null
+++ b/console/migrations/m180704_105641_create_buy_table.php
@@ -0,0 +1,41 @@
+createTable('buy', [
+ 'id' => $this->primaryKey(),
+ 'book_id' => $this->integer(),
+ 'name' => $this->string(),
+ 'email' => $this->string(),
+ 'created_at' => $this->integer(),
+ 'status' => $this->integer()
+ ]);
+
+ $this->addForeignKey('buy_book_fk',
+ 'buy',
+ 'book_id',
+ 'book',
+ 'id',
+ 'CASCADE',
+ 'CASCADE');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropForeignKey('buy_book_fk', 'buy');
+ $this->dropTable('buy');
+ }
+}
diff --git a/frontend/controllers/SupportController.php b/frontend/controllers/SupportController.php
index 1cec5c5..19420e0 100644
--- a/frontend/controllers/SupportController.php
+++ b/frontend/controllers/SupportController.php
@@ -9,6 +9,7 @@
namespace frontend\controllers;
use common\models\Book;
+ use common\models\Buy;
use common\models\Support;
use frontend\helpers\Url;
use frontend\models\SearchModel;
@@ -68,4 +69,21 @@
}
}
}
+
+
+ public function actionBuy($book_id = null){
+ $model = new Buy([
+ 'book_id' => $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('buy', [
+ '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 77d1c6b..f511001 100644
--- a/frontend/views/book/_book.php
+++ b/frontend/views/book/_book.php
@@ -22,17 +22,16 @@
400
) ?>
- price == null){?>
-
+ price != null){?>
вартість =$model->price?> грн.
-
+
-
+
diff --git a/frontend/views/support/buy.php b/frontend/views/support/buy.php
new file mode 100644
index 0000000..17588c0
--- /dev/null
+++ b/frontend/views/support/buy.php
@@ -0,0 +1,42 @@
+
+
diff --git a/frontend/views/support/index.php b/frontend/views/support/index.php
index f005997..e9a43be 100644
--- a/frontend/views/support/index.php
+++ b/frontend/views/support/index.php
@@ -11,7 +11,7 @@
-
Придбати заздалегіть
+
Підтримати
@@ -36,7 +36,7 @@
=$form->field($model, 'book_id')->hiddenInput()->label(false);?>
=$form->field($model, 'status')->hiddenInput()->label(false);?>
- =Html::submitButton('Придбати')?>
+ =Html::submitButton('Підтримати')?>
--
libgit2 0.21.4