public function actionIndex() { $countOrders = Orders::find()->count(); $countCatalogs = Catalogs::find()->where(['not', ['name' => 'ROOT']])->count(); $countProducts = Products::find()->count(); return $this->render('index', ['countOrders' => $countOrders, 'countCatalogs' => $countCatalogs, 'countProducts' => $countProducts]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Orders::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $this->load($params); // if (!$this->validate()) { // // uncomment the following line if you do not want to any records when validation fails // // $query->where('0=1'); // return $dataProvider; // } // $dateFrom = Yii::$app->request->queryParams['date_from']; // $dateTo = strtotime(Yii::$app->request->queryParams['date_to']); // $dateFrom = strtotime(Yii::$app->request->queryParams['date_from']); // $dateTo = strtotime(Yii::$app->request->queryParams['date_to']); $dateFrom = \DateTime::createFromFormat('d.m.Y', Yii::$app->request->queryParams['date_from']); $dateTo = \DateTime::createFromFormat('d.m.Y', Yii::$app->request->queryParams['date_to']); if ($dateFrom) { $query->andWhere(['>=', 'create_time', $dateFrom->format('Y-m-d')]); } if ($dateTo) { $query->andWhere(['<=', 'create_time', $dateTo->format('Y-m-d')]); } // if ($dateTo!==null) { // $query->andWhere(['<=', 'create_time', $dateTo]); // } // print_r($query); // $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
protected function findModel($pk) { if (($model = Orders::findOne($pk)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionIndex() { $products = Yii::$app->cart->getPositions(); $searchModel = new ProductsCartSearch(); $dataProvider = $searchModel->search($products); $order = new Orders(); $order->scenario = 'newOrder'; if (Yii::$app->request->post()) { $order->load(Yii::$app->request->post()); $summa = Yii::$app->cart->getCost(); $order->summa = $summa; $order->status = Orders::STATUS_NEW; if ($order->save()) { Yii::$app->cart->removeAll(); Yii::$app->session->setFlash('order', ['id' => $order->order_id, 'email' => $order->email, 'name' => $order->name]); return Yii::$app->getResponse()->refresh(); } } return $this->render('index', ['products' => $products, 'dataProvider' => $dataProvider, 'order' => $order]); }
public function getFormattedCreateTime() { $newOrder = Orders::findOne($this->order_id); return \DateTime::createFromFormat('Y-m-d H:i:s', $newOrder->create_time)->format('d.m.Y'); }