/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Products::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'otd' => $this->otd, 'osnls' => $this->osnls, 'tender' => $this->tender, 'cenrozn' => $this->cenrozn, 'obnalichie' => $this->obnalichie, 'kolotgr' => $this->kolotgr]); $query->andFilterWhere(['like', 'mnn', $this->mnn])->andFilterWhere(['like', 'tn', $this->tn])->andFilterWhere(['like', 'kpr', $this->kpr])->andFilterWhere(['like', 'nshort3', $this->nshort3])->andFilterWhere(['like', 'namepr', $this->namepr])->andFilterWhere(['like', 'country', $this->country])->andFilterWhere(['like', 'spar', $this->spar])->andFilterWhere(['like', 'tendergod', $this->tendergod])->andFilterWhere(['like', 'vidtovara', $this->vidtovara])->andFilterWhere(['<=', 'kol', $this->kolTo])->andFilterWhere(['>=', 'kol', $this->kolFrom])->andFilterWhere(['<=', 'goden_do', $this->godenDoTo])->andFilterWhere(['>=', 'goden_do', $this->godenDoFrom])->andFilterWhere(['<=', 'cenopt', $this->cenaoptTo])->andFilterWhere(['>=', 'cenopt', $this->cenaoptFrom])->andFilterWhere(['like', 'vidpost', $this->vidpost]); return $dataProvider; }
protected function parseAndSaveData($reader) { Products::deleteAll(); $report = array('countXml' => 0, 'countDb' => 0, 'notImport' => array()); while ($reader->read()) { if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "Row") { //increment count row in xml-file $report['countXml'] = $report['countXml'] + 1; //AR of the product $product = new Products(); while ($reader->read()) { if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "MNN") { $product->mnn = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "TN") { $product->tn = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "Kpr") { $product->kpr = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "nShort3") { $product->nshort3 = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "NamePr") { $product->namepr = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "Country") { $product->country = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "Otd") { $product->otd = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "OsnLS") { $product->osnls = (int) $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "Tender") { $product->tender = (int) $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "Spar") { $product->spar = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "GodenDo") { $product->goden_do = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "CenOpt") { $product->cenopt = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "CenRozn") { $product->cenrozn = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "Kol") { $product->kol = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "TenderGod") { $product->tendergod = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "VIDTOVARA") { $product->vidtovara = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "OBNALICHIE") { $product->obnalichie = (int) $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "KOLOTGR") { $product->kolotgr = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "VIDPOST") { $product->vidpost = $this->parseRowTag($reader); } if ($reader->nodeType == \XMLReader::ELEMENT && $reader->name == "KodPart") { $product->kodpart = $this->parseRowTag($reader); break; } } if ($product->save()) { $report['countDb'] = $report['countDb'] + 1; } else { $report['notImport'][] = 'код: ' . $product->kpr . ', тн: ' . $product->tn . ';'; } } } return $report; }
/** * Существует ли товар на складе? * @return boolean */ public function getIsProduct() { $condition = ['kodpart' => $this->kodpart, 'otd' => $this->otd, 'namepr' => $this->dsv]; $productModel = Products::findOne($condition); if (!empty($productModel)) { return true; } else { return false; } }
/** * Finds the Products model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Products the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Products::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * добавить продукт к заказу * @param type $id - код лр * @param type $orderId - ид заказа * @return string */ public function actionAddToProductForOrder($id, $orderId) { $product = Products::findOne(['kodpart' => $id]); $model = OrderedProduct::findOne(['kodpart' => $id, 'user_id' => Yii::$app->user->getId(), 'order_id' => $orderId]); if (empty($model)) { $model = new OrderedProduct(); $model->kodpart = $product->kodpart; $model->imn = $product->tn; $model->otd = $product->otd; $model->dsv = $product->namepr; $model->user_id = Yii::$app->user->getId(); $model->buggod = true; } if (Yii::$app->request->isPost) { $post = Yii::$app->request->post(); $model->kolz = (int) $post['kol']; if ($model->save()) { return $model->kolz; } } else { return 'false'; } }