Commit 4ca71a5540b55abf7eac4a16a246ce55e5bf5168
1 parent
d8bf42cd
Ntr
Showing
1 changed file
with
8 additions
and
5 deletions
Show diff stats
common/models/Event.php
| ... | ... | @@ -146,14 +146,17 @@ class Event extends \yii\db\ActiveRecord |
| 146 | 146 | |
| 147 | 147 | $handle = fopen($file, 'r'); |
| 148 | 148 | |
| 149 | - EventsToProducts::deleteAll(['event_id' =>iconv('cp1251', 'utf-8', $this->event_id)]); | |
| 149 | + EventsToProducts::deleteAll(['event_id' =>$this->event_id]); | |
| 150 | 150 | while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { |
| 151 | 151 | if(isset($data[0]) && isset($data[1])){ |
| 152 | 152 | $product = ProductVariant::find()->where(['sku' => iconv('cp1251', 'utf-8', $data[1])])->joinWith('product')->one(); |
| 153 | - $model = new EventsToProducts; | |
| 154 | - $model->event_id = iconv('cp1251', 'utf-8', $data[0]); | |
| 155 | - $model->product_id = $product->product->product_id; | |
| 156 | - $model->save(); | |
| 153 | + if($product instanceof ProductVariant){ | |
| 154 | + $model = new EventsToProducts; | |
| 155 | + $model->event_id = $this->event_id; | |
| 156 | + $model->product_id = $product->product->product_id; | |
| 157 | + $model->save(); | |
| 158 | + } | |
| 159 | + | |
| 157 | 160 | |
| 158 | 161 | |
| 159 | 162 | } | ... | ... |