From e71d5d51686c0ab53e2afb3f69bbd59c60859820 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 6 Dec 2016 11:33:36 +0200 Subject: [PATCH] remarketing --- console/controllers/FeedController.php | 59 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/console/controllers/FeedController.php b/console/controllers/FeedController.php index 247b177..3e80cfa 100644 --- a/console/controllers/FeedController.php +++ b/console/controllers/FeedController.php @@ -8,10 +8,11 @@ namespace console\controllers; +use yii\console\Controller; use Yii; use yii\helpers\Url; -use yii\console\Controller; use yii\web\NotFoundHttpException; +use common\modules\product\models\Product; class FeedController extends Controller @@ -19,26 +20,26 @@ 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 getProducts() { + return Product::find()->all(); + } -// public function createRow( $product, &$content ){ -// $url = Url::to(['catalog/product', 'product' => $product]); -// if($this->checkUrl($url)){ -// print $this->count++ . "\n"; -// $content[] = $url; -// } -// } + 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; + } + } public function actionProcess() { @@ -53,14 +54,16 @@ class FeedController extends Controller array('123', '456', '789'), array('"aaa"', '"bbb"') ); -// //$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); -//// } -// - fputcsv($handle, $content); + $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); + } fclose($handle); print $dirName .'/'. $filename; -- libgit2 0.21.4