/** * Creates a new Vendorproducts model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Vendorproducts(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->Pid]); } else { return $this->render('create', ['model' => $model]); } }
public function actionUpload() { $this->layout = "@app/views/layouts/vendor_left"; $model = new Vendorproducts(); $model->scenario = 'fileup'; if ($model->load(Yii::$app->request->post())) { $model->FileUpload = UploadedFile::getInstance($model, 'FileUpload'); if ($model->FileUpload) { $time = time(); $model->FileUpload->saveAs(realpath(Yii::$app->basePath) . '/csv/' . $time . '.' . $model->FileUpload->extension); $model->FileUpload = realpath(Yii::$app->basePath) . '/csv/' . $time . '.' . $model->FileUpload->extension; $handle = fopen($model->FileUpload, "r"); $i = 0; while (($fileop = fgetcsv($handle, 1000, ",")) !== false) { if ($i >= 1) { $userInfo = Yii::$app->db->createCommand()->insert('saleitems', ['vendorId' => Yii::$app->user->id, 'productId' => $fileop[0], 'Brand' => $fileop[1], 'Quantity' => $fileop[2], 'uom' => $fileop[3], 'AltQty' => $fileop[4], 'AltUom' => $fileop[5], 'UnitPrice' => $fileop[6], 'SalePrice' => $fileop[7], 'PriceUnit' => $fileop[8], 'StartDate' => $fileop[9], 'EndDate' => $fileop[10], 'ReserveCount' => $fileop[11], 'SaleInd' => $fileop[12], 'categoryName' => $fileop[13]])->execute(); } $i++; } $storeMain = new StoresMaster(); $storeMain->vendorId = Yii::$app->user->id; $storeMain->totalSaleItems = $i - 1; $storeMain->offerType = $model->offerType; $storeMain->offer = $model->offer; $storeMain->offerStartDate = $model->offerStartDate; $storeMain->offerEndDate = $model->offerEndDate; $storeMain->save(); Yii::$app->getSession()->setFlash('success', ' Your Products are successfully Updated '); return $this->redirect(['upload']); Yii::$app->getSession()->setFlash('success', ' Only Xlsheets are available '); } } else { return $this->render('vendor_view', ['model' => $model]); } }