/** * 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]); } }
/** * 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]); } }
/** * Import/Scrap a new Package model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionImport() { $model = new Package(); if (Yii::$app->request->isPost) { $product_url = $_POST['Package']['product_url']; $scraped = $this->_scrapAliExpressProduct($product_url); if (!empty($scraped['store_id'])) { $check_flag = Store::find()->where(['store_number' => $scraped['store_id']])->exists(); if ($check_flag == false) { $store = new Store(); $store->store_number = $scraped['store_id']; $store->name = urldecode($scraped['store_name']); $store->location = $scraped['store_location']; $store->since = date('Y-m-d', strtotime($scraped['store_since'])); $store->notes = "Import request Initiated from IP '" . Yii::$app->request->userIP . "'\n"; $store->save(); $data = ArrayHelper::toArray($store->id); $store_internal_id = $data[0]; } else { // store found so do nothing $primary = Store::find()->where(['store_number' => $scraped['store_id']])->one(); $data = ArrayHelper::toArray($primary); if ($primary != false) { $store_internal_id = $data['id']; } else { $store_internal_id = 0; } } } else { // if seller (store) information in unavailable $store_internal_id = 133; } // start updating the fields with latest data $model->store_id = $store_internal_id; $model->order_id = $_POST['Package']['order_id']; $model->order_date = date('Y-m-d'); // lets go with today's date $model->paid_with = "4"; // lets go with SCB-DebitCard $model->product_url = $product_url; $model->price = substr($scraped['price'], 0, 5); $model->description = substr($scraped['name'], 0, 75); $model->status = "Awaiting Shipment"; $model->notes = "Import request Initiated from IP '" . Yii::$app->request->userIP . "'\n" . "Data scrapped from " . $product_url; $model->save(); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('import', ['model' => $model]); } }
public function actionInstall($code, $shop_domain) { $store = Store::findOne(['domain' => $shop_domain]); if (!$store) { $store = new Store(); $store->domain = $shop_domain; } $client = $store->getClient(); if (!$client->validateSignature(Yii::$app->request->get())) { throw new UnauthorizedHttpException(__('Error validate signature')); } $store->access_token = $client->requestAccessToken($code); $store->save(); Yii::$app->session->set('shop_domain', $shop_domain); return $this->redirect(['index']); }
/** * 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]); }