public function actionIndex($store_id) { $data = Yii::$app->request->post(); $store = Store::findOne($store_id); if ($store && $data) { $store->webhook($data); } Yii::$app->response->format = 'json'; return ['status' => 'ok']; }
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']); }
public function actionIndex($store_id = 0, $order_id = 0) { $data = Yii::$app->request->post(); if ($data) { if (empty($data['shop_domain'])) { throw new BadRequestHttpException("Shop domain is missing"); } elseif (empty($data['order_info']['order_id'])) { throw new BadRequestHttpException("Order ID is missing"); } elseif (empty($data['return_url'])) { throw new BadRequestHttpException("Return Url is missing"); } elseif (empty($data['cancel_url'])) { throw new BadRequestHttpException("Cancel Url is missing"); } $store = Store::findOne(['domain' => $data['shop_domain']]); if (!$store) { throw new BadRequestHttpException("Store not found"); } // Save data to option $option_name = 'order_' . $data['order_info']['order_id']; $option = Option::findOne(['store_id' => $store->id, 'name' => $option_name]); if (!$option) { $option = new Option(); $option->link('store', $store); $option->name = $option_name; } $option->value = Json::encode($data); $option->save(); return $this->redirect(['index', 'store_id' => $store->id, 'order_id' => $data['order_info']['order_id']]); } elseif ($store_id && $order_id) { $store = Store::findOne($store_id); $option = $this->getOption($store_id, $order_id); $data = Json::decode($option->value); return $this->render('index', ['store' => $store, 'data' => $data, 'order_id' => $order_id]); } else { throw new BadRequestHttpException(); } }
/** * Finds the Store model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Store the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Store::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(__('The requested page does not exist.')); } }