Commit e71d5d51686c0ab53e2afb3f69bbd59c60859820
1 parent
0cd58f97
remarketing
Showing
1 changed file
with
31 additions
and
28 deletions
Show diff stats
console/controllers/FeedController.php
| ... | ... | @@ -8,10 +8,11 @@ |
| 8 | 8 | |
| 9 | 9 | namespace console\controllers; |
| 10 | 10 | |
| 11 | +use yii\console\Controller; | |
| 11 | 12 | use Yii; |
| 12 | 13 | use yii\helpers\Url; |
| 13 | -use yii\console\Controller; | |
| 14 | 14 | use yii\web\NotFoundHttpException; |
| 15 | +use common\modules\product\models\Product; | |
| 15 | 16 | |
| 16 | 17 | |
| 17 | 18 | class FeedController extends Controller |
| ... | ... | @@ -19,26 +20,26 @@ class FeedController extends Controller |
| 19 | 20 | private $urlList = []; |
| 20 | 21 | private $count = 1; |
| 21 | 22 | |
| 22 | -// public function getProducts() { | |
| 23 | -// return Product::find()->all(); | |
| 24 | -// } | |
| 25 | -// | |
| 26 | -// public function checkUrl($url){ | |
| 27 | -// if(!in_array($url, $this->urlList)){ | |
| 28 | -// $this->urlList[] = $url; | |
| 29 | -// return true; | |
| 30 | -// } else { | |
| 31 | -// return false; | |
| 32 | -// } | |
| 33 | -// } | |
| 23 | + public function getProducts() { | |
| 24 | + return Product::find()->all(); | |
| 25 | + } | |
| 34 | 26 | |
| 35 | -// public function createRow( $product, &$content ){ | |
| 36 | -// $url = Url::to(['catalog/product', 'product' => $product]); | |
| 37 | -// if($this->checkUrl($url)){ | |
| 38 | -// print $this->count++ . "\n"; | |
| 39 | -// $content[] = $url; | |
| 40 | -// } | |
| 41 | -// } | |
| 27 | + public function checkUrl($url){ | |
| 28 | + if(!in_array($url, $this->urlList)){ | |
| 29 | + $this->urlList[] = $url; | |
| 30 | + return true; | |
| 31 | + } else { | |
| 32 | + return false; | |
| 33 | + } | |
| 34 | + } | |
| 35 | + | |
| 36 | + public function createRow( $product, &$content ){ | |
| 37 | + $url = Url::to(['catalog/product', 'product' => $product]); | |
| 38 | + if($this->checkUrl($url)){ | |
| 39 | + print $this->count++ . "\n"; | |
| 40 | + $content[] = $url; | |
| 41 | + } | |
| 42 | + } | |
| 42 | 43 | |
| 43 | 44 | public function actionProcess() { |
| 44 | 45 | |
| ... | ... | @@ -53,14 +54,16 @@ class FeedController extends Controller |
| 53 | 54 | array('123', '456', '789'), |
| 54 | 55 | array('"aaa"', '"bbb"') |
| 55 | 56 | ); |
| 56 | -// //$content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price']; | |
| 57 | -// //$content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price']; | |
| 58 | -// | |
| 59 | -//// foreach ($this->getProducts() as $product) { | |
| 60 | -//// $this->createRow($product, $content); | |
| 61 | -//// } | |
| 62 | -// | |
| 63 | - fputcsv($handle, $content); | |
| 57 | + $content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price']; | |
| 58 | + $content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price']; | |
| 59 | + | |
| 60 | +// foreach ($this->getProducts() as $product) { | |
| 61 | +// $this->createRow($product, $content); | |
| 62 | +// } | |
| 63 | + | |
| 64 | + foreach ($content as $item) { | |
| 65 | + fputcsv($handle, $item); | |
| 66 | + } | |
| 64 | 67 | fclose($handle); |
| 65 | 68 | |
| 66 | 69 | print $dirName .'/'. $filename; | ... | ... |