/**
  * Updates an existing Store model.
  * If update is successful, the browser will be redirected to the 'update' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id = null)
 {
     if ($id) {
         $store = $this->findModel($id);
     } else {
         $store = new Store();
     }
     if ($store->load(Yii::$app->request->post()) && $store->save()) {
         Yii::$app->session->setFlash('success', __('Your changes has been saved successfully.'));
         return $this->redirect(['index']);
     } else {
         $model = new OptionsForm();
         $model->setStore($store);
         $request = Yii::$app->request;
         if ($request->isPost) {
             $model->load($request->post());
             if ($model->saveOptions()) {
                 $store->touch('updated_at');
                 $store->save();
                 Yii::$app->session->setFlash('success', __('Your changes has been saved successfully.'));
             }
             return $this->redirect(['update', 'id' => $store->id]);
         }
         return $this->render('update', ['store' => $store, 'model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates a new Store model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $coordinate = new Coordinate();
     $store = new Store();
     if ($coordinate->load(Yii::$app->request->post()) && $coordinate->validate() && $store->load(Yii::$app->request->post()) && $store->validate()) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $coordinate->save(false);
             $store->coordinate_id = $coordinate->id;
             $store->save(false);
             $transaction->commit();
             return $this->redirect(['view', 'id' => $store->id]);
         } catch (Exception $e) {
             $transaction->rollBack();
         }
     }
     return $this->render('create', ['coordinate' => $coordinate, 'store' => $store]);
 }
Пример #3
0
 /**
  * Import/Scrap a new Store model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionImport()
 {
     $model = new Store();
     if (Yii::$app->request->isPost) {
         //print_r(Yii::$app->request->post());
         $store_number = intval($_POST['Store']['store_number']);
         $scraped = $this->_scrapAliExpressStore($store_number);
         // start updating the fields with latest data
         $model->name = $scraped[1];
         $model->location = $scraped[2];
         $model->since = date('Y-m-d', strtotime($scraped[3]));
         $model->notes = "Import request Initiated from IP '" . Yii::$app->request->userIP . "'\n";
         $model->save();
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('import', ['model' => $model]);
     }
 }