Commit ceb083b9369c43efb156debfe7cbdeb313d50d28
1 parent
efb63a77
price.xml PriceController in console
Showing
4 changed files
with
181 additions
and
145 deletions
Show diff stats
.htaccess
@@ -131,6 +131,8 @@ AddDefaultCharset utf-8 | @@ -131,6 +131,8 @@ AddDefaultCharset utf-8 | ||
131 | 131 | ||
132 | RewriteRule sitemap.xml$ frontend/web/sitemap.xml [L] | 132 | RewriteRule sitemap.xml$ frontend/web/sitemap.xml [L] |
133 | 133 | ||
134 | + RewriteRule price.xml$ frontend/web/price.xml [L] | ||
135 | + | ||
134 | RewriteRule feed.csv$ frontend/web/feed.csv [L] | 136 | RewriteRule feed.csv$ frontend/web/feed.csv [L] |
135 | 137 | ||
136 | RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|txt|js|images|fonts|img|files)/ | 138 | RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|txt|js|images|fonts|img|files)/ |
1 | +<?php | ||
2 | + /** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: timur | ||
5 | + * Date: 26.06.17 | ||
6 | + * Time: 12:56 | ||
7 | + */ | ||
8 | + | ||
9 | + /** | ||
10 | + * @var \common\modules\product\models\Category $categories | ||
11 | + */ | ||
12 | + | ||
13 | + namespace console\controllers; | ||
14 | + | ||
15 | + use \yii\console\Controller; | ||
16 | + use common\modules\product\models\Category; | ||
17 | + use Yii; | ||
18 | + use yii\helpers\Console; | ||
19 | + | ||
20 | + class PriceController extends Controller | ||
21 | + { | ||
22 | + public function actionProcess() | ||
23 | + { | ||
24 | + $contentOfPriceXML = ''; | ||
25 | + | ||
26 | +// $is_count = Yii::$app->request->get('count', false); | ||
27 | + | ||
28 | + $categories = Category::find()->all(); | ||
29 | + | ||
30 | + $this->stdout('Start!' . "\n", Console::FG_RED); | ||
31 | + | ||
32 | +// set_time_limit(0); | ||
33 | +// header("Content-Type: text/xml"); | ||
34 | +// $contentOfPriceXML .= '<?xml version="1.0" encoding="UTF-8" ? >'; | ||
35 | + $contentOfPriceXML .= "<price>"; | ||
36 | + $contentOfPriceXML .= "<date>" . date("Y-m-d h:m") . "</date>"; | ||
37 | + $contentOfPriceXML .= "<firmName>www.linija-svitla.ua</firmName>"; | ||
38 | + $contentOfPriceXML .= "<firmId></firmId>"; | ||
39 | + $contentOfPriceXML .= "<rate></rate>"; | ||
40 | + $contentOfPriceXML .= "<categories>"; | ||
41 | + | ||
42 | + foreach ($categories as $category) { | ||
43 | + $contentOfPriceXML .= "<category>"; | ||
44 | + $contentOfPriceXML .= "<id>" . $category->category_id . "</id>"; | ||
45 | + $contentOfPriceXML .= "<name>" . $category->name . "</name>"; | ||
46 | + $contentOfPriceXML .= "</category>"; | ||
47 | + } | ||
48 | + $contentOfPriceXML .= "</categories>"; | ||
49 | + | ||
50 | + $contentOfPriceXML .= "<items>"; | ||
51 | + | ||
52 | + foreach ($categories as $category) { | ||
53 | + | ||
54 | + $this->stdout("in Process category"."\n", Console::FG_BLUE); | ||
55 | + | ||
56 | + $products = $category->getProducts() | ||
57 | + ->with( | ||
58 | + [ | ||
59 | +// 'filters', | ||
60 | + 'filters.group' | ||
61 | + ] | ||
62 | + ) | ||
63 | + ->joinWith('variant') | ||
64 | + ->where([ 'product_variant.status' => 0 ]) | ||
65 | + ->andWhere('product_variant.stock<>0') | ||
66 | + ->andWhere('product_variant.price<>0') | ||
67 | + ->all(); | ||
68 | + | ||
69 | +// if ($is_count) { | ||
70 | + $contentOfPriceXML .= ( count($products) ); | ||
71 | +// continue; | ||
72 | +// } | ||
73 | + | ||
74 | + /** @var Product $product */ | ||
75 | + | ||
76 | + foreach ($products as $product) { | ||
77 | + /** | ||
78 | + * Fix for emty brands 14.03.2017 | ||
79 | + */ | ||
80 | + | ||
81 | + $this->stdout("in Process product"."\n", Console::FG_GREEN); | ||
82 | + | ||
83 | + if (empty($product->brand)) { | ||
84 | + continue; | ||
85 | + } | ||
86 | + | ||
87 | + $contentOfPriceXML .= "<item>"; | ||
88 | + $contentOfPriceXML .= "<id>" . htmlspecialchars($product->variant->product_variant_id) . "</id>"; | ||
89 | + $contentOfPriceXML .= "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>"; | ||
90 | + $contentOfPriceXML .= "<vendor>" . $product->brand->name . "</vendor>"; | ||
91 | + $contentOfPriceXML .= "<code>" . htmlspecialchars($product->variant->sku) . "</code>"; | ||
92 | + $contentOfPriceXML .= "<name>" . htmlspecialchars($product->name) . " " . htmlspecialchars( | ||
93 | + $product->variant->name | ||
94 | + ) . " </name>"; | ||
95 | + $contentOfPriceXML .= "<description>" . htmlspecialchars($product->description) . "</description>"; | ||
96 | + $contentOfPriceXML .= "<url>http://www.linija-svitla.ua{$product->url}</url>"; | ||
97 | + $contentOfPriceXML .= "<image>http://www.linija-svitla.ua{$product->variant->imageUrl}</image>"; | ||
98 | + $contentOfPriceXML .= "<priceRUAH>" . $product->variant->price . "</priceRUAH>"; | ||
99 | + $contentOfPriceXML .= "<oldprice>" . $product->variant->price_old . "</oldprice>"; | ||
100 | + | ||
101 | + $type = false; | ||
102 | + foreach ($product->filters as $filter) { | ||
103 | + | ||
104 | + if ($filter->group->name == "Тип точечного освещение:") { | ||
105 | + $type = true; | ||
106 | + $contentOfPriceXML .= "<param name='Тип'>{$filter->name}</param>"; | ||
107 | + } | ||
108 | + if ($filter->group->name == "Тип настенного освещения:") { | ||
109 | + $type = true; | ||
110 | + $contentOfPriceXML .= "<param name='Тип'>{$filter->name}</param>"; | ||
111 | + } | ||
112 | + | ||
113 | + if ($filter->group->name == "Тип потолочного освещения:") { | ||
114 | + $type = true; | ||
115 | + $contentOfPriceXML .= "<param name='Тип'>{$filter->name}</param>"; | ||
116 | + } | ||
117 | + | ||
118 | + if ($filter->group->name == "Тип уличного освещения:") { | ||
119 | + $type = true; | ||
120 | + $contentOfPriceXML .= "<param name='Тип'>{$filter->name}</param>"; | ||
121 | + } | ||
122 | + | ||
123 | + if ($filter->group->name == "Тип лампочки:") { | ||
124 | + $type = true; | ||
125 | + $contentOfPriceXML .= "<param name='Тип'>{$filter->name}</param>"; | ||
126 | + } | ||
127 | + | ||
128 | + if ($filter->group->name == "Назначение:") { | ||
129 | + $contentOfPriceXML .= "<param name='Назначение'>{$filter->name}</param>"; | ||
130 | + } | ||
131 | + if ($filter->group->name == "Стиль:") { | ||
132 | + $contentOfPriceXML .= "<param name='Стиль'>{$filter->name}</param>"; | ||
133 | + } | ||
134 | + if ($filter->group->name == "Количество лампочек:") { | ||
135 | + $contentOfPriceXML .= "<param name='Количество источников света'>{$filter->name}</param>"; | ||
136 | + } | ||
137 | + if ($filter->group->name == "Тип источника света:") { | ||
138 | + $contentOfPriceXML .= "<param name='Тип источника освещения'>{$filter->name}</param>"; | ||
139 | + } | ||
140 | + if ($filter->group->name == "Цоколь:") { | ||
141 | + $contentOfPriceXML .= "<param name='Тип цоколя'>{$filter->name}</param>"; | ||
142 | + } | ||
143 | + //$contentOfPriceXML .= "<param name='Монтаж'>Припотолочная</param>"; | ||
144 | + | ||
145 | + } | ||
146 | + | ||
147 | + if (!$type) { | ||
148 | + $contentOfPriceXML .= "<param name='Тип'>{$product->category->name}</param>"; | ||
149 | + } | ||
150 | + | ||
151 | + $contentOfPriceXML .= "<priceRUSD></priceRUSD>"; | ||
152 | + $contentOfPriceXML .= "<stock>В наличии</stock>"; | ||
153 | + $contentOfPriceXML .= "<guarantee></guarantee>"; | ||
154 | + $contentOfPriceXML .= "</item>"; | ||
155 | + | ||
156 | + } | ||
157 | + | ||
158 | + } | ||
159 | + | ||
160 | + //var_dump($products);die(); | ||
161 | + | ||
162 | + | ||
163 | + | ||
164 | + | ||
165 | + $contentOfPriceXML .= "</items>"; | ||
166 | + | ||
167 | + $contentOfPriceXML .= "</price>"; | ||
168 | + | ||
169 | + $this->stdout('End!' . "\n", Console::FG_RED); | ||
170 | + | ||
171 | + $file = fopen(Yii::getAlias('@frontend/web/price.xml'), 'w+'); | ||
172 | + fwrite($file, $contentOfPriceXML); | ||
173 | + fclose($file); | ||
174 | + | ||
175 | + } | ||
176 | + } | ||
0 | \ No newline at end of file | 177 | \ No newline at end of file |
frontend/config/main.php
@@ -76,7 +76,7 @@ return [ | @@ -76,7 +76,7 @@ return [ | ||
76 | 76 | ||
77 | 'cabinet/main' => '/cabinet/main', | 77 | 'cabinet/main' => '/cabinet/main', |
78 | 'priceparam.xml' => 'site/priceparam', | 78 | 'priceparam.xml' => 'site/priceparam', |
79 | - 'price.xml' => 'site/price', | 79 | +// 'price.xml' => 'site/price', |
80 | 'smstest' => 'site/sms', | 80 | 'smstest' => 'site/sms', |
81 | 'search/main' => 'search/main', | 81 | 'search/main' => 'search/main', |
82 | 'news/<translit:\w+>' => 'news/show', | 82 | 'news/<translit:\w+>' => 'news/show', |
frontend/controllers/SiteController.php
@@ -15,6 +15,7 @@ use yii\helpers\ArrayHelper; | @@ -15,6 +15,7 @@ use yii\helpers\ArrayHelper; | ||
15 | use yii\web\BadRequestHttpException; | 15 | use yii\web\BadRequestHttpException; |
16 | use yii\web\Controller; | 16 | use yii\web\Controller; |
17 | 17 | ||
18 | +use yii\web\HttpException; | ||
18 | use yii\web\Response; | 19 | use yii\web\Response; |
19 | use yii\widgets\ActiveForm; | 20 | use yii\widgets\ActiveForm; |
20 | 21 | ||
@@ -218,148 +219,5 @@ class SiteController extends Controller | @@ -218,148 +219,5 @@ class SiteController extends Controller | ||
218 | 219 | ||
219 | print "</price>"; | 220 | print "</price>"; |
220 | } | 221 | } |
221 | - | ||
222 | - public function actionPrice() | ||
223 | - { | ||
224 | - | ||
225 | - | ||
226 | - | ||
227 | - $is_count = Yii::$app->request->get('count', false); | ||
228 | - | ||
229 | - $categories = Category::find()->all(); | ||
230 | - | ||
231 | - set_time_limit (0); | ||
232 | - header ("Content-Type: text/xml"); | ||
233 | - print '<?xml version="1.0" encoding="UTF-8" ?>'; | ||
234 | - print "<price>"; | ||
235 | - print "<date>" . date ("Y-m-d h:m") . "</date>"; | ||
236 | - print "<firmName>www.linija-svitla.ua</firmName>"; | ||
237 | - print "<firmId></firmId>"; | ||
238 | - print "<rate></rate>"; | ||
239 | - print "<categories>"; | ||
240 | - | ||
241 | - foreach($categories as $category){ | ||
242 | - print "<category>"; | ||
243 | - print "<id>" .$category->category_id . "</id>"; | ||
244 | - print "<name>" . $category->name. "</name>"; | ||
245 | - print "</category>"; | ||
246 | - } | ||
247 | - print "</categories>"; | ||
248 | - | ||
249 | - | ||
250 | - | ||
251 | - | ||
252 | - print "<items>"; | ||
253 | - | ||
254 | - foreach($categories as $category){ | ||
255 | - $products = $category->getProducts()->with(['filters','filters.group'])->joinWith('variant')->where(['product_variant.status'=>0])->all(); | ||
256 | - | ||
257 | - if ($is_count) { | ||
258 | - print (count($products)); | ||
259 | - continue; | ||
260 | - } | ||
261 | - | ||
262 | - /** @var Product $product */ | ||
263 | - | ||
264 | - foreach ($products as $product) | ||
265 | - { | ||
266 | - /** | ||
267 | - * Fix for emty brands 14.03.2017 | ||
268 | - */ | ||
269 | - if (empty($product->brand)) continue; | ||
270 | - | ||
271 | - print "<item>"; | ||
272 | - print "<id>" . htmlspecialchars($product->variant->product_variant_id) . "</id>"; | ||
273 | - print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>"; | ||
274 | - print "<vendor>" . $product->brand->name . "</vendor>"; | ||
275 | - print "<code>" . htmlspecialchars($product->variant->sku) . "</code>"; | ||
276 | - print "<name>" . htmlspecialchars($product->name)." " .htmlspecialchars($product->variant->name). " </name>"; | ||
277 | - print "<description>" . htmlspecialchars($product->description) . "</description>"; | ||
278 | - print "<url>http://www.linija-svitla.ua{$product->url}</url>"; | ||
279 | - print "<image>http://www.linija-svitla.ua{$product->variant->imageUrl}</image>"; | ||
280 | - print "<priceRUAH>" . $product->variant->price . "</priceRUAH>"; | ||
281 | - print "<oldprice>" . $product->variant->price_old . "</oldprice>"; | ||
282 | - | ||
283 | - $type = false; | ||
284 | - foreach( $product->filters as $filter){ | ||
285 | - | ||
286 | - | ||
287 | - | ||
288 | - if($filter->group->name == "Тип точечного освещение:"){ | ||
289 | - $type = true; | ||
290 | - print "<param name='Тип'>{$filter->name}</param>"; | ||
291 | - } | ||
292 | - if($filter->group->name == "Тип настенного освещения:"){ | ||
293 | - $type = true; | ||
294 | - print "<param name='Тип'>{$filter->name}</param>"; | ||
295 | - } | ||
296 | - | ||
297 | - if($filter->group->name == "Тип потолочного освещения:"){ | ||
298 | - $type = true; | ||
299 | - print "<param name='Тип'>{$filter->name}</param>"; | ||
300 | - } | ||
301 | - | ||
302 | - | ||
303 | - if($filter->group->name == "Тип уличного освещения:"){ | ||
304 | - $type = true; | ||
305 | - print "<param name='Тип'>{$filter->name}</param>"; | ||
306 | - } | ||
307 | - | ||
308 | - if($filter->group->name == "Тип лампочки:"){ | ||
309 | - $type = true; | ||
310 | - print "<param name='Тип'>{$filter->name}</param>"; | ||
311 | - } | ||
312 | - | ||
313 | - | ||
314 | - | ||
315 | - | ||
316 | - if($filter->group->name == "Назначение:"){ | ||
317 | - print "<param name='Назначение'>{$filter->name}</param>"; | ||
318 | - } | ||
319 | - if($filter->group->name == "Стиль:"){ | ||
320 | - print "<param name='Стиль'>{$filter->name}</param>"; | ||
321 | - } | ||
322 | - if($filter->group->name == "Количество лампочек:"){ | ||
323 | - print "<param name='Количество источников света'>{$filter->name}</param>"; | ||
324 | - } | ||
325 | - if($filter->group->name == "Тип источника света:"){ | ||
326 | - print "<param name='Тип источника освещения'>{$filter->name}</param>"; | ||
327 | - } | ||
328 | - if($filter->group->name == "Цоколь:"){ | ||
329 | - print "<param name='Тип цоколя'>{$filter->name}</param>"; | ||
330 | - } | ||
331 | - //print "<param name='Монтаж'>Припотолочная</param>"; | ||
332 | - | ||
333 | - } | ||
334 | - | ||
335 | - if(!$type){ | ||
336 | - print "<param name='Тип'>{$product->category->name}</param>"; | ||
337 | - } | ||
338 | - | ||
339 | - | ||
340 | - print "<priceRUSD></priceRUSD>"; | ||
341 | - print "<stock>В наличии</stock>"; | ||
342 | - print "<guarantee></guarantee>"; | ||
343 | - print "</item>"; | ||
344 | - | ||
345 | - | ||
346 | - } | ||
347 | - | ||
348 | - } | ||
349 | - | ||
350 | - | ||
351 | - | ||
352 | - | ||
353 | - | ||
354 | -//var_dump($products);die(); | ||
355 | - | ||
356 | - | ||
357 | - | ||
358 | - | ||
359 | - print "</items>"; | ||
360 | - | ||
361 | - print "</price>"; | ||
362 | - | ||
363 | - | ||
364 | - } | 222 | + |
365 | } | 223 | } |