diff --git a/console/SiteMapController.php b/console/SiteMapController.php index 31ac892..9db3350 100755 --- a/console/SiteMapController.php +++ b/console/SiteMapController.php @@ -47,6 +47,26 @@ ->innerJoinWith('enabledVariants.lang'); } + public function getProducts() + { + $products = Product::find() + ->innerJoinWith('variant') + ->innerJoinWith('brand.lang')->with('lang') + ->where([ + '!=', + 'product_variant.price', + 0 + ]) + ->andWhere([ + '!=', + 'product_variant.stock', + 0 + ]) + ->all(); + + return $products; + } + public function getSeoLinks() { return Seo::find() @@ -221,10 +241,13 @@ } } + $this->stdout('Add static' . PHP_EOL, Console::FG_BLUE); foreach ($this->getAddStatic() as $page) { $this->createRow($page, 1, 'Daily'); } - + + $this->stdout('Add pages' . PHP_EOL, Console::FG_BLUE); + foreach ($this->getStaticPages() as $page) { $url = $urlManager->createAbsoluteUrl( [ @@ -234,7 +257,9 @@ ); $this->createRow($url, 0.5); } - + + $this->stdout('Add categories' . PHP_EOL, Console::FG_BLUE); + foreach ($this->getCategories() as $category) { $url = $urlManager->createAbsoluteUrl( [ @@ -244,28 +269,49 @@ ); $this->createRow($url, 0.9, 'Daily'); } - foreach ($this->getVariants() - ->each(1000) as $row) { + +// foreach ($this->getVariants() +// ->each(1000) as $row) { +// /** +// * @var Product $row +// */ +// if(!empty($row->enabledVariants)) { +// $variant = $row->enabledVariants[0]; +// } +// if(!empty($variant)) { +// if (!preg_match("@^[a-zA-Z\d]+$@i", $variant->sku)) { +// continue; +// } +// $url = $urlManager->createAbsoluteUrl( +// [ +// 'catalog/product', +// 'product' => $row->lang->alias, +// ] +// ); +// $this->createRow($url, 0.7, 'Daily'); +// } +// } + /** + * New products generation + */ + + $this->stdout('Add products' . PHP_EOL, Console::FG_BLUE); + + foreach ($this->getProducts() as $product) { /** - * @var Product $row + * @var Product $product */ - if(!empty($row->enabledVariants)) { - $variant = $row->enabledVariants[0]; - } - if(!empty($variant)) { - if (!preg_match("@^[a-zA-Z\d]+$@i", $variant->sku)) { - continue; - } - $url = $urlManager->createAbsoluteUrl( - [ - 'catalog/product', - 'product' => $row->lang->alias, - ] - ); - $this->createRow($url, 0.7, 'Daily'); - } + $url = $urlManager->createAbsoluteUrl( + [ + 'catalog/product', + 'product' => $product->lang->alias, + ] + ); + $this->createRow($url, 0.7, 'Daily'); } - + + $this->stdout('Add brands' . PHP_EOL, Console::FG_BLUE); + foreach ($this->getBrands() as $brand) { $url = $urlManager->createAbsoluteUrl( @@ -277,7 +323,9 @@ $this->createRow($url, 0.5); } - + + $this->stdout('Add filters' . PHP_EOL, Console::FG_BLUE); + foreach ($this->getCategoriesWithFilters() as $category) { foreach ($category->taxGroups as $group) { if (in_array( @@ -306,7 +354,9 @@ } } - + + $this->stdout('Add seo links' . PHP_EOL, Console::FG_BLUE); + foreach ($this->getSeoLinks() as $link) { $url = Yii::$app->urlManager->baseUrl . $link->url; $this->createRow($url, 0.7); -- libgit2 0.21.4