public static function SaveProduct($productXML) { $product_id = (int) $productXML->product_id; $product = Products::findOne($product_id); if (is_null($product)) { // создаем запись $product = new Products(); $product->product_id = (int) $productXML->product_id; $product->catalog_id = (int) $productXML->catalog_id; $product->gallery_id = (int) $productXML->gallery_id; $product->name = (string) $productXML->name; $product->precontent = (string) $productXML->precontent; $product->content = (string) $productXML->content; $product->popular = (int) $productXML->popular; $product->price = (int) $productXML->price; // $product->count = (int) $productXML->count; $product->save(false); } else { // обновляем запись $product->product_id = (int) $productXML->product_id; $product->catalog_id = (int) $productXML->catalog_id; $product->gallery_id = (int) $productXML->gallery_id; $product->name = (string) $productXML->name; $product->precontent = (string) $productXML->precontent; $product->content = (string) $productXML->content; $product->popular = (int) $productXML->popular; $product->price = (int) $productXML->price; // $product->count = (int) $productXML->count; $product->save(false); } }
/** * Creates a new Products model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Products(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'product_id' => $model->product_id]); } else { return $this->render('create', ['model' => $model]); } }