731adb96
Alex Savenko
remarketing
|
1
2
3
4
5
6
7
8
9
10
|
<?php
/**
* Created by PhpStorm.
* User: Alex Savenko
* Date: 05.12.2016
* Time: 18:36
*/
namespace console\controllers;
|
e71d5d51
Alex Savenko
remarketing
|
11
|
use yii\console\Controller;
|
731adb96
Alex Savenko
remarketing
|
12
|
use Yii;
|
fd068f14
Alex Savenko
remarketing
|
13
|
use yii\helpers\Url;
|
fd068f14
Alex Savenko
remarketing
|
14
|
use yii\web\NotFoundHttpException;
|
e71d5d51
Alex Savenko
remarketing
|
15
|
use common\modules\product\models\Product;
|
731adb96
Alex Savenko
remarketing
|
16
17
18
19
20
21
22
|
class FeedController extends Controller
{
private $urlList = [];
private $count = 1;
|
e71d5d51
Alex Savenko
remarketing
|
23
24
25
|
public function getProducts() {
return Product::find()->all();
}
|
731adb96
Alex Savenko
remarketing
|
26
|
|
e71d5d51
Alex Savenko
remarketing
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
public function checkUrl($url){
if(!in_array($url, $this->urlList)){
$this->urlList[] = $url;
return true;
} else {
return false;
}
}
public function createRow( $product, &$content ){
$url = Url::to(['catalog/product', 'product' => $product]);
if($this->checkUrl($url)){
print $this->count++ . "\n";
$content[] = $url;
}
}
|
731adb96
Alex Savenko
remarketing
|
43
44
45
46
47
48
49
|
public function actionProcess() {
$dirName = Yii::getAlias('@frontend').'/web';
$filename = 'feed.csv';
setlocale(LC_ALL, 'ru_RU.CP1251');
|
0cd58f97
Alex Savenko
remarketing
|
50
|
$handle = fopen($dirName .'/'. $filename, "w");
|
731adb96
Alex Savenko
remarketing
|
51
|
|
0cd58f97
Alex Savenko
remarketing
|
52
53
54
55
56
|
$content = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
|
e71d5d51
Alex Savenko
remarketing
|
57
58
59
60
61
62
63
64
65
66
|
$content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price'];
$content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price'];
// foreach ($this->getProducts() as $product) {
// $this->createRow($product, $content);
// }
foreach ($content as $item) {
fputcsv($handle, $item);
}
|
0cd58f97
Alex Savenko
remarketing
|
67
|
fclose($handle);
|
731adb96
Alex Savenko
remarketing
|
68
69
70
71
|
print $dirName .'/'. $filename;
}
}
|