/** * Creates a new ElizeProduct model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ElizeProduct(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * @param Response $result */ private function saveElizeResult(Response $result) { $product = ElizeProduct::findOne(['article' => $result->getArticle()]); if (!$product) { $product = new ElizeProduct(); } $product->attributes = $result->toArray(); $product->new_price = !empty($result->getNewPrice()) ? $result->getNewPrice() : null; $product->old_price = !empty($result->getPrice()) ? $result->getPrice() : null; $product->deleted_at = '0000-00-00 00:00:00'; try { $ePrice = new ElizePrice(); $ePrice->article = $result->getArticle(); $ePrice->old_price = $product->old_price; $ePrice->new_price = $product->new_price; if ($product->save()) { $ePrice->save(); } else { \Yii::error(sprintf('Ошибка сохранения артикула E: %s data: %s', $result->getArticle(), json_encode($result->toArray())), 'cron'); } } catch (\Exception $e) { \Yii::error(sprintf('Exception %s сохранения артикула E %s data: %s', $e->getMessage(), $result->getArticle(), json_encode($result->toArray())), 'cron'); } }