diff --git a/.gitignore b/.gitignore
index 3973ae3..065fbf5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,4 +35,6 @@ common/config/params-local.php
backend/config/main-local.php
backend/config/params-local.php
frontend/config/main-local.php
-frontend/config/params-local.php
\ No newline at end of file
+frontend/config/params-local.php
+frontend/views/вертска
+frontend/web/css/node_modules
\ No newline at end of file
diff --git a/common/models/Customers.php b/common/models/Customers.php
index 1e15eb5..dfd894c 100644
--- a/common/models/Customers.php
+++ b/common/models/Customers.php
@@ -42,7 +42,6 @@ class Customers extends User
[['email'], 'unique'],
[['password_reset_token'], 'unique'],
[['phone'], 'unique'],
- [['username'], 'unique'],
];
}
diff --git a/common/widgets/BasketModal.php b/common/widgets/BasketModal.php
index c7f3979..6c4821a 100644
--- a/common/widgets/BasketModal.php
+++ b/common/widgets/BasketModal.php
@@ -1,15 +1,10 @@
item_id && $this->model){
- $widgetData = $this->findModel();
- } else {
- $widgetData= [new Fields()];
+ $sessionData = \Yii::$app->session->get('order');
+ $count = count($sessionData);
+ if(is_array($sessionData) && !empty($sessionData)){
+ return $this->render('busket_modal',[
+ 'items'=>$sessionData,
+ 'count' => $count
+ ]);
}
- return $this->render($this->template.'_field',['model'=>ArrayHelper::toArray($widgetData)]);
}
- protected function findModel()
- {
-
- if (($model = Fields::find()->where([
- 'table_id'=>$this->item_id,
- 'table_name'=>$this->model,
- 'field_type'=>$this->template,
- 'language'=>$this->language,
- ])->all())) {
-
- return $model;
-
- } else {
- return [new Fields()];
- }
- }
}
\ No newline at end of file
diff --git a/common/widgets/views/busket_modal.php b/common/widgets/views/busket_modal.php
index 2a6ecc0..6c9885b 100644
--- a/common/widgets/views/busket_modal.php
+++ b/common/widgets/views/busket_modal.php
@@ -1,7 +1,45 @@
+
+
+
+ -
+
+
+
+

+
+
+ Штукатурка гипсовая Кнауф Ротбанд 30 кг белая
+ Код: 45885-01016049
+
+
+
+
+
+
+
+
+
+
Всего товаров: = $count ?>
+
Сумма: 306.15 грн.
+
+
+
diff --git a/console/migrations/m160321_232402_orders.php b/console/migrations/m160321_232402_orders.php
index 0cec26a..2e03a91 100644
--- a/console/migrations/m160321_232402_orders.php
+++ b/console/migrations/m160321_232402_orders.php
@@ -13,7 +13,8 @@ class m160321_232402_orders extends Migration
}
$this->createTable('{{%orders}}', [
- 'id' => $this->primaryKey(),
+ 'order_id' => $this->primaryKey(),
+ 'customer_id' => $this->integer(),
'name' => $this->string()->notNull(),
'email' => $this->string()->notNull(),
'phone' => $this->string(32)->notNull(),
@@ -24,11 +25,25 @@ class m160321_232402_orders extends Migration
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $tableOptions);
+
+ $this->createTable('{{%order_items}}', [
+ 'order_items_id' => $this->primaryKey(),
+ 'order_id' => $this->integer(),
+ 'item_id' => $this->integer(),
+ 'item_count' => $this->integer(),
+ 'price' => $this->float(),
+ ], $tableOptions);
+
+ $this->addForeignKey('orders_items_fk', '{{%order_items}}', 'order_id', '{{%orders}}', 'order_id', 'CASCADE', 'CASCADE');
+ $this->addForeignKey('orders_items_items_fk', '{{%order_items}}', 'item_id', '{{%product}}', 'product_id', 'RESTRICT', 'RESTRICT');
}
public function down()
{
+ $this->dropForeignKey('orders_items_fk', '{{%order_items}}');
+ $this->dropForeignKey('orders_items_items_fk', '{{%order_items}}');
$this->dropTable('{{%orders}}');
+ $this->dropTable('{{%order_items}}');
}
}
diff --git a/frontend/controllers/OrdersController.php b/frontend/controllers/OrdersController.php
index be6b534..4df7352 100644
--- a/frontend/controllers/OrdersController.php
+++ b/frontend/controllers/OrdersController.php
@@ -2,6 +2,7 @@
namespace frontend\controllers;
+use common\widgets\BasketModal;
use Yii;
use yii\web\Controller;
@@ -10,10 +11,21 @@ use yii\data\ArrayDataProvider;
/**
* OrderController implements the CRUD actions for Order model.
*/
-class OrderыController extends Controller
+class OrdersController extends Controller
{
- public $layout='/column2';
+
+ /**
+ * @inheritdoc
+ */
+ public function beforeAction($action)
+ {
+ if ($action->id == 'buy-items' || $action->id == 'delete') {
+ Yii::$app->controller->enableCsrfValidation = false;
+ }
+
+ return true;
+ }
/**
* Lists all Order models.
@@ -105,7 +117,7 @@ class OrderыController extends Controller
$array[$data['id']] = $data;
Yii::$app->session->set('order', $array );
}
- echo count(Yii::$app->session->get('order'));
+ echo BasketModal::widget([]);
}
/**
diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php
index fffbc77..0d84e53 100644
--- a/frontend/views/layouts/main.php
+++ b/frontend/views/layouts/main.php
@@ -4,6 +4,7 @@
/* @var $content string */
+use common\widgets\BasketModal;
use frontend\assets\AppAsset;
use yii\helpers\Html;
use yii\helpers\Url;
@@ -79,84 +80,8 @@ AppAsset::register($this);