/**
  * Creates a new RivegaucheProduct model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new RivegaucheProduct();
     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 saveResult(Response $result)
 {
     $product = RivegaucheProduct::findOne(['article' => $result->getArticle()]);
     if (!$product) {
         $product = new RivegaucheProduct();
     }
     $product->attributes = $result->toArray();
     try {
         $rPrice = new RivegauchePrice();
         $rPrice->article = $result->getArticle();
         if ($result->getGoldPrice()) {
             $rPrice->gold_price = $result->getGoldPrice();
         }
         if ($result->getBluePrice()) {
             $rPrice->blue_price = $result->getBluePrice();
         }
         if ($result->getPrice()) {
             $rPrice->price = $result->getPrice();
         }
         $product->deleted_at = '0000-00-00 00:00:00';
         if ($product->save()) {
             if (!empty($rPrice->price) || !empty($rPrice->blue_price) || !empty($rPrice->gold_price)) {
                 $rPrice->save();
             }
         } else {
             \Yii::error(sprintf('Ошибка сохранения артикула R: %s data: %s', $result->getArticle(), json_encode($result->toArray())), 'cron');
         }
     } catch (\Exception $e) {
         \Yii::error(sprintf('Exception %s сохранения артикула R %s data: %s', $e->getMessage(), $result->getArticle(), json_encode($result->toArray())), 'cron');
     }
 }
 /**
  * @param $result
  * @param $link
  */
 private function saveResult($result, $link)
 {
     \Yii::info(sprintf('Сохраняем тело: %s ', json_encode($result)), 'cron');
     if (empty($result) || empty($result['link']) || empty($result['title']) || empty($result['category'])) {
         return;
     } else {
         \Yii::error('Ошибка сохранения артикула R: ' . json_encode($result), 'cron');
     }
     preg_match('/[0-9]+$/i', $result['link'], $data);
     $article = $data[0];
     unset($data);
     $product = RivegaucheProduct::findOne(['article' => $article]);
     if (!$product) {
         $product = new RivegaucheProduct();
     }
     $product->brand = $this->clearBrand($result);
     $product->title = $result['title'];
     $product->article = $article;
     $product->category = $link['category'];
     $product->group = $link['group'];
     $product->link = $result['link'];
     $product->sub_category = $link['sub_category'];
     $product->image_link = !empty($result['image_link']) ? $result['image_link'] : '';
     $product->description = !empty($result['description']) ? $result['description'] : '';
     $product->showcases_offer = $result['showcases_offer'];
     $product->showcases_new = $result['showcases_new'];
     $product->showcases_exclusive = $result['showcases_exclusive'];
     $product->showcases_compliment = $result['showcases_compliment'];
     $product->showcases_bestsellers = $result['showcases_bestsellers'];
     $product->showcases_expertiza = $result['showcases_expertiza'];
     $product->gold_price = $this->getPrice($result['price']['gold_price']);
     $product->blue_price = $this->getPrice($result['price']['blue_price']);
     $product->price = $this->getPrice($result['price']['price']);
     try {
         $rPrice = new RivegauchePrice();
         $rPrice->article = $article;
         $rPrice->gold_price = $this->getPrice($result['price']['gold_price']);
         $rPrice->blue_price = $this->getPrice($result['price']['blue_price']);
         $rPrice->price = $this->getPrice($result['price']['price']);
         if ($product->save()) {
             $rPrice->save();
         } else {
             \Yii::error('Ошибка сохранения артикула R: ' . json_encode($result), 'cron');
         }
     } catch (\Exception $e) {
         \Yii::error(sprintf('Exception %s сохранения артикула R: %s', $e->getMessage(), json_encode($result)), 'cron');
     }
 }