Commit 64dbf8bc7d0381d49a20be53390e3bd649b7d390

Authored by Administrator
1 parent 55bc4993

event

controllers/EventController.php
... ... @@ -113,6 +113,7 @@ class EventController extends Controller
113 113  
114 114 if ( ($file = UploadedFile::getInstance($model, 'products_file')) ) {
115 115 if(!empty($file)){
  116 +
116 117 $file->saveAs(Yii::getAlias('@uploadDir/' . $file->name));
117 118 $model->goEvent(Yii::getAlias('@uploadDir/' . $file->name));
118 119 }
... ...
models/Event.php
... ... @@ -170,13 +170,13 @@ class Event extends \yii\db\ActiveRecord
170 170  
171 171  
172 172 while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
173   - if(isset($data[0]) && isset($data[1])){
174   - $product = ProductVariant::find()->where(['sku' => $data[1]])->joinWith('product')->one();
  173 + if(isset($data[0])){
  174 + $product = ProductVariant::find()->where(['sku' => $data[0]])->joinWith('product')->one();
175 175 if($product instanceof ProductVariant){
176   - $model= EventsToProducts::find()->where(['event_id' =>$data[0], 'product_id' => $product->product->id ])->one();
  176 + $model= EventsToProducts::find()->where(['event_id' =>$this->id, 'product_id' => $product->product->id ])->one();
177 177 if(!$model instanceof EventsToProducts){
178 178 $model = new EventsToProducts;
179   - $model->event_id = $data[0];
  179 + $model->event_id = $this->id;
180 180 $model->product_id = $product->product->id;
181 181 $model->save();
182 182 }
... ... @@ -190,7 +190,7 @@ class Event extends \yii\db\ActiveRecord
190 190 }
191 191  
192 192 public function getProducts(){
193   - return $this->hasMany(Product::className(),['product_id' => 'product_id'] )->viaTable('events_to_products', ['id' => 'event_id']);
  193 + return $this->hasMany(Product::className(),['id' => 'product_id'] )->viaTable('events_to_products', ['event_id' => 'id']);
194 194 }
195 195  
196 196 public static function getSaleEvents(){
... ...
views/event/index.php
... ... @@ -25,10 +25,7 @@ $this->params['breadcrumbs'][] = $this->title;
25 25 'filterModel' => $searchModel,
26 26 'columns' => [
27 27 ['class' => 'yii\grid\SerialColumn'],
28   -
29   - 'id',
30   - 'lang.title',
31   - 'lang.alias',
  28 + 'lang.title:ntext',
32 29 'imageUrl:image',
33 30 // 'meta_title',
34 31 // 'description',
... ...