Blame view

frontend/controllers/SiteController.php 7.05 KB
3f2bc3d0   Administrator   first commit
1
  <?php
7ba4acc5   Administrator   after marge
2
  
3f2bc3d0   Administrator   first commit
3
4
  namespace frontend\controllers;
  
0ff57d01   Administrator   image size
5
  use common\modules\product\models\Category;
02e6c2ba   Karnovsky A   -
6
7
8
  use common\modules\product\models\CategorySearch;
  use common\modules\product\models\Product;
  use common\modules\product\models\ProductVariant;
3f2bc3d0   Administrator   first commit
9
  use Yii;
3f2bc3d0   Administrator   first commit
10
  use yii\web\Controller;
7ba4acc5   Administrator   after marge
11
12
13
14
  use common\models\Page;
  use common\models\News;
  use common\models\Catalog;
  use common\models\Products;
3f2bc3d0   Administrator   first commit
15
  
3f2bc3d0   Administrator   first commit
16
17
  class SiteController extends Controller
  {
ccc7a9d3   Karnovsky A   Karnovsky 12052016
18
19
20
21
22
23
24
25
26
      /**
       * @inheritdoc
       */
      public function actions()
      {
          return [
              'thumb' => 'iutbay\yii2imagecache\ThumbAction',
          ];
      }
055ecc3b   Karnovsky A   Karnovsky 11052016
27
  
3f2bc3d0   Administrator   first commit
28
29
      public function actionIndex()
      {
055ecc3b   Karnovsky A   Karnovsky 11052016
30
  
7ba4acc5   Administrator   after marge
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  //            $catalogs = Catalog::find()->where(['parent_id'=>'0'])->all();
          $modelText = Page::find()->where(['translit'=>'home'])->one();
  //            $news = News::find()->orderBy('id DESC')->limit(4)->all();
  //            $products_new = Products::find()->where(['new'=>'1'])->orderBy('id DESC')->innerJoinWith(['cost'])->groupBy('id')->limit(4)->all();
  //            //print_r($products_new);
  //            $products_top = Products::find()->where(['top'=>'1'])->orderBy('id DESC')->innerJoinWith(['cost'])->groupBy('id')->limit(4)->all();
  //            //print_r($products_top);
  //            //$products_sale = Products::find()->where(['sale'=>'1'])->innerJoinWith(['cost'])->orderBy('id DESC')->limit(4)->all();
  //            $products_akciya = Products::find()->where(['akciya'=>'1'])->innerJoinWith(['cost'])->orderBy('id DESC')->limit(4)->all();
          return $this->render('index', [
              'text'=>$modelText,
  //                    'catalogs'=>$catalogs,
  //                    'news'=>$news,
  //                    'products_new'=>$products_new,
  //                    'products_top'=>$products_top,
  //                    'products_akciya'=>$products_akciya,
055ecc3b   Karnovsky A   Karnovsky 11052016
47
          ]);
3f2bc3d0   Administrator   first commit
48
      }
055ecc3b   Karnovsky A   Karnovsky 11052016
49
  
7ba4acc5   Administrator   after marge
50
      public function actionError(){
055ecc3b   Karnovsky A   Karnovsky 11052016
51
  
7ba4acc5   Administrator   after marge
52
53
54
          return $this->render('error', [
              'code'=>Yii::$app->errorHandler->exception->statusCode,
              'message'=>Yii::$app->errorHandler->exception->getMessage(),
055ecc3b   Karnovsky A   Karnovsky 11052016
55
56
57
          ]);
      }
  
0ff57d01   Administrator   image size
58
59
      public function actionPriceparam ()
      {
02e6c2ba   Karnovsky A   -
60
61
62
63
          $category_alias = Yii::$app->request->get('category');
          $is_count = Yii::$app->request->get('count', false);
  
          if ( !($category = CategorySearch::findByAlias($category_alias)))
0ff57d01   Administrator   image size
64
          {
02e6c2ba   Karnovsky A   -
65
              throw new HttpException(404, 'Данной страницы не существует!');
0ff57d01   Administrator   image size
66
67
          }
  
02e6c2ba   Karnovsky A   -
68
          $products = $category->products;
0ff57d01   Administrator   image size
69
  
02e6c2ba   Karnovsky A   -
70
71
72
          if ($is_count) {
              print (count($products));
              exit;
0ff57d01   Administrator   image size
73
          }
02e6c2ba   Karnovsky A   -
74
  
0ff57d01   Administrator   image size
75
76
77
78
79
80
81
82
83
84
85
          set_time_limit (0);
          header ("Content-Type: text/xml");
          print '<?xml version="1.0" encoding="UTF-8" ?>';
          print "<price>";
          print "<date>" . date ("Y-m-d h:m") . "</date>";
          print "<firmName>Rukzachok</firmName>";
          print "<firmId></firmId>";
          print "<rate></rate>";
          print "<categories>";
  
          print "<category>";
02e6c2ba   Karnovsky A   -
86
          print "<id>" . $category->category_id . "</id>";
0ff57d01   Administrator   image size
87
          print "<parentId></parentId>";
02e6c2ba   Karnovsky A   -
88
          print "<name>" . $category->name . "</name>";
0ff57d01   Administrator   image size
89
90
91
92
93
          print "</category>";
  
  
          print "</categories>";
          print "<items>";
02e6c2ba   Karnovsky A   -
94
95
96
97
          /** @var Product $product */
          foreach ($products as $product) {
              /** @var ProductVariant $variant */
              foreach ($product->enabledVariants as $variant) {
0ff57d01   Administrator   image size
98
  
0ff57d01   Administrator   image size
99
                  print "<item>";
02e6c2ba   Karnovsky A   -
100
101
102
103
104
105
106
107
108
109
                  print "<id>" . htmlspecialchars($variant->product_variant_id) . "</id>";
                  print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>";
                  print "<vendor>" . $product->brand->name . "</vendor>";
                  print "<code>" . htmlspecialchars($variant->sku) . "</code>";
                  print "<typeprefix>" . htmlspecialchars(substr($category->name, 0, -2)) . " </typeprefix>";
                  print "<name>" . htmlspecialchars($product->name) . "  </name>";
                  print "<param>" . $variant->name . " </param>";
                  print "<description>" . htmlspecialchars($product->description) . "</description>";
                  print "<url>http://rukzachok.com.ua{$product->url}#{$variant->product_variant_id}</url>";
                  print "<image>http://rukzachok.com.ua{$variant->imageUrl}</image>";
61bae627   Administrator   image size
110
111
                  print "<priceRUAH>" . $variant->price . "</priceRUAH>";
                  print "<oldprice>" . $variant->price_old . "</oldprice>";
0ff57d01   Administrator   image size
112
113
114
115
                  print "<priceRUSD></priceRUSD>";
                  print "<stock>В наличии</stock>";
                  print "<guarantee></guarantee>";
                  print "</item>";
0ff57d01   Administrator   image size
116
117
              }
          }
0ff57d01   Administrator   image size
118
119
120
          print "</items>";
  
          print "</price>";
0ff57d01   Administrator   image size
121
122
123
124
      }
  
      public function actionPrice()
      {
02e6c2ba   Karnovsky A   -
125
126
          $category_alias = Yii::$app->request->get('category');
          $is_count = Yii::$app->request->get('count', false);
0ff57d01   Administrator   image size
127
  
02e6c2ba   Karnovsky A   -
128
          if ( !($category = CategorySearch::findByAlias($category_alias)))
0ff57d01   Administrator   image size
129
          {
02e6c2ba   Karnovsky A   -
130
              throw new HttpException(404, 'Данной страницы не существует!');
0ff57d01   Administrator   image size
131
132
          }
  
02e6c2ba   Karnovsky A   -
133
          $products = $category->products;
0ff57d01   Administrator   image size
134
  
02e6c2ba   Karnovsky A   -
135
136
137
138
          if ($is_count) {
              print (count($products));
              exit;
          }
0ff57d01   Administrator   image size
139
  
0ff57d01   Administrator   image size
140
  
0ff57d01   Administrator   image size
141
142
143
144
145
146
147
148
149
150
151
152
  //var_dump($products);die();
          set_time_limit (0);
          header ("Content-Type: text/xml");
          print '<?xml version="1.0" encoding="UTF-8" ?>';
          print "<price>";
          print "<date>" . date ("Y-m-d h:m") . "</date>";
          print "<firmName>Rukzachok</firmName>";
          print "<firmId></firmId>";
          print "<rate></rate>";
          print "<categories>";
  
          print "<category>";
02e6c2ba   Karnovsky A   -
153
          print "<id>" . $category->category_id . "</id>";
0ff57d01   Administrator   image size
154
          print "<parentId></parentId>";
02e6c2ba   Karnovsky A   -
155
          print "<name>" . $category->name . "</name>";
0ff57d01   Administrator   image size
156
157
158
159
          print "</category>";
  
          print "</categories>";
          print "<items>";
02e6c2ba   Karnovsky A   -
160
          /** @var Product $product */
0ff57d01   Administrator   image size
161
162
          foreach ($products as $product)
          {
02e6c2ba   Karnovsky A   -
163
164
              /** @var ProductVariant $variant */
              foreach ($product->enabledVariants as $variant) {
0ff57d01   Administrator   image size
165
166
  
                  print "<item>";
02e6c2ba   Karnovsky A   -
167
168
169
170
171
172
173
174
                  print "<id>" . htmlspecialchars($variant->product_variant_id) . "</id>";
                  print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>";
                  print "<vendor>" . $product->brand->name . "</vendor>";
                  print "<code>" . htmlspecialchars($variant->sku) . "</code>";
                  print "<name>" . htmlspecialchars($product->name) . " </name>";
                  print "<description>" . htmlspecialchars($product->description) . "</description>";
                  print "<url>http://rukzachok.com.ua{$product->url}#{$variant->product_variant_id}</url>";
                  print "<image>http://rukzachok.com.ua{$variant->imageUrl}</image>";
61bae627   Administrator   image size
175
176
                  print "<priceRUAH>" . $variant->price . "</priceRUAH>";
                  print "<oldprice>" . $variant->price_old . "</oldprice>";
0ff57d01   Administrator   image size
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
                  print "<priceRUSD></priceRUSD>";
                  print "<stock>В наличии</stock>";
                  print "<guarantee></guarantee>";
                  print "</item>";
  
              }
          }
  
  
          print "</items>";
  
          print "</price>";
  
  
      }
ccc7a9d3   Karnovsky A   Karnovsky 12052016
192
193
  
  
7ba4acc5   Administrator   after marge
194
  }