Commit 02e6c2ba5ebfe45b5f0bdb3302ab95a45eb1e1be
1 parent
0ff57d01
-
Showing
4 changed files
with
62 additions
and
89 deletions
Show diff stats
common/modules/product/models/Category.php
@@ -136,7 +136,7 @@ class Category extends \yii\db\ActiveRecord | @@ -136,7 +136,7 @@ class Category extends \yii\db\ActiveRecord | ||
136 | public function getProducts() { | 136 | public function getProducts() { |
137 | return $this->hasMany(Product::className(), ['product_id' => 'product_id']) | 137 | return $this->hasMany(Product::className(), ['product_id' => 'product_id']) |
138 | ->viaTable('product_category', ['category_id' => 'category_id']) | 138 | ->viaTable('product_category', ['category_id' => 'category_id']) |
139 | - ->with(['variants']) | 139 | + ->joinWith(['variants']) |
140 | ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); | 140 | ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); |
141 | // return $this->getRelations('product_categories'); | 141 | // return $this->getRelations('product_categories'); |
142 | } | 142 | } |
common/modules/product/models/Product.php
@@ -105,6 +105,10 @@ class Product extends \yii\db\ActiveRecord | @@ -105,6 +105,10 @@ class Product extends \yii\db\ActiveRecord | ||
105 | ]; | 105 | ]; |
106 | } | 106 | } |
107 | 107 | ||
108 | + public function getUrl() { | ||
109 | + return '/product/'. $this->alias; | ||
110 | + } | ||
111 | + | ||
108 | /** | 112 | /** |
109 | * @return \yii\db\ActiveQuery | 113 | * @return \yii\db\ActiveQuery |
110 | */ | 114 | */ |
frontend/config/main.php
@@ -74,6 +74,8 @@ return [ | @@ -74,6 +74,8 @@ return [ | ||
74 | 'brands' => 'catalog/brands', | 74 | 'brands' => 'catalog/brands', |
75 | ] | 75 | ] |
76 | ], | 76 | ], |
77 | + 'priceparam.xml' => 'site/priceparam', | ||
78 | + 'price.xml' => 'site/price', | ||
77 | // 'catalog' => 'catalog/all', | 79 | // 'catalog' => 'catalog/all', |
78 | // 'catalog/<translit:\w+>' => 'catalog/index', | 80 | // 'catalog/<translit:\w+>' => 'catalog/index', |
79 | // 'products/search' => 'products/search', | 81 | // 'products/search' => 'products/search', |
frontend/controllers/SiteController.php
@@ -3,6 +3,9 @@ | @@ -3,6 +3,9 @@ | ||
3 | namespace frontend\controllers; | 3 | namespace frontend\controllers; |
4 | 4 | ||
5 | use common\modules\product\models\Category; | 5 | use common\modules\product\models\Category; |
6 | +use common\modules\product\models\CategorySearch; | ||
7 | +use common\modules\product\models\Product; | ||
8 | +use common\modules\product\models\ProductVariant; | ||
6 | use Yii; | 9 | use Yii; |
7 | use yii\web\Controller; | 10 | use yii\web\Controller; |
8 | use common\models\Page; | 11 | use common\models\Page; |
@@ -54,24 +57,21 @@ class SiteController extends Controller | @@ -54,24 +57,21 @@ class SiteController extends Controller | ||
54 | 57 | ||
55 | public function actionPriceparam () | 58 | public function actionPriceparam () |
56 | { | 59 | { |
57 | - if (! $catalog = Category::find () | ||
58 | - ->where (['translit' => $_GET['translit']]) | ||
59 | - ->with ('parent') | ||
60 | - ->one () | ||
61 | - ) | 60 | + $category_alias = Yii::$app->request->get('category'); |
61 | + $is_count = Yii::$app->request->get('count', false); | ||
62 | + | ||
63 | + if ( !($category = CategorySearch::findByAlias($category_alias))) | ||
62 | { | 64 | { |
63 | - throw new HttpException(404, 'Данной странице не существует!'); | 65 | + throw new HttpException(404, 'Данной страницы не существует!'); |
64 | } | 66 | } |
65 | 67 | ||
66 | - //var_dump();die; | ||
67 | - | ||
68 | - $products = Products::find ()->where (['catalog_id' => $catalog->id])->all(); | ||
69 | - if (isset($_GET['count'])){ | ||
70 | - | ||
71 | - print (count($products));die; | 68 | + $products = $category->products; |
72 | 69 | ||
70 | + if ($is_count) { | ||
71 | + print (count($products)); | ||
72 | + exit; | ||
73 | } | 73 | } |
74 | -//var_dump($products);die(); | 74 | + |
75 | set_time_limit (0); | 75 | set_time_limit (0); |
76 | header ("Content-Type: text/xml"); | 76 | header ("Content-Type: text/xml"); |
77 | print '<?xml version="1.0" encoding="UTF-8" ?>'; | 77 | print '<?xml version="1.0" encoding="UTF-8" ?>'; |
@@ -83,81 +83,61 @@ class SiteController extends Controller | @@ -83,81 +83,61 @@ class SiteController extends Controller | ||
83 | print "<categories>"; | 83 | print "<categories>"; |
84 | 84 | ||
85 | print "<category>"; | 85 | print "<category>"; |
86 | - print "<id>" . $catalog->id . "</id>"; | 86 | + print "<id>" . $category->category_id . "</id>"; |
87 | print "<parentId></parentId>"; | 87 | print "<parentId></parentId>"; |
88 | - print "<name>" . $catalog->name . "</name>"; | 88 | + print "<name>" . $category->name . "</name>"; |
89 | print "</category>"; | 89 | print "</category>"; |
90 | 90 | ||
91 | 91 | ||
92 | print "</categories>"; | 92 | print "</categories>"; |
93 | print "<items>"; | 93 | print "<items>"; |
94 | - foreach ($products as $product) | ||
95 | - { | ||
96 | - $color = Mod::find()->where (' | ||
97 | - (onstock_status_id > 0 OR is_always_active > 0) | ||
98 | - AND cost > 0 | ||
99 | - AND status = 1 | ||
100 | - ')->where(['product_id' => $product->id])->all(); | ||
101 | - | ||
102 | - $brend = Brends::find()->where(['id' => $product->brend_id])->one(); | ||
103 | - //$brends = Brends::find()->orderBy('sort ASC')->all(); | ||
104 | - | ||
105 | - //var_dump($brend);die; | 94 | + /** @var Product $product */ |
95 | + foreach ($products as $product) { | ||
96 | + /** @var ProductVariant $variant */ | ||
97 | + foreach ($product->enabledVariants as $variant) { | ||
106 | 98 | ||
107 | - foreach($color as $v) { | ||
108 | - | ||
109 | - $col = $v['color']; | ||
110 | - $pr = $v['cost']; | ||
111 | - $old_pr = $v['old_cost']; | ||
112 | print "<item>"; | 99 | print "<item>"; |
113 | - print "<id>" . htmlspecialchars ($v['id']) . "</id>"; | ||
114 | - print "<categoryId>" . htmlspecialchars ($product->catalog_id) . "</categoryId>"; | ||
115 | - print "<vendor>".$brend['name']."</vendor>"; | ||
116 | - print "<code>" . htmlspecialchars ($v['art']) . "</code>"; | ||
117 | - print "<typeprefix>" . htmlspecialchars (substr($catalog->name, 0,-2)) ." </typeprefix>"; | ||
118 | - print "<name>" . htmlspecialchars ($product->name) ." </name>"; | ||
119 | - print "<param>". $col . " </param>"; | ||
120 | - print "<description>" . htmlspecialchars ($product->body_ru) . "</description>"; | ||
121 | - print "<url>http://rukzachok.com.ua/products/" . htmlspecialchars ($_GET['translit']) . "/" . htmlspecialchars ($product->translit). "</url>"; | ||
122 | - print "<image>http://rukzachok.com.ua/upload/mod/big/" . $v['image'] . "</image>"; | ||
123 | - print "<priceRUAH>" . $pr . "</priceRUAH>"; | ||
124 | - print "<oldprice>" . $old_pr . "</oldprice>"; | 100 | + print "<id>" . htmlspecialchars($variant->product_variant_id) . "</id>"; |
101 | + print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>"; | ||
102 | + print "<vendor>" . $product->brand->name . "</vendor>"; | ||
103 | + print "<code>" . htmlspecialchars($variant->sku) . "</code>"; | ||
104 | + print "<typeprefix>" . htmlspecialchars(substr($category->name, 0, -2)) . " </typeprefix>"; | ||
105 | + print "<name>" . htmlspecialchars($product->name) . " </name>"; | ||
106 | + print "<param>" . $variant->name . " </param>"; | ||
107 | + print "<description>" . htmlspecialchars($product->description) . "</description>"; | ||
108 | + print "<url>http://rukzachok.com.ua{$product->url}#{$variant->product_variant_id}</url>"; | ||
109 | + print "<image>http://rukzachok.com.ua{$variant->imageUrl}</image>"; | ||
110 | + print "<priceRUAH>" . $product->price . "</priceRUAH>"; | ||
111 | + print "<oldprice>" . $product->price_old . "</oldprice>"; | ||
125 | print "<priceRUSD></priceRUSD>"; | 112 | print "<priceRUSD></priceRUSD>"; |
126 | print "<stock>В наличии</stock>"; | 113 | print "<stock>В наличии</stock>"; |
127 | print "<guarantee></guarantee>"; | 114 | print "<guarantee></guarantee>"; |
128 | print "</item>"; | 115 | print "</item>"; |
129 | - | ||
130 | } | 116 | } |
131 | } | 117 | } |
132 | - | ||
133 | - | ||
134 | print "</items>"; | 118 | print "</items>"; |
135 | 119 | ||
136 | print "</price>"; | 120 | print "</price>"; |
137 | - | ||
138 | - | ||
139 | } | 121 | } |
140 | 122 | ||
141 | public function actionPrice() | 123 | public function actionPrice() |
142 | { | 124 | { |
125 | + $category_alias = Yii::$app->request->get('category'); | ||
126 | + $is_count = Yii::$app->request->get('count', false); | ||
143 | 127 | ||
144 | - if (! $catalog = Category::find () | ||
145 | - ->where (['translit' => $_GET['translit']]) | ||
146 | - ->with ('parent') | ||
147 | - ->one () | ||
148 | - ) | 128 | + if ( !($category = CategorySearch::findByAlias($category_alias))) |
149 | { | 129 | { |
150 | - throw new HttpException(404, 'Данной странице не существует!'); | 130 | + throw new HttpException(404, 'Данной страницы не существует!'); |
151 | } | 131 | } |
152 | 132 | ||
133 | + $products = $category->products; | ||
153 | 134 | ||
135 | + if ($is_count) { | ||
136 | + print (count($products)); | ||
137 | + exit; | ||
138 | + } | ||
154 | 139 | ||
155 | - $products = Products::find ()->where (['catalog_id' => $catalog->id])->all(); | ||
156 | - if (isset($_GET['count'])){ | ||
157 | - | ||
158 | - print (count($products));die; | ||
159 | 140 | ||
160 | - } | ||
161 | //var_dump($products);die(); | 141 | //var_dump($products);die(); |
162 | set_time_limit (0); | 142 | set_time_limit (0); |
163 | header ("Content-Type: text/xml"); | 143 | header ("Content-Type: text/xml"); |
@@ -170,43 +150,30 @@ class SiteController extends Controller | @@ -170,43 +150,30 @@ class SiteController extends Controller | ||
170 | print "<categories>"; | 150 | print "<categories>"; |
171 | 151 | ||
172 | print "<category>"; | 152 | print "<category>"; |
173 | - print "<id>" . $catalog->id . "</id>"; | 153 | + print "<id>" . $category->category_id . "</id>"; |
174 | print "<parentId></parentId>"; | 154 | print "<parentId></parentId>"; |
175 | - print "<name>" . $catalog->name . "</name>"; | 155 | + print "<name>" . $category->name . "</name>"; |
176 | print "</category>"; | 156 | print "</category>"; |
177 | 157 | ||
178 | print "</categories>"; | 158 | print "</categories>"; |
179 | print "<items>"; | 159 | print "<items>"; |
160 | + /** @var Product $product */ | ||
180 | foreach ($products as $product) | 161 | foreach ($products as $product) |
181 | { | 162 | { |
182 | - $color = Mod::find()->where (' | ||
183 | - (onstock_status_id > 0 OR is_always_active > 0) | ||
184 | - AND cost > 0 | ||
185 | - AND status = 1 | ||
186 | - ')->where(['product_id' => $product->id])->all(); | ||
187 | - | ||
188 | - $brend = Brends::find()->where(['id' => $product->brend_id])->one(); | ||
189 | - //$brends = Brends::find()->orderBy('sort ASC')->all(); | ||
190 | - | ||
191 | - //var_dump($brend);die; | ||
192 | - | ||
193 | - foreach($color as $v) { | ||
194 | - | ||
195 | - $col = $v['color']; | ||
196 | - $pr = $v['cost']; | ||
197 | - $old_pr = $v['old_cost']; | 163 | + /** @var ProductVariant $variant */ |
164 | + foreach ($product->enabledVariants as $variant) { | ||
198 | 165 | ||
199 | print "<item>"; | 166 | print "<item>"; |
200 | - print "<id>" . htmlspecialchars ($v['id']) . "</id>"; | ||
201 | - print "<categoryId>" . htmlspecialchars ($product->catalog_id) . "</categoryId>"; | ||
202 | - print "<vendor>".$brend['name']."</vendor>"; | ||
203 | - print "<code>" . htmlspecialchars ($v['art']) . "</code>"; | ||
204 | - print "<name>" . htmlspecialchars ($product->name) ." ". $col . " </name>"; | ||
205 | - print "<description>" . htmlspecialchars ($product->body_ru) . "</description>"; | ||
206 | - print "<url>http://rukzachok.com.ua/products/" . htmlspecialchars ($_GET['translit']) . "/" . htmlspecialchars ($product->translit) . "</url>"; | ||
207 | - print "<image>http://rukzachok.com.ua/upload/mod/big/" . $v['image'] . "</image>"; | ||
208 | - print "<priceRUAH>" . $pr . "</priceRUAH>"; | ||
209 | - print "<oldprice>" . $old_pr . "</oldprice>"; | 167 | + print "<id>" . htmlspecialchars($variant->product_variant_id) . "</id>"; |
168 | + print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>"; | ||
169 | + print "<vendor>" . $product->brand->name . "</vendor>"; | ||
170 | + print "<code>" . htmlspecialchars($variant->sku) . "</code>"; | ||
171 | + print "<name>" . htmlspecialchars($product->name) . " </name>"; | ||
172 | + print "<description>" . htmlspecialchars($product->description) . "</description>"; | ||
173 | + print "<url>http://rukzachok.com.ua{$product->url}#{$variant->product_variant_id}</url>"; | ||
174 | + print "<image>http://rukzachok.com.ua{$variant->imageUrl}</image>"; | ||
175 | + print "<priceRUAH>" . $product->price . "</priceRUAH>"; | ||
176 | + print "<oldprice>" . $product->price_old . "</oldprice>"; | ||
210 | print "<priceRUSD></priceRUSD>"; | 177 | print "<priceRUSD></priceRUSD>"; |
211 | print "<stock>В наличии</stock>"; | 178 | print "<stock>В наличии</stock>"; |
212 | print "<guarantee></guarantee>"; | 179 | print "<guarantee></guarantee>"; |