diff --git a/console/controllers/FeedController.php b/console/controllers/FeedController.php new file mode 100644 index 0000000..7a1e6ef --- /dev/null +++ b/console/controllers/FeedController.php @@ -0,0 +1,64 @@ +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 .= ''; + + fwrite($handle, $content); + fclose($handle); + + print $dirName .'/'. $filename; + } +} \ No newline at end of file -- libgit2 0.21.4