limit(1000) ->innerJoin(ProductVariant::tableName(), ProductVariant::tableName() .'.product_id = '. Product::tableName() .'.product_id') ->where(['and', ProductVariant::tableName().'.status = 0', ProductVariant::tableName().'.stock > 0']) ->all(); } public function createRow( $product, &$content ){ if ($this->checkId($product->product_id)) { print $this->count++ . "\r\n"; $content[] = [ $product->product_id, $product->category->category_id, $product->category->name, $product->name, $product->price.' UAH', ]; } } public function checkId($id){ if(!in_array($id, $this->idList)){ $this->idList[] = $id; return true; } else { return false; } } 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', 'Price']; foreach ($this->getProducts() as $product) { $this->createRow($product, $content); } foreach ($content as $item) { fputcsv($handle, $item); } fclose($handle); print $dirName .'/'. $filename; } }