Commit c9d723d78be8c926f54a42400954f53640916b6f

Authored by Karnovsky A
1 parent 5845a9f4

-

common/modules/product/controllers/ManageController.php
... ... @@ -157,13 +157,16 @@ class ManageController extends Controller
157 157 $model = $this->findModel($id);
158 158 if ($model->load(Yii::$app->request->post())) {
159 159 $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload');
160   - $variantImagesUpload = UploadedFile::getInstances($model, 'variants');
161   - $model->variantImagesUpload = [];
  160 + $model->variantImagesUpload = UploadedFile::getInstances($model, 'variants');
  161 + /*if (!empty($variantImagesUpload)) {
  162 + var_dump($variantImagesUpload);exit;
  163 + }*/
  164 + /*$model->variantImagesUpload = [];
162 165 foreach ($_POST['Product']['variants'] as $i => $variant) {
163 166 if (!empty($variant['product_variant_id'])) {
164 167 $model->variantImagesUpload[$variant['product_variant_id']] = $variantImagesUpload[$i];
165 168 }
166   - }
  169 + }*/
167 170 if ($model->save()) {
168 171 // foreach ($model->images as $image) {
169 172 // $image->delete();
... ... @@ -178,10 +181,13 @@ class ManageController extends Controller
178 181 }
179 182  
180 183 if ( ($images = $model->variantImagesUpload()) !== FALSE) {
181   - foreach ($images as $product_variant_id => $image) {
  184 + foreach ($images as $i => $image) {
  185 + if (empty($model->_variants[$i])) {
  186 + continue;
  187 + }
182 188 $imageModel = new ProductImage();
183 189 $imageModel->product_id = $model->product_id;
184   - $imageModel->product_variant_id = $product_variant_id;
  190 + $imageModel->product_variant_id = intval($model->_variants[$i]['product_variant_id']);
185 191 $imageModel->image = $image;
186 192 $imageModel->save();
187 193 }
... ...
common/modules/product/models/Product.php
... ... @@ -223,7 +223,7 @@ class Product extends \yii\db\ActiveRecord
223 223 if (!is_array($_variant)) {
224 224 return;
225 225 }
226   - if (!empty($_variant['product_variant_id'])) {
  226 + if (!empty($_variant['product_variant_id'])) {
227 227 unset($todel[$_variant['product_variant_id']]);
228 228 $model = ProductVariant::findOne($_variant['product_variant_id']);
229 229 } else {
... ... @@ -234,9 +234,9 @@ class Product extends \yii\db\ActiveRecord
234 234 $model->product_id = $this->product_id;
235 235 $model->save();
236 236 }
237   -// if (!empty($todel)) {
238   -// ProductVariant::deleteAll(['product_variant_id' => $todel]);
239   -// }
  237 + if (!empty($todel)) {
  238 + ProductVariant::deleteAll(['product_variant_id' => $todel]);
  239 + }
240 240 }
241 241  
242 242 public function beforeDelete() {
... ...
common/modules/product/models/ProductVariant.php
... ... @@ -156,4 +156,8 @@ class ProductVariant extends \yii\db\ActiveRecord
156 156 public function getId(){
157 157 return $this->product_variant_id;
158 158 }
  159 +
  160 + public function beforeDelete() {
  161 + ProductImage::deleteAll(['product_variant_id' => $this->product_variant_id]);
  162 + }
159 163 }
... ...
frontend/controllers/CatalogController.php
... ... @@ -215,6 +215,21 @@ class CatalogController extends \yii\web\Controller
215 215 $params['prices'] = $filter['prices'];
216 216 }
217 217  
  218 + if ( !empty($filter['special']) ) {
  219 + if (!is_array($filter['special'])) {
  220 + $filter['special'] = [$filter['special']];
  221 + }
  222 + if (in_array('new', $filter['special'])) {
  223 + $params['special']['is_new'] = true;
  224 + }
  225 + if (in_array('top', $filter['special'])) {
  226 + $params['special']['is_top'] = true;
  227 + }
  228 + if (in_array('promo', $filter['special'])) {
  229 + $params['special']['akciya'] = true;
  230 + }
  231 + }
  232 +
218 233 $productModel = new ProductFrontendSearch();
219 234 $productProvider = $productModel->search(null, $params);
220 235  
... ...