Commit c9d723d78be8c926f54a42400954f53640916b6f

Authored by Karnovsky A
1 parent 5845a9f4

-

common/modules/product/controllers/ManageController.php
@@ -157,13 +157,16 @@ class ManageController extends Controller @@ -157,13 +157,16 @@ class ManageController extends Controller
157 $model = $this->findModel($id); 157 $model = $this->findModel($id);
158 if ($model->load(Yii::$app->request->post())) { 158 if ($model->load(Yii::$app->request->post())) {
159 $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); 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 foreach ($_POST['Product']['variants'] as $i => $variant) { 165 foreach ($_POST['Product']['variants'] as $i => $variant) {
163 if (!empty($variant['product_variant_id'])) { 166 if (!empty($variant['product_variant_id'])) {
164 $model->variantImagesUpload[$variant['product_variant_id']] = $variantImagesUpload[$i]; 167 $model->variantImagesUpload[$variant['product_variant_id']] = $variantImagesUpload[$i];
165 } 168 }
166 - } 169 + }*/
167 if ($model->save()) { 170 if ($model->save()) {
168 // foreach ($model->images as $image) { 171 // foreach ($model->images as $image) {
169 // $image->delete(); 172 // $image->delete();
@@ -178,10 +181,13 @@ class ManageController extends Controller @@ -178,10 +181,13 @@ class ManageController extends Controller
178 } 181 }
179 182
180 if ( ($images = $model->variantImagesUpload()) !== FALSE) { 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 $imageModel = new ProductImage(); 188 $imageModel = new ProductImage();
183 $imageModel->product_id = $model->product_id; 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 $imageModel->image = $image; 191 $imageModel->image = $image;
186 $imageModel->save(); 192 $imageModel->save();
187 } 193 }
common/modules/product/models/Product.php
@@ -223,7 +223,7 @@ class Product extends \yii\db\ActiveRecord @@ -223,7 +223,7 @@ class Product extends \yii\db\ActiveRecord
223 if (!is_array($_variant)) { 223 if (!is_array($_variant)) {
224 return; 224 return;
225 } 225 }
226 - if (!empty($_variant['product_variant_id'])) { 226 + if (!empty($_variant['product_variant_id'])) {
227 unset($todel[$_variant['product_variant_id']]); 227 unset($todel[$_variant['product_variant_id']]);
228 $model = ProductVariant::findOne($_variant['product_variant_id']); 228 $model = ProductVariant::findOne($_variant['product_variant_id']);
229 } else { 229 } else {
@@ -234,9 +234,9 @@ class Product extends \yii\db\ActiveRecord @@ -234,9 +234,9 @@ class Product extends \yii\db\ActiveRecord
234 $model->product_id = $this->product_id; 234 $model->product_id = $this->product_id;
235 $model->save(); 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 public function beforeDelete() { 242 public function beforeDelete() {
common/modules/product/models/ProductVariant.php
@@ -156,4 +156,8 @@ class ProductVariant extends \yii\db\ActiveRecord @@ -156,4 +156,8 @@ class ProductVariant extends \yii\db\ActiveRecord
156 public function getId(){ 156 public function getId(){
157 return $this->product_variant_id; 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,6 +215,21 @@ class CatalogController extends \yii\web\Controller
215 $params['prices'] = $filter['prices']; 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 $productModel = new ProductFrontendSearch(); 233 $productModel = new ProductFrontendSearch();
219 $productProvider = $productModel->search(null, $params); 234 $productProvider = $productModel->search(null, $params);
220 235