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 @@ +
+ +
+
+

Всего товаров:

+

Сумма: 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);
-
-
    -
  • -
    -
    -
    - -
    -
    - Штукатурка гипсовая Кнауф Ротбанд 30 кг белая - Код: 45885-01016049 -
    -
    -
    -
    1
    -
    -
    +
    -
    -
    -
    -
    -
    102.05 грн.
    -
    -
    -
  • -
  • -
    -
    -
    - -
    -
    - Штукатурка гипсовая Кнауф Ротбанд 30 кг белая - Код: 45885-01016049 -
    -
    -
    -
    1
    -
    -
    +
    -
    -
    -
    -
    -
    102.05 грн.
    -
    -
    -
  • -
  • -
    -
    -
    - -
    -
    - Штукатурка гипсовая Кнауф Ротбанд 30 кг белая - Код: 45885-01016049 -
    -
    -
    -
    1
    -
    -
    +
    -
    -
    -
    -
    -
    102.05 грн.
    -
    -
    -
  • -
-
-
-

Всего товаров: 3

-

Сумма: 306.15 грн.

-
-
- продолжить покупки - -
+
+
@@ -257,87 +182,9 @@ AppAsset::register($this);
-
-

товар добавлен в корзину

-
    -
  • -
    -
    -
    - -
    -
    - Штукатурка гипсовая Кнауф Ротбанд 30 кг белая - Код: 45885-01016049 -
    -
    -
    -
    1
    -
    -
    +
    -
    -
    -
    -
    -
    102.05 грн.
    -
    -
    -
  • -
  • -
    -
    -
    - -
    -
    - Штукатурка гипсовая Кнауф Ротбанд 30 кг белая - Код: 45885-01016049 -
    -
    -
    -
    1
    -
    -
    +
    -
    -
    -
    -
    -
    102.05 грн.
    -
    -
    -
  • -
  • -
    -
    -
    - -
    -
    - Штукатурка гипсовая Кнауф Ротбанд 30 кг белая - Код: 45885-01016049 -
    -
    -
    -
    1
    -
    -
    +
    -
    -
    -
    -
    -
    102.05 грн.
    -
    -
    -
  • -
-
-
-

Всего товаров: 3

-

Сумма: 306.15 грн.

-
-
- продолжить покупки - -
+
+
-
diff --git a/frontend/views/site/login.php b/frontend/views/site/login.php index 56ea98e..90e81c4 100644 --- a/frontend/views/site/login.php +++ b/frontend/views/site/login.php @@ -19,7 +19,7 @@ $this->params['breadcrumbs'][] = $this->title;
'login-form']); ?> - field($model, 'username')->textInput(['autofocus' => true]) ?> + field($model, 'email')->textInput(['autofocus' => true]) ?> field($model, 'password')->passwordInput() ?> diff --git a/frontend/web/css/concat_all.css b/frontend/web/css/concat_all.css index f3bcc73..eaedebd 100644 --- a/frontend/web/css/concat_all.css +++ b/frontend/web/css/concat_all.css @@ -2494,7 +2494,7 @@ span.red { .busket_modal_wrapper .busket_modal_01 .order_list .count_block .count_buttons { position: relative; /*top: 4px;*/ - right: 6px; + right: 16px; display: inline-block; vertical-align: bottom; } @@ -2680,7 +2680,7 @@ span.red { .busket_modal_header .busket_modal_02 .order_list .count_block .count_buttons { position: relative; /*top: 4px;*/ - right: 6px; + right: 16px; display: inline-block; vertical-align: bottom; } diff --git a/frontend/web/css/concat_all_back.css b/frontend/web/css/concat_all_back.css index bb01d29..b359e28 100644 --- a/frontend/web/css/concat_all_back.css +++ b/frontend/web/css/concat_all_back.css @@ -2492,8 +2492,7 @@ span.red { .busket_modal_wrapper .busket_modal_01 .order_list .count_block .count_buttons { position: relative; - /*top: 4px;*/ - right: 6px; + right: 16px; display: inline-block; vertical-align: bottom; } diff --git a/frontend/web/css/style.css b/frontend/web/css/style.css index 731499f..cfa34fa 100644 --- a/frontend/web/css/style.css +++ b/frontend/web/css/style.css @@ -1071,10 +1071,32 @@ input.error_pass{ #loginform-rememberme{ display: none; } + .field-loginform-rememberme{ display: inline; color: #6aa034; } + .field-loginform-rememberme label:hover{ color: #517a27; +} + +.buy_one_item { + display: inline-block; + width: 50px; + height: 31px; + vertical-align: top; + font-size: 17px; + line-height: 1; + padding: 0 10px 0 10px; + color: #555; + background-color: #fff; + background-image: none; + border: 1px solid #ccc; + border-radius: 4px; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); + -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s; + -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; + transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; } \ No newline at end of file diff --git a/frontend/web/js/my_scripts.js b/frontend/web/js/my_scripts.js index 4e8469c..a9b4694 100644 --- a/frontend/web/js/my_scripts.js +++ b/frontend/web/js/my_scripts.js @@ -21,10 +21,10 @@ $(document).ready(function(){ filter_list.on('click', function(){ $(this).next().slideToggle(300); var this_img = $(this).children('img'); - if (this_img.attr('src') === "images/head_down.png" ) { - this_img.attr('src', 'images/head_up.png'); + if (this_img.attr('src') === "/images/head_down.png" ) { + this_img.attr('src', '/images/head_up.png'); } else { - this_img.attr('src', 'images/head_down.png'); + this_img.attr('src', '/images/head_down.png'); }; }); @@ -85,46 +85,25 @@ $(document).ready(function(){ // arrow left hover arrow_left.hover( function(){ - $(this).attr('src', 'images/slider_left_hover.png'); + $(this).attr('src', '/images/slider_left_hover.png'); }, function(){ - $(this).attr('src', 'images/slider_left.png'); + $(this).attr('src', '/images/slider_left.png'); }); // arrow right hover arrow_right.hover( function(){ - $(this).attr('src', 'images/slider_right_hover.png'); + $(this).attr('src', '/images/slider_right_hover.png'); }, function(){ - $(this).attr('src', 'images/slider_right.png'); + $(this).attr('src', '/images/slider_right.png'); }); // добавить в корзину - счетчик + - товар var open_card_item_price = $('.counter').children('.price'), - counter_plus_btn = $('.counter').find('.button_plus'), - counter_minus_btn = $('.counter').find('.button_minus'), counter_item_count = $('.counter').find('.count_number'), state_price = 1*($('.counter').children('.price').html()); - counter_plus_btn.click(function(){ - var count = +counter_item_count.html(); - count++; - counter_item_count.text(count); - - var become = 1*($('.counter').children('.price').html()); - var result = become + state_price; - open_card_item_price.text(result.toFixed(2)); - }); - counter_minus_btn.click(function(){ - var become = 1*($('.counter').children('.price').html()); - var result = become - state_price; - if(become > 0) { - open_card_item_price.text(result.toFixed(2)); - var count = +counter_item_count.html(); - count--; - counter_item_count.text(count); - } - }); // активный класс для корзины var basket_order_list = $('.order_list').find('.order_list_li'); @@ -141,19 +120,19 @@ $(document).ready(function(){ basket_each_count = basket_order_list.children('.how_many'); // количество каждого товара // console.log(basket_each_price); - function basket_all_prices() { - var all_count = 0; - var all_price = 0; - for (var i = basket_each_count.length - 1; i >= 0; i--) { - var temp = basket_each_count[i].innerHTML; - var temp_price = basket_each_price[i].innerHTML; - all_count += parseInt(temp); - all_price += parseFloat(temp_price); - }; - basket_all_items.text(all_count); - basket_all_price.text(all_price.toFixed(2)); - } - basket_all_prices(); + //function basket_all_prices() { + // var all_count = 0; + // var all_price = 0; + // for (var i = basket_each_count.length - 1; i >= 0; i--) { + // var temp = basket_each_count[i].innerHTML; + // var temp_price = basket_each_price[i].innerHTML; + // all_count += parseInt(temp); + // all_price += parseFloat(temp_price); + // }; + // basket_all_items.text(all_count); + // basket_all_price.text(all_price.toFixed(2)); + //} + //basket_all_prices(); // modal widows @@ -293,6 +272,8 @@ $(document).ready(function(){ log_wrap.fadeOut(200); forgot_pass_wrap.fadeOut(200); forgot_pass_success_wrap.fadeOut(200); + forgot_pass_success_wrap.fadeOut(200); + busket_modal_wrapper.fadeOut(200); callback_wrap.fadeOut(200); }); $(".close_modal").click(function(){ @@ -499,6 +480,68 @@ $(document).ready(function(){ all_modal_moves(); + function countPrise(block){ + var total_price = 0; + block.find('.price').each(function(){ + total_price += +$(this).html(); + }); + $('.total_price').html(total_price); + $("input[name='OrderForm[total_price]']").val(total_price); + } + + + $('.item').on('click', '.basket_add_but', function(e){ + var id = $(this).parents('.item').data('id'); + console.log(id); + $.post( "/orders/buy-items", {id: id}, function( data ) { + $('.basket_result').each(function(){ + $(this).html(data) + }); + }); + + }); + + $('.basket_result').on('click', '.delete_item_btn', function(){ + var id = $(this).parents('.order_list_li').data('id'); + $(this).parents('.order_list_li').remove(); + $.post( "/orders/delete", {id: id}, function( data ) { + }); + countPrise(); + }); + + $('.basket_result').on('click', '.button_minus', function(){ + var input = $(this).parents('.order_list_li ').find('input'); + var number = input.val(); + if(number > 1){ + number--; + input.val(number); + var price = $(this).parents('.goods_data').find('.item_prise_block').find('span').html(); + var new_price = number * price; + $(this).parents('.goods_data').find('.item_prise_total_block').find('span').html(new_price); + } + countPrise(); + }); + + + $('.basket_result').on('click', '.button_plus', function(){ + var input = $(this).parents('.order_list_li ').find('input'); + var number = input.val(); + number++; + input.val(number); + var price = $(this).parents('.goods_data').find('.item_prise_block').find('span').html(); + var new_price = number * price; + $(this).parents('.goods_data').find('.item_prise_total_block').find('span').html(new_price); + countPrise(); + }); + + $('.basket_result').on('change', '.buy_one_item', function(){ + var num = $(this).val(); + var priceBlock = $(this).parents('.order_list_li').find('.price'); + var price = priceBlock.html(); + var new_price = num * price; + priceBlock.html(new_price); + countPrise(); + }); }); \ No newline at end of file -- libgit2 0.21.4