Commit fe7b6960a5f9698bdafc6f4aa8956181694ecf3e

Authored by Yarik
1 parent 871a7349

Basket

common/config/main.php
@@ -157,6 +157,9 @@ return [ @@ -157,6 +157,9 @@ return [
157 ], 157 ],
158 ] 158 ]
159 ], 159 ],
  160 + 'basket' => [
  161 + 'class' => 'common\models\Basket',
  162 + ],
160 ], 163 ],
161 164
162 'modules' => [ 165 'modules' => [
common/models/Basket.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace common\models;
  4 +
  5 + use common\modules\product\models\ProductVariant;
  6 + use yii\base\Component;
  7 + use yii\web\NotFoundHttpException;
  8 +
  9 + class Basket extends Component
  10 + {
  11 +
  12 + public $session;
  13 +
  14 + public function __construct(array $config = [ ])
  15 + {
  16 + $this->session = \Yii::$app->session;
  17 + if(!$this->session->has('basket')) {
  18 + $this->session->set('basket', [ ]);
  19 + }
  20 + parent::__construct($config);
  21 + }
  22 +
  23 + public function add(int $product_variant_id, int $count)
  24 + {
  25 + $data = $this->getData();
  26 + if(array_key_exists($product_variant_id, $data)) {
  27 + $data[ $product_variant_id ][ 'count' ] += $count;
  28 + if($data[$product_variant_id]['count'] <= 0) {
  29 + unset($data[$product_variant_id]);
  30 + }
  31 + } else {
  32 + $model = $this->findModel($product_variant_id);
  33 + $data[ $product_variant_id ] = [
  34 + 'price' => $model->price,
  35 + 'count' => $count,
  36 + ];
  37 + }
  38 + $this->setData($data);
  39 + }
  40 +
  41 + public function set(int $product_variant_id, int $count)
  42 + {
  43 + $data = $this->getData();
  44 + if(array_key_exists($product_variant_id, $data)) {
  45 + $data[ $product_variant_id ][ 'count' ] = $count;
  46 + if($data[$product_variant_id]['count'] <= 0) {
  47 + unset($data[$product_variant_id]);
  48 + }
  49 + } else {
  50 + $model = $this->findModel($product_variant_id);
  51 + $data[ $product_variant_id ] = [
  52 + 'price' => $model->price,
  53 + 'count' => $count,
  54 + ];
  55 + }
  56 + $this->setData($data);
  57 + }
  58 +
  59 + public function getData(): array
  60 + {
  61 + return $this->session->get('basket');
  62 + }
  63 +
  64 + public function getItem(int $product_variant_id) {
  65 + $data = $this->getData();
  66 + if(!empty($data[$product_variant_id])) {
  67 + return $data[$product_variant_id];
  68 + } else {
  69 + return false;
  70 + }
  71 + }
  72 +
  73 + public function setData(array $data)
  74 + {
  75 + $this->session->set('basket', $data);
  76 + }
  77 +
  78 + public function getSum(): float
  79 + {
  80 + $data = $this->getData();
  81 + $sum = 0;
  82 + foreach($data as $item) {
  83 + $sum += $item[ 'price' ] * $item[ 'count' ];
  84 + }
  85 + return $sum;
  86 + }
  87 +
  88 + public function getCount(): int {
  89 + $data = $this->getData();
  90 + return count($data);
  91 + }
  92 +
  93 + public function findModel(int $product_variant_id): ProductVariant
  94 + {
  95 + $model = ProductVariant::find()
  96 + ->where([ 'product_variant_id' => $product_variant_id ])
  97 + ->one();
  98 + if(empty( $model )) {
  99 + throw new NotFoundHttpException('Product not found');
  100 + } else {
  101 + return $model;
  102 + }
  103 + }
  104 +
  105 + public function findModels(array $product_variant_ids)
  106 + {
  107 + return ProductVariant::find()
  108 + ->where([ 'product_variant_id' => $product_variant_ids ])
  109 + ->with([
  110 + 'product',
  111 + 'image',
  112 + ])
  113 + ->all();
  114 + }
  115 +
  116 + public function getModal(): string
  117 + {
  118 + $output = '';
  119 + $data = $this->getData();
  120 + $models = $this->findModels(array_keys($this->getData()));
  121 + if(!empty( $models )) {
  122 + $output = \Yii::$app->view->renderFile('@frontend/views/basket/modal_items.php', [
  123 + 'models' => $models,
  124 + 'basket' => $this,
  125 + ]);
  126 + }
  127 + return $output;
  128 + }
  129 + }
0 \ No newline at end of file 130 \ No newline at end of file
common/modules/product/controllers/ManageController.php
@@ -80,7 +80,7 @@ class ManageController extends Controller @@ -80,7 +80,7 @@ class ManageController extends Controller
80 public function actionCreate() 80 public function actionCreate()
81 { 81 {
82 $model = new Product(); 82 $model = new Product();
83 - 83 +
84 if ($model->load(Yii::$app->request->post())) { 84 if ($model->load(Yii::$app->request->post())) {
85 $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); 85 $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload');
86 86
frontend/assets/AppAsset.php
@@ -23,7 +23,9 @@ class AppAsset extends AssetBundle @@ -23,7 +23,9 @@ class AppAsset extends AssetBundle
23 ]; 23 ];
24 public $js = [ 24 public $js = [
25 'js/js_head.js', 25 'js/js_head.js',
26 - 'js/js_footer.js' 26 + //'js/js_footer.js',
  27 + '/js/artbox_basket.js',
  28 + 'js/script.js',
27 ]; 29 ];
28 public $depends = [ 30 public $depends = [
29 'yii\web\JqueryAsset', 31 'yii\web\JqueryAsset',
frontend/controllers/BasketController.php 0 → 100755
  1 +<?php
  2 +
  3 +namespace frontend\controllers;
  4 +
  5 +use common\models\Basket;
  6 +use yii\web\Response;
  7 +
  8 +class BasketController extends \yii\web\Controller
  9 +{
  10 + public $enableCsrfValidation = false;
  11 + public function actionIndex() {
  12 + $response = \Yii::$app->response;
  13 + $response->format = Response::FORMAT_JSON;
  14 + /**
  15 + * @var Basket $basket
  16 + */
  17 + $basket = \Yii::$app->basket;
  18 + $result = [
  19 + 'basket' => $basket->getData(),
  20 + ];
  21 + return $result;
  22 + }
  23 + public function actionAdd(int $product_variant_id, int $count) {
  24 + $response = \Yii::$app->response;
  25 + $response->format = Response::FORMAT_JSON;
  26 + /**
  27 + * @var Basket $basket
  28 + */
  29 + $basket = \Yii::$app->basket;
  30 + $basket->add($product_variant_id, $count);
  31 + $result = [
  32 + 'basket' => $basket->getData(),
  33 + 'modal' => $basket->getModal(),
  34 + ];
  35 + return $result;
  36 + }
  37 + public function actionSet(int $product_variant_id, int $count) {
  38 + $response = \Yii::$app->response;
  39 + $response->format = Response::FORMAT_JSON;
  40 + /**
  41 + * @var Basket $basket
  42 + */
  43 + $basket = \Yii::$app->basket;
  44 + $basket->set($product_variant_id, $count);
  45 + $result = [
  46 + 'basket' => $basket->getData(),
  47 + 'modal' => $basket->getModal(),
  48 + ];
  49 + return $result;
  50 + }
  51 + public function actionTest() {
  52 + /**
  53 + * @var Basket $basket
  54 + */
  55 + $basket = \Yii::$app->basket;
  56 + $modal = $basket->getModal();
  57 + return $modal;
  58 + }
  59 +}
frontend/controllers/CatalogController.php
@@ -125,6 +125,7 @@ class CatalogController extends \yii\web\Controller @@ -125,6 +125,7 @@ class CatalogController extends \yii\web\Controller
125 */ 125 */
126 $query = $productProvider->query; 126 $query = $productProvider->query;
127 $query->with([ 127 $query->with([
  128 + 'variant',
128 'comments', 129 'comments',
129 'averageRating', 130 'averageRating',
130 ]); 131 ]);
frontend/views/basket/modal_items.php 0 → 100644
  1 +<?php
  2 + use common\models\Basket;
  3 + use common\modules\product\models\ProductVariant;
  4 + use yii\helpers\Html;
  5 + use yii\web\View;
  6 +
  7 + /**
  8 + * @var View $this
  9 + * @var ProductVariant[] $models
  10 + * @var Basket $basket
  11 + */
  12 +?>
  13 +<div class="modal-dialog buy-product" role="document">
  14 + <div class="modal-content">
  15 + <div class="modal-header">
  16 + <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  17 + <span aria-hidden="true">&times;</span>
  18 + </button>
  19 + <div class="modal-title" id="myModalLabel">
  20 + <div class="h3">
  21 + <span class="cart-icon"></span>
  22 + <a href="#"><span class="cart_count"><?php echo $basket->getCount(); ?></span> товар(ов)</a>
  23 + на сумму
  24 + <span class="cart_total"><?php echo $basket->getSum(); ?></span><span class="currency">&nbsp;<!--грн.--></span>
  25 + </div>
  26 + </div>
  27 +
  28 + </div>
  29 +
  30 + <div class="modal-body">
  31 +
  32 + <table class="tovar">
  33 + <tbody>
  34 + <?php
  35 + foreach($models as $model) {
  36 + ?>
  37 + <tr data-id="<?php echo $model->product_variant_id; ?>">
  38 + <td class="left">
  39 + <?php
  40 + echo Html::img($model->getImageUrl());
  41 + ?>
  42 + </td>
  43 + <td class="right">
  44 + <div class="title"><?php echo $model->getFullname();?></div>
  45 + <div class="count_choise">
  46 + <span class="minus"></span>
  47 + <input type="text" name="count" value="<?php echo $basket->getItem($model->product_variant_id)['count'];?>" class="prod_count">
  48 + <span class="plus"></span>
  49 + <span class="total_summ">= <span class="total_prod">
  50 + <?php
  51 + $item = $basket->getItem($model->product_variant_id);
  52 + echo $item['count'] * $item['price'];
  53 + ?>
  54 + </span><span class="currency">&nbsp;<!--грн.--></span></span>
  55 + </div>
  56 + <input type="hidden" name="prod_id" value="" id="prod_id">
  57 + </td>
  58 + </tr>
  59 + <?php
  60 + }
  61 + ?>
  62 + <tr>
  63 + <td class="left">
  64 + <a href="ordering.htm" class="btn">Оформить заказ</a>
  65 + </td>
  66 + <td class="right">
  67 + <div class="back_to_shop">
  68 + <a data-dismiss="modal" aria-label="Close" href="javascript:false">продолжить покупки</a>
  69 + </div>
  70 + <p class="rettext">товар сохранится в корзине</p>
  71 + </td>
  72 + </tr>
  73 + </tbody>
  74 + </table>
  75 + <br/>
  76 +
  77 + </div>
  78 +
  79 + <div class="modal-footer">
  80 +
  81 + <div class="gray_part" id="buy_back_call_form">
  82 + <p class="title">Заказать без оформления</p>
  83 + <p class="subtitle">Можно не заполнять никаких форм, просто оставить телефон и консультант решит все вопросы по оформлению заказа.</p>
  84 + <div class="back_call_form">
  85 + <input type="tel" class="customerphone" name="customerphone" value="" placeholder="+38 (0XX) XXX-XX-XX">
  86 + <span class="btn btn-gray disabled" id="buy_back_call_submit" disabled1="disabled1">жду звонка</span>
  87 + <span class="submit_indicator"></span>
  88 + <div class="clr"></div>
  89 + </div>
  90 + <p class="phone-example">например: +38 (095) 282-85-08</p>
  91 + </div>
  92 +
  93 + </div>
  94 +
  95 + </div>
  96 +</div>
0 \ No newline at end of file 97 \ No newline at end of file
frontend/views/catalog/_product_item.php
1 <?php 1 <?php
2 -/** @var $model common\modules\product\models\Product */  
3 -  
4 - 2 + /**
  3 + * @var $model common\modules\product\models\Product
  4 + */
5 use yii\helpers\Html; 5 use yii\helpers\Html;
6 use yii\helpers\Url; 6 use yii\helpers\Url;
7 -  
8 ?> 7 ?>
9 <div class="catalog_item"> 8 <div class="catalog_item">
10 <div class="wrapper"> 9 <div class="wrapper">
@@ -25,7 +24,7 @@ use yii\helpers\Url; @@ -25,7 +24,7 @@ use yii\helpers\Url;
25 ]) ?> 24 ]) ?>
26 </a> 25 </a>
27 <div class="info_icons"> 26 <div class="info_icons">
28 - <a href="#" class="btn buy_button" data-toggle="modal" data-target="#buyForm" lang="145">Купить светильник </a> 27 + <a href="#" class="btn buy_button" data-toggle="modal" data-target="#buyForm" data-id="<?=$model->variant->product_variant_id; ?>" lang="145">Купить светильник </a>
29 <ul class="ul wishlike_block hidden"> 28 <ul class="ul wishlike_block hidden">
30 <li class="compare hidden"> 29 <li class="compare hidden">
31 <a onclick="add2compare(); return false;" class="compare compare_text_link_3631483" href="#">К сравнению</a> 30 <a onclick="add2compare(); return false;" class="compare compare_text_link_3631483" href="#">К сравнению</a>
@@ -41,43 +40,30 @@ use yii\helpers\Url; @@ -41,43 +40,30 @@ use yii\helpers\Url;
41 <div class="dlexfduinxipi"> 40 <div class="dlexfduinxipi">
42 Цена: 41 Цена:
43 <span class="main"> 42 <span class="main">
44 -  
45 - 932.40 43 + 932.40
46 <span class="currency">грн</span> 44 <span class="currency">грн</span>
47 -  
48 </span> 45 </span>
49 </div> 46 </div>
50 </div> 47 </div>
51 <div class="additional_info params"> 48 <div class="additional_info params">
52 <div class="additional_title" style="display: none;"><a href="http://www.linija-svitla.ua/podvesnoy-svetilnik-massive-41782-53-10-145.htm">Люстры Massive 41782/53/10</a></div> 49 <div class="additional_title" style="display: none;"><a href="http://www.linija-svitla.ua/podvesnoy-svetilnik-massive-41782-53-10-145.htm">Люстры Massive 41782/53/10</a></div>
53 <div class="block_product_status av" title="70 1"> 50 <div class="block_product_status av" title="70 1">
54 -  
55 есть на складе 51 есть на складе
56 </div> 52 </div>
57 <div class="block_title">Особенности</div> 53 <div class="block_title">Особенности</div>
58 <div class="descr"> 54 <div class="descr">
59 <div class="info"> 55 <div class="info">
60 <ul class="sv"> 56 <ul class="sv">
61 -  
62 -  
63 <li><span>Тип:</span> подвесной светильник</li> 57 <li><span>Тип:</span> подвесной светильник</li>
64 -  
65 -  
66 <li><span>Бренд:</span> Massive</li> 58 <li><span>Бренд:</span> Massive</li>
67 -  
68 <li><span>Модель: </span>41782/53/10</li> 59 <li><span>Модель: </span>41782/53/10</li>
69 -  
70 -  
71 <li><span>кол-во ламп: </span>1</li> 60 <li><span>кол-во ламп: </span>1</li>
72 <li><span>цоколь: </span>E27</li> 61 <li><span>цоколь: </span>E27</li>
73 <li><span>мощность: </span>max. 60W</li> 62 <li><span>мощность: </span>max. 60W</li>
74 <li><span>высота: </span>1250</li> 63 <li><span>высота: </span>1250</li>
75 <li><span>ширина: </span>275</li> 64 <li><span>ширина: </span>275</li>
76 <li><span>выступающая часть: </span>275</li> 65 <li><span>выступающая часть: </span>275</li>
77 -  
78 -  
79 </ul> 66 </ul>
80 -  
81 </div> 67 </div>
82 <div class="clearfix"></div> 68 <div class="clearfix"></div>
83 </div> 69 </div>
@@ -85,18 +71,13 @@ use yii\helpers\Url; @@ -85,18 +71,13 @@ use yii\helpers\Url;
85 <div class="dlexfduinxipi"> 71 <div class="dlexfduinxipi">
86 Цена: 72 Цена:
87 <span class="main"> 73 <span class="main">
88 -  
89 - 932.40 74 + 932.40
90 <span class="currency">грн</span> 75 <span class="currency">грн</span>
91 -  
92 </span> 76 </span>
93 </div> 77 </div>
94 </div> 78 </div>
95 </div> 79 </div>
96 <div class="opacity_bg"></div> 80 <div class="opacity_bg"></div>
97 -  
98 -  
99 -  
100 </div> 81 </div>
101 </div> 82 </div>
102 </div> 83 </div>
103 \ No newline at end of file 84 \ No newline at end of file
frontend/views/catalog/product.php
@@ -292,7 +292,7 @@ @@ -292,7 +292,7 @@
292 292
293 293
294 <!--href="#/*http://www.linija-svitla.ua/ordering.htm*/"--> 294 <!--href="#/*http://www.linija-svitla.ua/ordering.htm*/"-->
295 - <a lang="5892" class="btn btnBuy buy_button btn-large1" data-toggle="modal" data-target="#buyForm"> 295 + <a lang="5892" class="btn btnBuy buy_button btn-large1" data-id="<?php echo $product->variant->product_variant_id;?>" data-toggle="modal" data-target="#buyForm">
296 296
297 Купить светильник 297 Купить светильник
298 298
@@ -413,7 +413,7 @@ @@ -413,7 +413,7 @@
413 </div> 413 </div>
414 414
415 <div class="buy_button"> 415 <div class="buy_button">
416 - <a href="#" class="btn btn-large buy_button" data-toggle="modal" data-target="#buyForm" lang="5892">Купить светильник </a> 416 + <a href="#" class="btn btn-large buy_button" data-toggle="modal" data-id="<?php echo $product->variant->product_variant_id; ?>" data-target="#buyForm" lang="5892">Купить светильник </a>
417 <div class="payment_visa"> 417 <div class="payment_visa">
418 Оплатить 418 Оплатить
419 <a href="payment.htm#privat" target="_blank"> 419 <a href="payment.htm#privat" target="_blank">
@@ -1319,7 +1319,7 @@ @@ -1319,7 +1319,7 @@
1319 <img src="http://www.linija-svitla.ua/gallery/prod/fe_leila3/5893_5.jpg" alt="люстра FE/LEILA3" class="selected"> 1319 <img src="http://www.linija-svitla.ua/gallery/prod/fe_leila3/5893_5.jpg" alt="люстра FE/LEILA3" class="selected">
1320 </a> 1320 </a>
1321 <div class="info_icons"> 1321 <div class="info_icons">
1322 - <a href="#" class="btn btnBuy buy_button" data-toggle="modal" data-target="#buyForm" lang="5893">Купить светильник</a> 1322 + <a href="#" class="btn btnBuy buy_button" data-id="<?php echo $product->variant->product_variant_id; ?>" data-toggle="modal" data-target="#buyForm" lang="5893">Купить светильник</a>
1323 <ul class="ul wishlike_block"> 1323 <ul class="ul wishlike_block">
1324 <li class="compare"> 1324 <li class="compare">
1325 <a onclick="add2compare(); return false;" class="compare compare_text_link_5893" lang="5893" href="#">К сравнению</a> 1325 <a onclick="add2compare(); return false;" class="compare compare_text_link_5893" lang="5893" href="#">К сравнению</a>
@@ -1361,7 +1361,7 @@ @@ -1361,7 +1361,7 @@
1361 <img src="http://www.linija-svitla.ua/gallery/prod/fe_leila1c/6991_5.jpg" alt=" FE/LEILA1C" class="selected"> 1361 <img src="http://www.linija-svitla.ua/gallery/prod/fe_leila1c/6991_5.jpg" alt=" FE/LEILA1C" class="selected">
1362 </a> 1362 </a>
1363 <div class="info_icons"> 1363 <div class="info_icons">
1364 - <a href="#" class="btn btnBuy buy_button" data-toggle="modal" data-target="#buyForm" lang="6991">Купить светильник</a> 1364 + <a href="#" class="btn btnBuy buy_button" data-toggle="modal" data-id="<?php echo $product->variant->product_variant_id; ?>" data-target="#buyForm" lang="6991">Купить светильник</a>
1365 <ul class="ul wishlike_block"> 1365 <ul class="ul wishlike_block">
1366 <li class="compare"> 1366 <li class="compare">
1367 <a onclick="add2compare(); return false;" class="compare compare_text_link_6991" lang="6991" href="#">К сравнению</a> 1367 <a onclick="add2compare(); return false;" class="compare compare_text_link_6991" lang="6991" href="#">К сравнению</a>
@@ -1403,7 +1403,7 @@ @@ -1403,7 +1403,7 @@
1403 <img src="http://www.linija-svitla.ua/gallery/prod/fe_leila2/5894_5.jpg" alt="настенный светильник FE/LEILA2" class="selected"> 1403 <img src="http://www.linija-svitla.ua/gallery/prod/fe_leila2/5894_5.jpg" alt="настенный светильник FE/LEILA2" class="selected">
1404 </a> 1404 </a>
1405 <div class="info_icons"> 1405 <div class="info_icons">
1406 - <a href="#" class="btn btnBuy buy_button" data-toggle="modal" data-target="#buyForm" lang="5894">Купить светильник</a> 1406 + <a href="#" class="btn btnBuy buy_button" data-id="<?php echo $product->variant->product_variant_id; ?>" data-toggle="modal" data-target="#buyForm" lang="5894">Купить светильник</a>
1407 <ul class="ul wishlike_block"> 1407 <ul class="ul wishlike_block">
1408 <li class="compare"> 1408 <li class="compare">
1409 <a onclick="add2compare(); return false;" class="compare compare_text_link_5894" lang="5894" href="#">К сравнению</a> 1409 <a onclick="add2compare(); return false;" class="compare compare_text_link_5894" lang="5894" href="#">К сравнению</a>
frontend/views/catalog/products.php
1 <?php 1 <?php
2 -/** @var $productProvider \yii\data\ActiveDataProvider */ 2 + /**
  3 + * @var $productProvider \yii\data\ActiveDataProvider
  4 + * @var View $this
  5 + */
3 use frontend\widgets\FilterWidget; 6 use frontend\widgets\FilterWidget;
4 -use yii\widgets\ListView;  
5 -  
6 -  
7 - 7 + use yii\web\View;
  8 + use yii\widgets\ListView;
8 ?> 9 ?>
9 <!-- Табы для слайдера --> 10 <!-- Табы для слайдера -->
10 <div class="bigSlidertabs fixed" style="position:fixed;"> 11 <div class="bigSlidertabs fixed" style="position:fixed;">
frontend/views/layouts/main.php
@@ -157,7 +157,6 @@ AppAsset::register($this); @@ -157,7 +157,6 @@ AppAsset::register($this);
157 <div id="top-cart-content"> 157 <div id="top-cart-content">
158 <p class="empty-cart">Корзина пуста</p> 158 <p class="empty-cart">Корзина пуста</p>
159 </div> 159 </div>
160 -  
161 </div> 160 </div>
162 <div class="clearfix"></div> 161 <div class="clearfix"></div>
163 </div> 162 </div>
frontend/web/js/artbox_basket.js 0 → 100644
  1 +var ArtboxBasket = (function () {
  2 + function ArtboxBasket() {
  3 + $.get('/basket', function (data) {
  4 + this._items = data.basket;
  5 + }.bind(this), 'json').fail(function () {
  6 + console.error('Basket cannot be init');
  7 + });
  8 + }
  9 + Object.defineProperty(ArtboxBasket.prototype, "items", {
  10 + get: function () {
  11 + return this._items;
  12 + },
  13 + enumerable: true,
  14 + configurable: true
  15 + });
  16 + ArtboxBasket.prototype.add = function (product_variant_id, count) {
  17 + $.post('/basket/add?product_variant_id=' + product_variant_id + '&count=' + count, function (data) {
  18 + this._items = data.basket;
  19 + this.updateModal(data.modal, true);
  20 + }.bind(this), 'json').fail(function (xhr, status, error) {
  21 + console.error(error);
  22 + });
  23 + };
  24 + ArtboxBasket.prototype.set = function (product_variant_id, count) {
  25 + $.post('/basket/set?product_variant_id=' + product_variant_id + '&count=' + count, function (data) {
  26 + this._items = data.basket;
  27 + this.updateModal(data.modal);
  28 + }.bind(this), 'json').fail(function (xhr, status, error) {
  29 + console.error(error);
  30 + });
  31 + };
  32 + ArtboxBasket.prototype.updateModal = function (modal, show) {
  33 + if (show === void 0) { show = false; }
  34 + var modalBox = $('#buyForm');
  35 + modalBox.html(modal);
  36 + if (show) {
  37 + modalBox.modal('show');
  38 + }
  39 + this.updateCart();
  40 + };
  41 + ArtboxBasket.prototype.updateCart = function () {
  42 + var cart = $('#top-cart-content');
  43 + var count = this.count;
  44 + if (count > 0) {
  45 + $(cart).html('<a href="ordering.htm"><span class="in_the_cart">В корзине</span><span id="in_cart_col">' + count + ' товар' + ((count > 4) ? 'ов' : ((count > 1) ? 'а' : '')) + '</span><br/><span id="in_cart_sum">на ' + this.sum + ' </span><br/></a><div id="in_cart_a"><a class="btn" href="ordering.htm">оформить покупку</a></div>');
  46 + }
  47 + else {
  48 + }
  49 + };
  50 + Object.defineProperty(ArtboxBasket.prototype, "count", {
  51 + get: function () {
  52 + return Object.keys(this._items).length;
  53 + },
  54 + enumerable: true,
  55 + configurable: true
  56 + });
  57 + Object.defineProperty(ArtboxBasket.prototype, "sum", {
  58 + get: function () {
  59 + var sum = 0;
  60 + $.each(this._items, function (index, value) {
  61 + sum += value.price * value.count;
  62 + });
  63 + return sum;
  64 + },
  65 + enumerable: true,
  66 + configurable: true
  67 + });
  68 + return ArtboxBasket;
  69 +}());
  70 +//# sourceMappingURL=artbox_basket.js.map
0 \ No newline at end of file 71 \ No newline at end of file
frontend/web/js/artbox_basket.js.map 0 → 100644
  1 +{"version":3,"file":"artbox_basket.js","sourceRoot":"","sources":["artbox_basket.ts"],"names":[],"mappings":"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"}
0 \ No newline at end of file 2 \ No newline at end of file
frontend/web/js/artbox_basket.ts 0 → 100644
  1 +class ArtboxBasket {
  2 + private _items;
  3 + get items() {
  4 + return this._items;
  5 + }
  6 + constructor() {
  7 + $.get('/basket', function (data) {
  8 + this._items = data.basket;
  9 + }.bind(this), 'json').fail(function() {
  10 + console.error('Basket cannot be init');
  11 + });
  12 + }
  13 + public add(product_variant_id, count) {
  14 + $.post('/basket/add?product_variant_id='+product_variant_id+'&count='+count, function (data) {
  15 + this._items = data.basket;
  16 + this.updateModal(data.modal, true);
  17 + }.bind(this), 'json').fail(function (xhr, status, error) {
  18 + console.error(error);
  19 + });
  20 + }
  21 + public set(product_variant_id, count) {
  22 + $.post('/basket/set?product_variant_id='+product_variant_id+'&count='+count, function (data) {
  23 + this._items = data.basket;
  24 + this.updateModal(data.modal);
  25 + }.bind(this), 'json').fail(function (xhr, status, error) {
  26 + console.error(error);
  27 + });
  28 + }
  29 + public updateModal(modal, show = false)
  30 + {
  31 + var modalBox = $('#buyForm');
  32 + modalBox.html(modal);
  33 + if(show) {
  34 + modalBox.modal('show');
  35 + }
  36 + this.updateCart();
  37 + }
  38 + public updateCart() {
  39 + var cart = $('#top-cart-content');
  40 + var count = this.count;
  41 + if(count > 0) {
  42 + $(cart).html('<a href="ordering.htm"><span class="in_the_cart">В корзине</span><span id="in_cart_col">' + count + ' товар' + ((count > 4) ? 'ов' : ((count > 1) ? 'а' : '')) + '</span><br/><span id="in_cart_sum">на ' + this.sum + ' </span><br/></a><div id="in_cart_a"><a class="btn" href="ordering.htm">оформить покупку</a></div>');
  43 + } else {
  44 +
  45 + }
  46 + }
  47 + get count(): number {
  48 + return Object.keys(this._items).length;
  49 + }
  50 + get sum(): number {
  51 + var sum = 0;
  52 + $.each(this._items, function(index, value) {
  53 + sum += value.price * value.count;
  54 + });
  55 + return sum;
  56 + }
  57 +}
0 \ No newline at end of file 58 \ No newline at end of file
frontend/web/js/js_head.js
@@ -3516,48 +3516,48 @@ $(document).ready(function() { @@ -3516,48 +3516,48 @@ $(document).ready(function() {
3516 }, 'slow'); 3516 }, 'slow');
3517 return false; 3517 return false;
3518 }); 3518 });
3519 - $(document).on("click", '.plus', function() {  
3520 - var input = $(this).parent().find('input');  
3521 - var sp = parseFloat($(input).val());  
3522 - if (sp > 100) {  
3523 - $(this).parent().find('.minus').attr('class', '').addClass('plus-disabled');  
3524 - $(input).val(sp + 1);  
3525 - } else if (sp >= 0 && sp < 100) {  
3526 - $(this).parent().find('.minus-disabled').attr('class', '').addClass('minus');  
3527 - $(input).val(sp + 1);  
3528 - }  
3529 - if (typeof save_cart == 'function') {  
3530 - if (!$(input).hasClass('qtyInput')) {  
3531 - save_cart($("#buyForm #prod_id").val(), $("#buyForm input.prod_count").val());  
3532 - } else {  
3533 - save_cart($(input).prop('lang'), $(input).val(), $(this).closest("table.order_details"));  
3534 - }  
3535 - }  
3536 - });  
3537 - $(document).on("click", '.minus', function() {  
3538 - var input = $(this).parent().find('input');  
3539 - var sp = parseFloat($(input).val());  
3540 - if (sp > 2 && sp < 100) {  
3541 - $(input).val(sp - 1);  
3542 - } else if (sp = 2) {  
3543 - $(this).parent().find('.minus').attr('class', '').addClass('minus-disabled');  
3544 - $(input).val(sp - 1);  
3545 - }  
3546 - if (typeof save_cart == 'function')  
3547 - if (!$(input).hasClass('qtyInput')) {  
3548 - save_cart($("#buyForm #prod_id").val(), $("#buyForm input.prod_count").val());  
3549 - } else {  
3550 - save_cart($(input).prop('lang'), $(input).val(), $(this).closest("table.order_details"));  
3551 - }  
3552 - });  
3553 - $(".count_choise input").keydown(function(e) {  
3554 - if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 || (e.keyCode == 65 && e.ctrlKey === true) || (e.keyCode >= 35 && e.keyCode <= 39)) {  
3555 - return;  
3556 - }  
3557 - if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {  
3558 - e.preventDefault();  
3559 - }  
3560 - }); 3519 +// $(document).on("click", '.plus', function() {
  3520 +// var input = $(this).parent().find('input');
  3521 +// var sp = parseFloat($(input).val());
  3522 +// if (sp > 100) {
  3523 +// $(this).parent().find('.minus').attr('class', '').addClass('plus-disabled');
  3524 +// $(input).val(sp + 1);
  3525 +// } else if (sp >= 0 && sp < 100) {
  3526 +// $(this).parent().find('.minus-disabled').attr('class', '').addClass('minus');
  3527 +// $(input).val(sp + 1);
  3528 +// }
  3529 +// if (typeof save_cart == 'function') {
  3530 +// if (!$(input).hasClass('qtyInput')) {
  3531 +// save_cart($("#buyForm #prod_id").val(), $("#buyForm input.prod_count").val());
  3532 +// } else {
  3533 +// save_cart($(input).prop('lang'), $(input).val(), $(this).closest("table.order_details"));
  3534 +// }
  3535 +// }
  3536 +// });
  3537 +// $(document).on("click", '.minus', function() {
  3538 +// var input = $(this).parent().find('input');
  3539 +// var sp = parseFloat($(input).val());
  3540 +// if (sp > 2 && sp < 100) {
  3541 +// $(input).val(sp - 1);
  3542 +// } else if (sp = 2) {
  3543 +// $(this).parent().find('.minus').attr('class', '').addClass('minus-disabled');
  3544 +// $(input).val(sp - 1);
  3545 +// }
  3546 +// if (typeof save_cart == 'function')
  3547 +// if (!$(input).hasClass('qtyInput')) {
  3548 +// save_cart($("#buyForm #prod_id").val(), $("#buyForm input.prod_count").val());
  3549 +// } else {
  3550 +// save_cart($(input).prop('lang'), $(input).val(), $(this).closest("table.order_details"));
  3551 +// }
  3552 +// });
  3553 +// $(".count_choise input").keydown(function(e) {
  3554 +// if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 || (e.keyCode == 65 && e.ctrlKey === true) || (e.keyCode >= 35 && e.keyCode <= 39)) {
  3555 +// return;
  3556 +// }
  3557 +// if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  3558 +// e.preventDefault();
  3559 +// }
  3560 +// });
3561 $('.properties_block .block_title').on('click', function() { 3561 $('.properties_block .block_title').on('click', function() {
3562 properties_block = $(this).parent(); 3562 properties_block = $(this).parent();
3563 if (properties_block.hasClass('closed')) { 3563 if (properties_block.hasClass('closed')) {
frontend/web/js/script.js 0 → 100644
  1 +var artbox_basket = new ArtboxBasket();
  2 +$(document).on('click', '.buy_button', function(e) {
  3 + e.preventDefault();
  4 + var product_variant_id = $(this).data('id');
  5 + var count = 1;
  6 + artbox_basket.add(product_variant_id, count);
  7 +});
  8 +$(document).on('change', '#buyForm .prod_count', function(e) {
  9 + e.preventDefault();
  10 + var product_variant_id = $(this).parents('tr').data('id');
  11 + var value = $(this).val();
  12 + if(value < 0) {
  13 + value = 0;
  14 + }
  15 + artbox_basket.set(product_variant_id, value);
  16 +});
  17 +$(document).on('click', '#buyForm .count_choise .minus', function(e) {
  18 + e.preventDefault();
  19 + var container = $(this).parents('tr');
  20 + var input = $(container).find('.prod_count');
  21 + var value = $(input).val();
  22 + var new_value = parseInt(value) - 1;
  23 + $(input).val(new_value);
  24 + $(input).trigger('change');
  25 +});
  26 +$(document).on('click', '#buyForm .count_choise .plus', function(e) {
  27 + e.preventDefault();
  28 + var container = $(this).parents('tr');
  29 + var input = $(container).find('.prod_count');
  30 + var value = $(input).val();
  31 + var new_value = parseInt(value) + 1;
  32 + $(input).val(new_value);
  33 + $(input).trigger('change');
  34 +});
0 \ No newline at end of file 35 \ No newline at end of file