diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index 8b5357c..0d1169b 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -136,7 +136,7 @@ class Category extends \yii\db\ActiveRecord public function getProducts() { return $this->hasMany(Product::className(), ['product_id' => 'product_id']) ->viaTable('product_category', ['category_id' => 'category_id']) - ->with(['variants']) + ->joinWith(['variants']) ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); // return $this->getRelations('product_categories'); } diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index 6efdb51..921bc45 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -105,6 +105,10 @@ class Product extends \yii\db\ActiveRecord ]; } + public function getUrl() { + return '/product/'. $this->alias; + } + /** * @return \yii\db\ActiveQuery */ diff --git a/frontend/config/main.php b/frontend/config/main.php index 36e88e7..0451622 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -74,6 +74,8 @@ return [ 'brands' => 'catalog/brands', ] ], + 'priceparam.xml' => 'site/priceparam', + 'price.xml' => 'site/price', // 'catalog' => 'catalog/all', // 'catalog/' => 'catalog/index', // 'products/search' => 'products/search', diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 018923f..28e668c 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -3,6 +3,9 @@ namespace frontend\controllers; use common\modules\product\models\Category; +use common\modules\product\models\CategorySearch; +use common\modules\product\models\Product; +use common\modules\product\models\ProductVariant; use Yii; use yii\web\Controller; use common\models\Page; @@ -54,24 +57,21 @@ class SiteController extends Controller public function actionPriceparam () { - if (! $catalog = Category::find () - ->where (['translit' => $_GET['translit']]) - ->with ('parent') - ->one () - ) + $category_alias = Yii::$app->request->get('category'); + $is_count = Yii::$app->request->get('count', false); + + if ( !($category = CategorySearch::findByAlias($category_alias))) { - throw new HttpException(404, 'Данной странице не существует!'); + throw new HttpException(404, 'Данной страницы не существует!'); } - //var_dump();die; - - $products = Products::find ()->where (['catalog_id' => $catalog->id])->all(); - if (isset($_GET['count'])){ - - print (count($products));die; + $products = $category->products; + if ($is_count) { + print (count($products)); + exit; } -//var_dump($products);die(); + set_time_limit (0); header ("Content-Type: text/xml"); print ''; @@ -83,81 +83,61 @@ class SiteController extends Controller print ""; print ""; - print "" . $catalog->id . ""; + print "" . $category->category_id . ""; print ""; - print "" . $catalog->name . ""; + print "" . $category->name . ""; print ""; print ""; print ""; - foreach ($products as $product) - { - $color = Mod::find()->where (' - (onstock_status_id > 0 OR is_always_active > 0) - AND cost > 0 - AND status = 1 - ')->where(['product_id' => $product->id])->all(); - - $brend = Brends::find()->where(['id' => $product->brend_id])->one(); - //$brends = Brends::find()->orderBy('sort ASC')->all(); - - //var_dump($brend);die; + /** @var Product $product */ + foreach ($products as $product) { + /** @var ProductVariant $variant */ + foreach ($product->enabledVariants as $variant) { - foreach($color as $v) { - - $col = $v['color']; - $pr = $v['cost']; - $old_pr = $v['old_cost']; print ""; - print "" . htmlspecialchars ($v['id']) . ""; - print "" . htmlspecialchars ($product->catalog_id) . ""; - print "".$brend['name'].""; - print "" . htmlspecialchars ($v['art']) . ""; - print "" . htmlspecialchars (substr($catalog->name, 0,-2)) ." "; - print "" . htmlspecialchars ($product->name) ." "; - print "". $col . " "; - print "" . htmlspecialchars ($product->body_ru) . ""; - print "http://rukzachok.com.ua/products/" . htmlspecialchars ($_GET['translit']) . "/" . htmlspecialchars ($product->translit). ""; - print "http://rukzachok.com.ua/upload/mod/big/" . $v['image'] . ""; - print "" . $pr . ""; - print "" . $old_pr . ""; + print "" . htmlspecialchars($variant->product_variant_id) . ""; + print "" . htmlspecialchars($product->category->category_id) . ""; + print "" . $product->brand->name . ""; + print "" . htmlspecialchars($variant->sku) . ""; + print "" . htmlspecialchars(substr($category->name, 0, -2)) . " "; + print "" . htmlspecialchars($product->name) . " "; + print "" . $variant->name . " "; + print "" . htmlspecialchars($product->description) . ""; + print "http://rukzachok.com.ua{$product->url}#{$variant->product_variant_id}"; + print "http://rukzachok.com.ua{$variant->imageUrl}"; + print "" . $product->price . ""; + print "" . $product->price_old . ""; print ""; print "В наличии"; print ""; print ""; - } } - - print ""; print ""; - - } public function actionPrice() { + $category_alias = Yii::$app->request->get('category'); + $is_count = Yii::$app->request->get('count', false); - if (! $catalog = Category::find () - ->where (['translit' => $_GET['translit']]) - ->with ('parent') - ->one () - ) + if ( !($category = CategorySearch::findByAlias($category_alias))) { - throw new HttpException(404, 'Данной странице не существует!'); + throw new HttpException(404, 'Данной страницы не существует!'); } + $products = $category->products; + if ($is_count) { + print (count($products)); + exit; + } - $products = Products::find ()->where (['catalog_id' => $catalog->id])->all(); - if (isset($_GET['count'])){ - - print (count($products));die; - } //var_dump($products);die(); set_time_limit (0); header ("Content-Type: text/xml"); @@ -170,43 +150,30 @@ class SiteController extends Controller print ""; print ""; - print "" . $catalog->id . ""; + print "" . $category->category_id . ""; print ""; - print "" . $catalog->name . ""; + print "" . $category->name . ""; print ""; print ""; print ""; + /** @var Product $product */ foreach ($products as $product) { - $color = Mod::find()->where (' - (onstock_status_id > 0 OR is_always_active > 0) - AND cost > 0 - AND status = 1 - ')->where(['product_id' => $product->id])->all(); - - $brend = Brends::find()->where(['id' => $product->brend_id])->one(); - //$brends = Brends::find()->orderBy('sort ASC')->all(); - - //var_dump($brend);die; - - foreach($color as $v) { - - $col = $v['color']; - $pr = $v['cost']; - $old_pr = $v['old_cost']; + /** @var ProductVariant $variant */ + foreach ($product->enabledVariants as $variant) { print ""; - print "" . htmlspecialchars ($v['id']) . ""; - print "" . htmlspecialchars ($product->catalog_id) . ""; - print "".$brend['name'].""; - print "" . htmlspecialchars ($v['art']) . ""; - print "" . htmlspecialchars ($product->name) ." ". $col . " "; - print "" . htmlspecialchars ($product->body_ru) . ""; - print "http://rukzachok.com.ua/products/" . htmlspecialchars ($_GET['translit']) . "/" . htmlspecialchars ($product->translit) . ""; - print "http://rukzachok.com.ua/upload/mod/big/" . $v['image'] . ""; - print "" . $pr . ""; - print "" . $old_pr . ""; + print "" . htmlspecialchars($variant->product_variant_id) . ""; + print "" . htmlspecialchars($product->category->category_id) . ""; + print "" . $product->brand->name . ""; + print "" . htmlspecialchars($variant->sku) . ""; + print "" . htmlspecialchars($product->name) . " "; + print "" . htmlspecialchars($product->description) . ""; + print "http://rukzachok.com.ua{$product->url}#{$variant->product_variant_id}"; + print "http://rukzachok.com.ua{$variant->imageUrl}"; + print "" . $product->price . ""; + print "" . $product->price_old . ""; print ""; print "В наличии"; print ""; -- libgit2 0.21.4