731adb96
Alex Savenko
remarketing
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
class FeedController extends Controller
{
private $urlList = [];
private $count = 1;
public function getProducts() {
return Product::find()->all();
}
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."\r\n";
}
}
public function actionProcess() {
$dirName = Yii::getAlias('@frontend').'/web';
$filename = 'feed.csv';
setlocale(LC_ALL, 'ru_RU.CP1251');
$handle = fopen($dirName .'/'. $filename, "w");
$content = 'ID, ID2, Item Category, Item title, Item description, Price'."\r\n";
foreach ($this->getProducts() as $product) {
$this->createRow($product, $content);
}
$content .= '</urlset>';
fwrite($handle, $content);
fclose($handle);
print $dirName .'/'. $filename;
}
}
|