Commit 1c8ebc9119f11afe2d80d1cccd3a3d2a08dc51b6
1 parent
00629bc9
Share functional
Showing
9 changed files
with
53 additions
and
58 deletions
Show diff stats
common/models/Share.php
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | namespace common\models; |
4 | 4 | |
5 | +use common\modules\product\models\Product; | |
5 | 6 | use Yii; |
6 | 7 | |
7 | 8 | class Share extends \yii\db\ActiveRecord |
... | ... | @@ -22,8 +23,8 @@ class Share extends \yii\db\ActiveRecord |
22 | 23 | |
23 | 24 | public function beforeSave($insert) { |
24 | 25 | $this->user_id = Yii::$app->user->id; |
25 | - $this->date_time = time(); | |
26 | - $this->date = new \yii\db\Expression('NOW()'); | |
26 | + $this->date_time = date('Y-m-d H:i:s'); | |
27 | + $this->date = date('Y-m-d'); | |
27 | 28 | return parent::beforeSave($insert); |
28 | 29 | } |
29 | 30 | |
... | ... | @@ -33,7 +34,7 @@ class Share extends \yii\db\ActiveRecord |
33 | 34 | |
34 | 35 | public function getProduct() |
35 | 36 | { |
36 | - return $this->hasOne(Products::className(), ['id' => 'product_id']); | |
37 | + return $this->hasOne(Product::className(), ['product_id' => 'product_id']); | |
37 | 38 | } |
38 | 39 | |
39 | 40 | public function getShareList() | ... | ... |
frontend/controllers/IamController.php
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | namespace frontend\controllers; |
4 | 4 | |
5 | +use common\models\ShareSearch; | |
5 | 6 | use Yii; |
6 | 7 | use yii\web\Controller; |
7 | 8 | use yii\filters\AccessControl; |
... | ... | @@ -94,37 +95,43 @@ class IamController extends Controller |
94 | 95 | } |
95 | 96 | |
96 | 97 | public function actionShare(){ |
97 | - if(!empty($_GET['id'])){ | |
98 | + if(Yii::$app->request->get('id')) { | |
98 | 99 | if(!$model = Share::find()->where('user_id=:user_id and product_id=:product_id',[':user_id'=>Yii::$app->user->id,':product_id'=>$_GET['id']])->one()) |
99 | 100 | $model = new Share; |
100 | 101 | |
101 | - $model->product_id = $_GET['id']; | |
102 | + $model->product_id = Yii::$app->request->get('id'); | |
102 | 103 | $model->save(); |
103 | 104 | |
104 | 105 | Yii::$app->getSession()->setFlash('success', 'Этот товар добавлен в закладку!'); |
105 | 106 | return $this->redirect(Yii::$app->request->referrer); |
106 | 107 | } |
107 | - else{ | |
108 | + else { | |
108 | 109 | /* $dataProvider = new ActiveDataProvider([ |
109 | 110 | 'query' => Share::find()->where(['user_id'=>Yii::$app->user->id])->orderBy('date_time DESC'), |
110 | 111 | 'pagination' => [ |
111 | 112 | 'pageSize' => 20, |
112 | 113 | ], |
113 | 114 | ]);*/ |
114 | - if(!empty($_GET['deleteID'])){ | |
115 | - $model = Share::find()->where(['user_id'=>Yii::$app->user->id,'id'=>$_GET['deleteID']])->one(); | |
115 | + if(Yii::$app->request->get('deleteID')) { | |
116 | + $model = Share::find()->where(['user_id'=>Yii::$app->user->id,'id'=>Yii::$app->request->get('deleteID')])->one(); | |
116 | 117 | $model->delete(); |
117 | 118 | return $this->redirect(Yii::$app->request->referrer); |
118 | 119 | } |
119 | - $query = Share::find()->where(['user_id'=>Yii::$app->user->id])->groupBy('date')->orderBy('date DESC'); | |
120 | + | |
121 | + $items = []; | |
122 | + foreach(Share::find()->where(['user_id' => Yii::$app->user->id])->all() as $item) { | |
123 | + $items[$item->date][] = $item; | |
124 | + } | |
125 | + | |
126 | + /* $query = Share::find()->where(['user_id'=>Yii::$app->user->id])->groupBy('date')->orderBy('date DESC'); | |
120 | 127 | $countQuery = clone $query; |
121 | 128 | $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize'=>20]); |
122 | 129 | $pages->forcePageParam = false; |
123 | 130 | $pages->pageSizeParam = false; |
124 | 131 | $share = $query->offset($pages->offset) |
125 | 132 | ->limit($pages->limit) |
126 | - ->all(); | |
127 | - return $this->render('share',['share'=>$share,'pages'=>$pages]); | |
133 | + ->all();*/ | |
134 | + return $this->render('share', ['items' => $items]); | |
128 | 135 | } |
129 | 136 | } |
130 | 137 | ... | ... |
frontend/views/catalog/product.php
... | ... | @@ -125,6 +125,21 @@ $this->registerJs (" |
125 | 125 | <a href="#" rel='product' class="link_buy fl">В Корзину</a> |
126 | 126 | <div class="both"></div> |
127 | 127 | </div> |
128 | + | |
129 | + <div class="product_service"> | |
130 | + <ul> | |
131 | + <?php if (Yii::$app->user->id) :?> | |
132 | + <li class="item1"><a href="<?= Url::to (['iam/share', 'id' => $product->product_id]) ?>">Добавить в закладки</a></li> | |
133 | + <?php endif?> | |
134 | + <?php if (FALSE && Yii::$app->user->id) :?> | |
135 | + <li class="item2"><a href="<?= Url::to (['iam/price', 'id' => $product->product_id]) ?>">Узнать о снижение цены</a></li> | |
136 | + <?php endif?> | |
137 | + <?php if (FALSE) :?> | |
138 | + <li class="item3"><a href="<?= Url::to (['products/compare', 'id' => $product->product_id]) ?>">Добавить в сравнение</a></li> | |
139 | + <?php endif?> | |
140 | + </ul> | |
141 | + </div> | |
142 | + | |
128 | 143 | </div> |
129 | 144 | <?php /* |
130 | 145 | <div class="product_service"> | ... | ... |
frontend/views/iam/1person.php
... | ... | @@ -23,12 +23,7 @@ $this->title = 'Профиль'; |
23 | 23 | <div class="leftbar"> |
24 | 24 | <div class="mycabinet"> |
25 | 25 | <div class="begin">Мой кабинет</div> |
26 | - <ul> | |
27 | - <li>Личные данные</li> | |
28 | - <li><a href="<?=Url::to(['iam/myorders'])?>">Мои заказы</a></li> | |
29 | - <!--<li><a href="<?=Url::to(['iam/share'])?>">Закладки</a></li>--> | |
30 | - <li><a href="<?=Url::to(['iam/price'])?>">Пожелания</a></li> | |
31 | - </ul> | |
26 | + <?= $this->render('_tabs')?> | |
32 | 27 | </div> |
33 | 28 | </div> |
34 | 29 | ... | ... |
1 | +<ul> | |
2 | + <li><a href="<?=\yii\helpers\Url::to(['iam/index'])?>">Личные данные</a></li> | |
3 | + <li><a href="<?=\yii\helpers\Url::to(['iam/myorders'])?>">Мои заказы</a></li> | |
4 | + <li><a href="<?=\yii\helpers\Url::to(['iam/share'])?>">Закладки</a></li> | |
5 | + <!--li><a href="<?=\yii\helpers\Url::to(['iam/price'])?>">Пожелания</a></li--> | |
6 | +</ul> | |
0 | 7 | \ No newline at end of file | ... | ... |
frontend/views/iam/edit_person.php
... | ... | @@ -31,12 +31,7 @@ $('#user-phone').mask('(000) 000-0000'); |
31 | 31 | <div class="leftbar"> |
32 | 32 | <div class="mycabinet"> |
33 | 33 | <div class="begin">Мой кабинет</div> |
34 | - <ul> | |
35 | - <li><a href="<?=Url::to(['iam/index'])?>">Личные данные</a></li> | |
36 | - <li><a href="<?=Url::to(['iam/myorders'])?>">Мои заказы</a></li> | |
37 | - <!--<li><a href="<?=Url::to(['iam/share'])?>">Закладки</a></li>--> | |
38 | - <!--li><a href="<?=Url::to(['iam/price'])?>">Пожелания</a></li--> | |
39 | - </ul> | |
34 | + <?= $this->render('_tabs')?> | |
40 | 35 | </div> |
41 | 36 | </div> |
42 | 37 | ... | ... |
frontend/views/iam/myorders.php
... | ... | @@ -32,12 +32,7 @@ $this->registerJs(" |
32 | 32 | <div class="leftbar"> |
33 | 33 | <div class="mycabinet"> |
34 | 34 | <div class="begin">Мой кабинет</div> |
35 | - <ul> | |
36 | - <li><a href="<?=Url::to(['iam/index'])?>">Личные данные</a></li> | |
37 | - <li><a href="<?=Url::to(['iam/myorders'])?>" class="active">Мои заказы</a></li> | |
38 | - <!--<li><a href="<?=Url::to(['iam/share'])?>">Закладки</a></li>--> | |
39 | - <!--li><a href="<?=Url::to(['iam/price'])?>">Пожелания</a></li--> | |
40 | - </ul> | |
35 | + <?= $this->render('_tabs')?> | |
41 | 36 | </div> |
42 | 37 | </div> |
43 | 38 | ... | ... |
frontend/views/iam/person.php
... | ... | @@ -22,12 +22,7 @@ $this->title = 'Профиль'; |
22 | 22 | <div class="leftbar"> |
23 | 23 | <div class="mycabinet"> |
24 | 24 | <div class="begin">Мой кабинет</div> |
25 | - <ul> | |
26 | - <li><a href="<?=Url::to(['iam/index'])?>" class="active">Личные данные</a></li> | |
27 | - <li><a href="<?=Url::to(['iam/myorders'])?>">Мои заказы</a></li> | |
28 | - <!--<li><a href="<?=Url::to(['iam/share'])?>">Закладки</a></li>--> | |
29 | - <!--li><a href="<?=Url::to(['iam/price'])?>">Пожелания</a></li--> | |
30 | - </ul> | |
25 | + <?= $this->render('_tabs')?> | |
31 | 26 | </div> |
32 | 27 | </div> |
33 | 28 | ... | ... |
frontend/views/iam/share.php
... | ... | @@ -31,35 +31,28 @@ $this->registerJs(" |
31 | 31 | <div class="leftbar"> |
32 | 32 | <div class="mycabinet"> |
33 | 33 | <div class="begin">Мой кабинет</div> |
34 | - <ul> | |
35 | - <li><a href="<?=Url::to(['iam/index'])?>">Личные данные</a></li> | |
36 | - <li><a href="<?=Url::to(['iam/myorders'])?>">Мои заказы</a></li> | |
37 | - <!--<li><a href="<?=Url::to(['iam/share'])?>">Закладки</a></li>--> | |
38 | - <!--li><a href="<?=Url::to(['iam/price'])?>">Пожелания</a></li--> | |
39 | - </ul> | |
34 | + <?= $this->render('_tabs')?> | |
40 | 35 | </div> |
41 | 36 | </div> |
42 | 37 | |
43 | 38 | <div class="content"> |
44 | - | |
45 | - | |
46 | 39 | <div class="favorites"> |
47 | 40 | <div style="margin-top:-5px;"> |
48 | - <?foreach($share as $key=>$item):?> | |
41 | + <?php $i=0; foreach($items as $date=>$_items): $i++;?> | |
49 | 42 | <div class="fav_point"> |
50 | - <div class="left"><a href="#" class="link">№ <?=$key+1?></a></div> | |
51 | - <div class="left"><?=$item->date?></div> | |
43 | + <div class="left"><a href="#" class="link">№ <?=$i?></a></div> | |
44 | + <div class="left"><?= $date?></div> | |
52 | 45 | <div class="both"></div> |
53 | 46 | |
54 | 47 | <div class="orders_view"> |
55 | - <?foreach($item->shareList as $item_p):if(!empty($item_p->product)):?> | |
48 | + <?foreach($_items as $item_p):if(!empty($item_p->product)):?> | |
56 | 49 | <div class="order"> |
57 | 50 | <div><a href="<?=Url::to(['iam/share','deleteID'=>$item_p->id])?>" class="delete_button"></a></div> |
58 | - <div class="pixbox"><a href="<?=Url::to(['products/show','translit_rubric'=>$item_p->product->catalog->translit,'translit'=>$item_p->product->translit,'id'=>$item_p->product->id])?>"> | |
51 | + <div class="pixbox"><a href="<?=Url::to(['catalog/product', 'product' => $item_p->product])?>"> | |
59 | 52 | <?= \common\components\artboximage\ArtboxImageHelper::getImage($item_p->product->imageUrl, 'iam')?> |
60 | 53 | </div> |
61 | - <div class="order_title"><a href="<?=Url::to(['products/show','translit_rubric'=>$item_p->product->catalog->translit,'translit'=>$item_p->product->translit,'id'=>$item_p->product->id])?>" class="name"><?=$item_p->product->name?></a></div> | |
62 | - <?if(!empty($item_p->product->cost->cost)):?><div class="order_price"><span><?=$item_p->product->cost->cost?></span> грн.</div><?endif;?> | |
54 | + <div class="order_title"><a href="<?=Url::to(['catalog/product', 'product' => $item_p->product])?>" class="name"><?=$item_p->product->name?></a></div> | |
55 | + <?if(!empty($item_p->product->variants[0])):?><div class="order_price"><span><?=$item_p->product->variants[0]->price?></span> грн.</div><?endif;?> | |
63 | 56 | <p class="note"></p> |
64 | 57 | </div> |
65 | 58 | <?endif;endforeach;?> |
... | ... | @@ -67,15 +60,8 @@ $this->registerJs(" |
67 | 60 | </div> |
68 | 61 | </div> |
69 | 62 | <?endforeach;?> |
70 | - | |
71 | 63 | </div> |
72 | - | |
73 | 64 | </div> |
74 | - | |
75 | - | |
76 | - | |
77 | - | |
78 | - | |
79 | - | |
80 | 65 | </div> |
66 | + <div class="both"></div> | |
81 | 67 | </div> | ... | ... |