diff --git a/console/SiteMapController.php b/console/SiteMapController.php index 2677750..058ea4e 100755 --- a/console/SiteMapController.php +++ b/console/SiteMapController.php @@ -3,6 +3,7 @@ namespace artweb\artbox\ecommerce\console; use artweb\artbox\ecommerce\models\Brand; + use artweb\artbox\ecommerce\models\Product; use artweb\artbox\ecommerce\models\ProductVariant; use artweb\artbox\language\components\LanguageUrlManager; use artweb\artbox\language\models\Language; @@ -41,18 +42,8 @@ public function getVariants() { - return ProductVariant::find() - ->with('lang') - ->with('product.lang') - ->select('*', 'DISTINCT ON (product_id)') - ->andWhere( - [ - '!=', - 'stock', - 0, - ] - ); - + return Product::find() + ->with('enabledVariants.lang'); } public function getSeoLinks() @@ -254,16 +245,21 @@ } foreach ($this->getVariants() - ->batch(1000) as $rows) { - foreach ($rows as $row) { - if (!preg_match("@^[a-zA-Z\d]+$@i", $row->sku)) { + ->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->product->lang->alias, - 'variant' => $row->sku, + 'product' => $row->lang->alias, ] ); $this->createRow($url, 0.7, 'Daily'); -- libgit2 0.21.4