Blame view

console/controllers/FeedController.php 1.83 KB
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;
  
c1f098dc   Alex Savenko   remarketing
11
12
13
14
15
  use common\models\Articles;
  use common\models\Seo;
  use common\modules\product\helpers\FilterHelper;
  use common\modules\product\models\Brand;
  use common\modules\product\models\Category;
731adb96   Alex Savenko   remarketing
16
  use common\modules\product\models\Product;
fd068f14   Alex Savenko   remarketing
17
  use frontend\models\ProductFrontendSearch;
731adb96   Alex Savenko   remarketing
18
  use Yii;
c1f098dc   Alex Savenko   remarketing
19
20
21
  use common\models\Page;
  use common\models\PageSearch;
  use yii\helpers\ArrayHelper;
fd068f14   Alex Savenko   remarketing
22
  use yii\helpers\Url;
c1f098dc   Alex Savenko   remarketing
23
  use yii\console\Controller;
fd068f14   Alex Savenko   remarketing
24
  use yii\web\NotFoundHttpException;
c1f098dc   Alex Savenko   remarketing
25
  use yii\filters\VerbFilter;
731adb96   Alex Savenko   remarketing
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  
  
  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";
7612cbbe   Alex Savenko   remarketing
50
              $content[] = $url;
731adb96   Alex Savenko   remarketing
51
52
53
54
55
56
57
58
59
60
61
          }
      }
  
      public function actionProcess() {
  
          $dirName = Yii::getAlias('@frontend').'/web';
          $filename = 'feed.csv';
          setlocale(LC_ALL, 'ru_RU.CP1251');
  
          $handle = fopen($dirName .'/'. $filename, "w");
  
7a131af6   Alex Savenko   remarketing
62
          $content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price'];
15e8d972   Alex Savenko   remarketing
63
          $content[] = ['ID', 'ID2', 'Item Category', 'Item title', 'Item description', 'Price'];
731adb96   Alex Savenko   remarketing
64
  
15e8d972   Alex Savenko   remarketing
65
66
67
  //        foreach ($this->getProducts() as $product) {
  //            $this->createRow($product, $content);
  //        }
731adb96   Alex Savenko   remarketing
68
  
7a131af6   Alex Savenko   remarketing
69
          fputcsv($handle, $content);
731adb96   Alex Savenko   remarketing
70
71
72
73
74
          fclose($handle);
  
          print $dirName .'/'. $filename;
      }
  }