Commit 15b6552f51fc70a91d3c070cc4012eb5892200bd

Authored by Yarik
1 parent 240fe900

Sitemap

Showing 1 changed file with 13 additions and 17 deletions   Show diff stats
console/SiteMapController.php
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace artweb\artbox\ecommerce\console; 3 namespace artweb\artbox\ecommerce\console;
4 4
5 use artweb\artbox\ecommerce\models\Brand; 5 use artweb\artbox\ecommerce\models\Brand;
  6 + use artweb\artbox\ecommerce\models\Product;
6 use artweb\artbox\ecommerce\models\ProductVariant; 7 use artweb\artbox\ecommerce\models\ProductVariant;
7 use artweb\artbox\language\components\LanguageUrlManager; 8 use artweb\artbox\language\components\LanguageUrlManager;
8 use artweb\artbox\language\models\Language; 9 use artweb\artbox\language\models\Language;
@@ -41,18 +42,8 @@ @@ -41,18 +42,8 @@
41 42
42 public function getVariants() 43 public function getVariants()
43 { 44 {
44 - return ProductVariant::find()  
45 - ->with('lang')  
46 - ->with('product.lang')  
47 - ->select('*', 'DISTINCT ON (product_id)')  
48 - ->andWhere(  
49 - [  
50 - '!=',  
51 - 'stock',  
52 - 0,  
53 - ]  
54 - );  
55 - 45 + return Product::find()
  46 + ->with('enabledVariants.lang');
56 } 47 }
57 48
58 public function getSeoLinks() 49 public function getSeoLinks()
@@ -254,16 +245,21 @@ @@ -254,16 +245,21 @@
254 } 245 }
255 246
256 foreach ($this->getVariants() 247 foreach ($this->getVariants()
257 - ->batch(1000) as $rows) {  
258 - foreach ($rows as $row) {  
259 - if (!preg_match("@^[a-zA-Z\d]+$@i", $row->sku)) { 248 + ->each(1000) as $row) {
  249 + /**
  250 + * @var Product $row
  251 + */
  252 + if(!empty($row->enabledVariants)) {
  253 + $variant = $row->enabledVariants[0];
  254 + }
  255 + if(!empty($variant)) {
  256 + if (!preg_match("@^[a-zA-Z\d]+$@i", $variant->sku)) {
260 continue; 257 continue;
261 } 258 }
262 $url = $urlManager->createAbsoluteUrl( 259 $url = $urlManager->createAbsoluteUrl(
263 [ 260 [
264 'catalog/product', 261 'catalog/product',
265 - 'product' => $row->product->lang->alias,  
266 - 'variant' => $row->sku, 262 + 'product' => $row->lang->alias,
267 ] 263 ]
268 ); 264 );
269 $this->createRow($url, 0.7, 'Daily'); 265 $this->createRow($url, 0.7, 'Daily');