public function searchNewProduct($params) { $query = LetualProduct::find(); // print_r($params);die; $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]); $this->load($params); $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'deleted_at' => $this->deleted_at]); if (!empty($params['date'])) { $query->where('DATE_FORMAT(created_at, "%Y-%m-%d") = "' . $params['date'] . '"'); } $query->andFilterWhere(['like', 'article', $this->article])->andFilterWhere(['like', 'link', $this->link])->andFilterWhere(['like', 'group', $this->group])->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'sub_category', $this->sub_category])->andFilterWhere(['like', 'brand', $this->brand])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'new_price', $this->new_price])->andFilterWhere(['like', 'old_price', $this->old_price])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'image_link', $this->image_link]); return $dataProvider; }
<?php use yii\helpers\Html; /* @var $this yii\web\View */ $this->title = 'Летуаль'; $this->params['breadcrumbs'][] = $this->title; $dataProvider = new \yii\data\ActiveDataProvider(['query' => \app\models\LetualProduct::find(), 'pagination' => ['pageSize' => 20], 'sort' => ['attributes' => ['article', 'group', 'category']]]); ?> <div class="site-about"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo \yii\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $dataProvider, 'layout' => "{sorter}\n{pager}\n{summary}\n{items}", 'columns' => ['article', 'group', 'category', 'sub_category', 'brand', 'title', 'description', ["attribute" => "description", 'filter' => array("1" => "Active", "2" => "Inactive"), 'value' => 'description']]]); ?> <p> This is the About page. You may modify the following file to customize its content: </p> <code><?php echo __FILE__; ?> </code> </div>
public function actionLpodr() { $entity = new LetualProduct(); $offset = 0; do { $products = $entity->getEntity($offset, 20); if (!empty($products)) { foreach ($products as $product) { if (empty($product->letu_id)) { $query = new Query(); $str = ''; $rows = $query->from('pproduct')->match(new Expression(':match', ['match' => '@(description) ' . \Yii::$app->sphinx->escapeMatchValue($product->title)]))->all(); foreach ($rows as $row) { if (!empty($row['id'])) { // проставляем идентификатор $str = $row['id']; break; } } // обновляем таблицу podruzka_product if (!empty($str)) { $productEntity = PodruzkaProduct::findOne(['id' => $str]); if ($productEntity instanceof PodruzkaProduct) { if (empty($productEntity->letu_id)) { $productEntity->letu_id = (string) $product->id; $productEntity->save(); } } } } } $z = 1; $offset += 20; unset($productEntity); unset($query); } else { $z = 0; } } while ($z > 0); return 0; }
/** * @return \yii\db\ActiveQuery */ public function getL() { return $this->hasOne(LetualProduct::className(), ['id' => 'l_id']); }
/** * @return \yii\db\ActiveQuery */ public function getArticle0() { return $this->hasOne(LetualProduct::className(), ['article' => 'article']); }
/** * @return string */ public function actionArticleUpdate() { if ($pArticle = reset($_POST['PodruzkaProduct'])['article']) { if ($pp = PodruzkaProduct::find()->where(['article' => $pArticle])->one()) { if (!empty($_POST['l_id'])) { if ($lp = LetualProduct::find()->where(['article' => $_POST['l_id']])->one()) { $pp->l_id = $lp->id; } } else { $pp->l_id = null; } if (!empty($_POST['r_id'])) { if ($rp = RivegaucheProduct::find()->where(['article' => $_POST['r_id']])->one()) { $pp->r_id = $rp->id; } } else { $pp->r_id = null; } if (!empty($_POST['i_id'])) { if ($ip = IledebeauteProduct::find()->where(['article' => $_POST['i_id']])->one()) { $pp->i_id = $ip->id; } } else { $pp->i_id = null; } if (!empty($_POST['e_id'])) { if ($ep = ElizeProduct::find()->where(['article' => $_POST['e_id']])->one()) { $pp->e_id = $ep->id; } } else { $pp->e_id = null; } $pp->save(); return json_encode(['result' => true]); } } return json_encode(['result' => false]); }
/** * @param Response $result */ private function saveLetualResult(Response $result) { $product = LetualProduct::findOne(['article' => $result->getArticle()]); if (!$product) { $product = new LetualProduct(); } $product->attributes = $result->toArray(); $product->new_price = $result->getNewPrice(); $product->old_price = $result->getPrice(); try { $lPrice = new LetualPrice(); $lPrice->article = $result->getArticle(); if ($result->getPrice()) { $lPrice->old_price = $result->getPrice(); } if ($result->getNewPrice()) { $lPrice->new_price = $result->getNewPrice(); } $product->deleted_at = '0000-00-00 00:00:00'; if ($product->save()) { if (!empty($lPrice->new_price) || !empty($lPrice->new_price)) { $lPrice->save(); } } else { \Yii::error(sprintf('Ошибка сохранения артикула L: %s data: %s', $result->getArticle(), json_encode($result->toArray())), 'cron'); } } catch (\Exception $e) { \Yii::error(sprintf('Exception %s сохранения артикула L %s data: %s', $e->getMessage(), $result->getArticle(), json_encode($result->toArray())), 'cron'); } }
private function saveResult($result) { foreach ($result as $key => $res) { if ($key == 'elements') { foreach ($res as $data) { $product = LetualProduct::findOne(['article' => $data['article']]); if (!$product) { $product = new LetualProduct(); } $product->article = $data['article']; $product->title = $data['title']; $product->description = $data['description']; $letualPrice = new LetualPrice(); $letualPrice->article = $data['article']; $letualPrice->new_price = $this->getPrice($data['price']['newPrice']); $letualPrice->old_price = $this->getPrice($data['price']['oldPrice']); if (!empty($product)) { $product->brand = $this->clearBrand($result['brand']); $product->image_link = !empty($result['image']) ? $result['image'] : $product->image_link; $product->link = $result['link']; $product->group = $result['group']; $product->category = $result['category']; $product->sub_category = $result['sub_category']; $product->new_price = $letualPrice->new_price; $product->old_price = $letualPrice->old_price; $product->save(); if (!empty($letualPrice)) { $letualPrice->save(); } } } } } }
/** * Finds the LetualProduct model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return LetualProduct the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = LetualProduct::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Возвращает строку с инпутами для таблицы с формой сопоставления * * @param $model * * @return string */ public static function getArticleMatchingForm($model) { $result = Html::activeLabel($model, 'l_id'); $result .= Html::input('', 'l_id', !empty($lp = LetualProduct::find()->where(['id' => $model->l_id])->one()) ? $lp->article : '', ['class' => 'kv-editable-input form-control']); $result .= Html::activeLabel($model, 'r_id'); $result .= Html::input('', 'r_id', !empty($lp = RivegaucheProduct::find()->where(['id' => $model->r_id])->one()) ? $lp->article : '', ['class' => 'kv-editable-input form-control']); $result .= Html::activeLabel($model, 'e_id'); $result .= Html::input('', 'e_id', !empty($ep = ElizeProduct::find()->where(['id' => $model->e_id])->one()) ? $ep->article : '', ['class' => 'kv-editable-input form-control']); $result .= Html::activeLabel($model, 'i_id'); $result .= Html::input('', 'i_id', !empty($lp = IledebeauteProduct::find()->where(['id' => $model->i_id])->one()) ? $lp->article : '', ['class' => 'kv-editable-input form-control']); return $result; }