Exemple #1
0
 public function init()
 {
     parent::init();
     //Get cart items and calculate total value
     //Cookie cart array type : ['product_id' => 'quantity', ...]
     $cart_info = \Yii::$app->request->cookies->getValue('cart');
     if ($cart_info !== null) {
         $products = unserialize($cart_info);
         if (is_array($products)) {
             $product_ids = array_keys($products);
             $product_models = ProductModel::getProducts($product_ids);
             //find()->where(['id'=>$product_ids])->all();
             foreach ($product_models as $product_model) {
                 $this->value += $product_model->price * $products[$product_model->id];
                 $this->items += $products[$product_model->id];
                 \Yii::info('Quantity of ' . $product_model->id . ' (' . $product_model->price . ') - ' . $products[$product_model->id]);
             }
         }
     }
     if ($this->value > 0) {
         $this->message = "\$('.cart').addClass('active'); \$('.cart').append(\"<span class='cart-value'> ({$this->value} ₴ - {$this->items} items)</span>\");";
     } else {
         $this->message = "";
     }
 }
 public function actionView($id)
 {
     $categories = CategoryModel::getAllUsingColumns();
     $product = ProductModel::getById($id);
     $view = new View();
     $view->categories = $categories;
     $view->product = $product;
     $view->display('product/view.php');
     return true;
 }
Exemple #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'price' => $this->price, 'quantity' => $this->quantity, 'isAvailable' => $this->isAvailable, 'rating' => $this->rating, 'amountRated' => $this->amountRated, 'idCategory' => $this->idCategory]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'photo', $this->photo]);
     return $dataProvider;
 }
Exemple #4
0
 public function actionView()
 {
     $cart_info = \Yii::$app->request->cookies->getValue('cart');
     $cart_info = unserialize($cart_info);
     if (is_array($cart_info)) {
         $products = ProductModel::getProducts(array_keys($cart_info));
         //find()->where(['id'=>array_keys($cart_info)])->all();
         $shippings = ShippingModel::getShippings();
         //find()->all();
         return $this->render('view', ['cart' => $cart_info, 'products' => $products, 'shippings' => $shippings]);
     } else {
         return $this->render('empty');
     }
 }
 public function actionView($id)
 {
     $order = ProductOrderModel::getById($id);
     $productsArray = json_decode($order->products, true);
     $productsIds = implode(', ', array_keys($productsArray));
     $products = ProductModel::getAll($productsIds);
     $countProducts = ProductOrderModel::countProductsInOrder($productsArray);
     $amountProducts = ProductOrderModel::amountProductsPriceInCart($productsArray, $products);
     $view = new View();
     $view->products = $products;
     $view->productsArray = $productsArray;
     $view->countProducts = $countProducts;
     $view->amountProducts = $amountProducts;
     $view->display('admin_order/view.php');
     return true;
 }
 public function actionAdd()
 {
     $model = new CommentModel();
     $model->date = date("Y-m-d");
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $product = ProductModel::find()->where(['id' => $model->idProduct])->one();
         $product->rating = ($product->rating * $product->amountRated + $model->mark) / ($product->amountRated + 1);
         $product->amountRated = $product->amountRated + 1;
         if (!$product->save()) {
             echo "Error updating product.";
         }
     } else {
         echo "Error adding comment.";
     }
     return $this->redirect(\Yii::$app->user->getReturnUrl());
 }
Exemple #7
0
 public function actionIndex()
 {
     $showProducts = FL::fileGetContents('product_count_main_page.txt');
     if (!$showProducts) {
         $showProducts = 6;
     }
     $categories = CategoryModel::getAllUsingColumns();
     $products = ProductModel::getAllUsingColumns(true, $showProducts);
     $recommended = ProductModel::getAllByColumn('is_recommended', '1');
     $view = new View();
     $view->categories = $categories;
     $view->products = $products;
     $view->recommended = $recommended;
     $view->display('site/index.php');
     return true;
 }
 public function actionDelete($id)
 {
     $product = ProductModel::getById($id);
     if (isset($_POST['delNo'])) {
         FL::redirectTo('/admin/product');
     }
     if (isset($_POST['delYes'])) {
         $result = ProductModel::delete($id);
         if ($result) {
             FL::redirectTo('/admin/product');
         }
     }
     $view = new View();
     $view->product = $product;
     $view->display('admin_product/delete.php');
     return true;
 }
 public function actionCategory($categoryId, $page = 1)
 {
     $limit = FL::fileGetContents('product_count_category_page.txt');
     if (!$limit) {
         $limit = 9;
     }
     $page = (int) $page;
     $categories = CategoryModel::getAllUsingColumns();
     $products = ProductModel::getByCategoryId($categoryId, $limit, $page);
     if (!$products) {
         $products = [];
     }
     $total = ProductModel::getTotal('category_id', $categoryId);
     $pagination = FL::buildPagination($total, $page, $limit, 'page-');
     $view = new View();
     $view->categories = $categories;
     $view->products = $products;
     $view->categoryId = $categoryId;
     if (isset($pagination)) {
         $view->pagination = $pagination;
     }
     $view->display('catalog/category.php');
     return true;
 }
Exemple #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdProduct0()
 {
     return $this->hasOne(ProductModel::className(), ['id' => 'idProduct']);
 }
Exemple #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdProducts()
 {
     return $this->hasMany(ProductModel::className(), ['id' => 'idProduct'])->viaTable('{product_list}', ['idOrder' => 'id']);
 }
Exemple #12
0
 public static function getProductsInCategories($categoryIds)
 {
     $result_products = array();
     foreach ($categoryIds as $categoryId) {
         $products = \Yii::$app->cache->get('products_category_' . $categoryId);
         if ($products === false) {
             $products = ProductModel::find()->where(['idCategory' => $categoryId])->all();
             \Yii::$app->cache->add('products_category_' . $categoryId, $products);
         }
         foreach ($products as $product) {
             $result_products[] = $product;
         }
     }
     return $result_products;
 }
Exemple #13
0
 public function actionOrder()
 {
     $userName = '';
     $errors = [];
     $categories = CategoryModel::getAllUsingColumns();
     $productsKeysArray = Session::getSession('products');
     if ($productsKeysArray) {
         $keysArray = array_keys($productsKeysArray);
         $keysString = implode(',', $keysArray);
         if ($keysString) {
             $products = ProductModel::getAll($keysString);
             $amountPrice = CartModel::amountProductsPriceInCart($productsKeysArray, $products);
         }
     }
     $user = UserModel::getUser('user');
     if ($user) {
         $userName = $user->name;
         $userId = $user->id;
     } else {
         $userId = 0;
     }
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $phone = FL::clearStr($_POST['phone']);
         $comment = FL::clearStr($_POST['comment']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isValue($phone)) {
             $errors[] = 'Телефон не может быть пустым';
         }
         if (!FL::isPhone($phone)) {
             $errors[] = 'Невалидный телефон';
         }
         if (!FL::isValue($comment)) {
             $errors[] = 'Комментарий не может быть пустым';
         }
         if (empty($errors)) {
             $productsKeysArray = Session::getSession('products');
             if ($productsKeysArray) {
                 $products = json_encode($productsKeysArray);
             }
             $cart = new CartModel();
             $cart->user_name = $name;
             $cart->user_phone = $phone;
             $cart->user_comment = $comment;
             $cart->user_id = $userId;
             $cart->products = $products;
             $orderId = $cart->save();
             if ($orderId) {
                 Session::deleteSession('products');
                 Session::createSession('message', 'Заказ оформлен!');
                 FL::redirectTo('/cart');
             }
         }
     } else {
         $countProducts = CartModel::countProductsInCart();
         if ($countProducts <= 0) {
             FL::redirectTo('/');
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->amountPrice = $amountPrice;
     $view->userName = $userName;
     $view->errors = $errors;
     $view->display('cart/order.php');
     return true;
 }
Exemple #14
0
use app\models\CharacteristicModel;
use app\models\ProductModel;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model app\models\CharacteristicValueModel */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="characteristic-value-model-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'idProduct')->dropDownList(ArrayHelper::map(ProductModel::find()->all(), 'id', 'name'));
?>

    <?php 
echo $form->field($model, 'idCharacteristic')->dropDownList(ArrayHelper::map(CharacteristicModel::find()->all(), 'id', 'name'));
?>

    <?php 
echo $form->field($model, 'value')->textInput(['maxlength' => 50]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
 /**
  * 初始化搜索表
  */
 public function init()
 {
     //在线创作表
     $products = ProductModel::all();
     if (count($products)) {
         $rst['product'] = $this->tochange($products, 'product');
     } else {
         $rst['product'] = "在线创作表 product 没有记录!";
     }
     //上传的产品表
     $goods = GoodsModel::all();
     if (count($goods)) {
         $rst['goods'] = $this->tochange($goods, 'goods');
     } else {
         $rst['goods'] = "上传的产品表 goods 没有记录!";
     }
     //创意表
     $ideas = IdeasModel::all();
     if (count($ideas)) {
         $rst['idea'] = $this->tochange($ideas, 'idea');
     } else {
         $rst['idea'] = "创意表 idea 没有记录!";
     }
     //分镜表
     $storyboards = StoryBoardModel::all();
     if (count($ideas)) {
         $rst['storyboard'] = $this->tochange($storyboards, 'storyboard');
     } else {
         $rst['storyboard'] = "分镜表 storyboard 没有记录!";
     }
     //公司表
     $companys = CompanyModel::all();
     if (count($ideas)) {
         $rst['company'] = $this->tochange($companys, 'company');
     } else {
         $rst['company'] = "公司表 company 没有记录!";
     }
     //影视作品表
     $works = WorksModel::all();
     if (count($works)) {
         $rst['works'] = $this->tochange($works, 'works');
     } else {
         $rst['works'] = "作品表 works 没有记录!";
     }
     //演员表
     $actors = StaffModel::where('genre', 1)->get();
     if (count($actors)) {
         $rst['actor'] = $this->tochange($actors, 'actor');
     } else {
         $rst['actor'] = "人员表演员 actor 没有记录!";
     }
     //租赁表
     $rents = RentModel::all();
     if (count($rents)) {
         $rst['rent'] = $this->tochange($rents, 'rent');
     } else {
         $rst['rent'] = "租赁表 rent 没有记录!";
     }
     //设计表
     $designs = DesignModel::all();
     if (count($designs)) {
         $rst['design'] = $this->tochange($designs, 'design');
     } else {
         $rst['design'] = "设计表 design 没有记录!";
     }
     dd($rst);
 }
 /**
  * Deletes an existing CommentModel model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $product = ProductModel::find()->where(['id' => $model->idProduct])->one();
     if ($product->amountRated > 1) {
         $product->rating = ($product->rating * $product->amountRated - $model->mark) / ($product->amountRated - 1);
     } else {
         $product->rating = 0;
     }
     $product->amountRated = $product->amountRated - 1;
     $product->save();
     $model->delete();
     return $this->redirect(['index']);
 }
 public function getDelete($id)
 {
     $product = \App\Models\ProductModel::find($id);
     if ($product) {
         $product->delete();
     }
 }
 /**
  * Finds the ProductModel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ProductModel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ProductModel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdProducts()
 {
     return $this->hasMany(ProductModel::className(), ['id' => 'idProduct'])->viaTable('{characteristic_value}', ['idCharacteristic' => 'id']);
 }