public function delete()
 {
     $id = \Input::get('id');
     $product = Products::find($id);
     $status = $product->delete() ? 1 : 0;
     return \Response::json($status);
 }
Esempio n. 2
0
 public static function saveImage($model)
 {
     $model->date = date('Y-m-d');
     $maxId = Products::find()->select('max(id)')->scalar();
     $imageName = $maxId + 1;
     // (uniqid('img_')-как вариант, без нагрузки на бд)лучше вариант чем с датой, primary key всегда будет
     // уникальным + запрос вроде не сложный на выборку поскольку primary индексированый и взять максимальное
     // не составит большую нагрузку на бд
     $model->photo = UploadedFile::getInstance($model, 'photo');
     $fullName = Yii::getAlias('@webroot') . '/photos/' . $imageName . '.' . $model->photo->extension;
     $model->photo->saveAs($fullName);
     $img = Image::getImagine()->open($fullName);
     $size = $img->getSize();
     $ratio = $size->getWidth() / $size->getHeight();
     $height = round(Products::IMAGE_WIDTH / $ratio);
     $box = new Box(Products::IMAGE_WIDTH, $height);
     $img->resize($box)->save(Yii::getAlias('@webroot') . '/thumbnails/' . $imageName . '.' . $model->photo->extension);
     $model->thumbnail = '/thumbnails/' . $imageName . '.' . $model->photo->extension;
     $model->photo = '/photos/' . $imageName . '.' . $model->photo->extension;
     $save = $model->save();
     if ($save) {
         return true;
     } else {
         die('product model was not save');
     }
 }
Esempio n. 3
0
 private function getAllModel($brand)
 {
     $products = Products::find()->where(['uid' => Yii::$app->user->id, 'brand' => $brand])->all();
     $model_array = array();
     $model_array['无'] = '无';
     foreach ($products as $item) {
         $name = $item->getAttribute('model');
         $model_array[$name] = $name;
     }
     return $model_array;
 }
 public function actionView($justcategory, $tipus = "lista")
 {
     $categoryData = ProductCategories::find()->where(["slug" => $justcategory])->asArray()->one();
     $sort = new Sort(['attributes' => ['ar' => ['asc' => ['price' => SORT_ASC], 'desc' => ['price' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'Ár'], 'termeknev' => ['asc' => ['products.title' => SORT_ASC], 'desc' => ['products.title' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'Név']]]);
     $sort->sortParam = 'rendezes';
     $dataProvider = new ActiveDataProvider(['query' => Products::find()->where(["products.category" => $categoryData["id"]])->with(["productImages", "productToppings", "productCategory"])->orderBy($sort->orders)]);
     if ($tipus == "lista") {
         return $this->render('category_list', ['categoryData' => $categoryData, 'dataProvider' => $dataProvider, 'sort' => $sort, 'type' => $tipus]);
     } else {
         return $this->render('category_grid', ['categoryData' => $categoryData, 'dataProvider' => $dataProvider, 'sort' => $sort, 'type' => $tipus]);
     }
 }
 public function getProducts($orderId)
 {
     $products = $this->find()->where(["order_id" => $orderId])->asArray()->all();
     if ($products) {
         $out = [];
         foreach ($products as $key => $row) {
             $out[] = array("count" => $row["count"], "product" => Products::find()->where(["id" => $row["product_id"]])->with("productToppings")->asArray()->one(), "feltet" => Json::decode($row["toppings"]));
         }
         return $out;
     }
     return false;
 }
Esempio n. 6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'price' => $this->price, 'quantity' => $this->quantity, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'photo', $this->photo])->andFilterWhere(['like', 'thumbnail', $this->thumbnail]);
     return $dataProvider;
 }
Esempio n. 7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $queryProducts = Products::find();
     $dataProvider = new ActiveDataProvider(['query' => $queryProducts]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $queryProducts->andFilterWhere(['id' => $this->id, 'made_year' => $this->made_year, 'power' => $this->power, 'price' => $this->price]);
     $queryProducts->andFilterWhere(['like', 'model', $this->model])->andFilterWhere(['in', 'id_brand', (new Query())->select('id')->from('brands')->where(['like', 'name', !empty($this->nameBrand) ? $this->nameBrand : ''])]);
     return $dataProvider;
 }
Esempio n. 8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'imeilen' => $this->imeilen, 'status' => $this->status, 'uid' => Yii::$app->user->id]);
     $query->andFilterWhere(['like', 'brand', $this->brand])->andFilterWhere(['like', 'model', $this->model])->andFilterWhere(['like', 'unit', $this->unit])->andFilterWhere(['like', 'info', $this->info])->andFilterWhere(['like', 'class', $this->class]);
     return $dataProvider;
 }
Esempio n. 9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['No' => $this->No, 'Cost' => $this->Cost]);
     $query->andFilterWhere(['like', 'ProductCode', $this->ProductCode])->andFilterWhere(['like', 'ProductName', $this->ProductName])->andFilterWhere(['like', 'Image', $this->Image])->andFilterWhere(['like', 'Type', $this->Type])->andFilterWhere(['like', 'Company', $this->Company]);
     return $dataProvider;
 }
Esempio n. 10
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'buy_price' => $this->buy_price, 'sell_price' => $this->sell_price, 'category_id' => $this->category_id, 'warehouse_id' => $this->warehouse_id, 'quantity' => $this->quantity, 'min_stock' => $this->min_stock, 'max_stock' => $this->max_stock, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'barcode', $this->barcode]);
     return $dataProvider;
 }
Esempio n. 11
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'productmain_id' => $this->productmain_id, 'category_id' => $this->category_id, 'unit_id' => $this->unit_id, 'sub_qty' => $this->sub_qty]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'detail', $this->detail]);
     return $dataProvider;
 }
Esempio n. 12
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->joinWith(['category', 'manufacturer', 'size']);
     $query->andFilterWhere(['product_id' => $this->product_id, 'qty' => $this->qty, 'min_qty' => $this->min_qty, 'price' => $this->price, 'wholesale_price' => $this->wholesale_price, 'visibility' => $this->visibility, 'weight' => $this->weight, 'width' => $this->width, 'height' => $this->height, 'depth' => $this->depth, 'additional_shipping_cost' => $this->additional_shipping_cost, 'flag_active' => $this->flag_active, 'flag_onsale' => $this->flag_onsale, 'flag_visible' => $this->flag_visible, 'flag_show_price' => $this->flag_show_price, 'flag_available' => $this->flag_available, 'available_date' => $this->available_date, 'qty_onsale' => $this->qty_onsale, 'reduction_price' => $this->reduction_price, 'reduction_start_date' => $this->reduction_start_date, 'reduction_end_date' => $this->reduction_end_date, 'flag_reduction' => $this->flag_reduction, 'reduction_type' => $this->reduction_type, 'date_added' => $this->date_added, 'date_update' => $this->date_update]);
     $query->andFilterWhere(['like', 'category_name', $this->category_id])->andFilterWhere(['like', 'manufacturer_name', $this->manufacturer_id])->andFilterWhere(['like', 'product_name', $this->product_name])->andFilterWhere(['like', 'upc_barcode', $this->upc_barcode])->andFilterWhere(['like', 'ean13_barcode', $this->ean13_barcode])->andFilterWhere(['like', 'prod_short_desc', $this->prod_short_desc])->andFilterWhere(['like', 'prod_long_desc', $this->prod_long_desc])->andFilterWhere(['like', 'size_name', $this->size_id])->andFilterWhere(['like', 'size', $this->size]);
     return $dataProvider;
 }
Esempio n. 13
0
 public function price($ids, $id_count)
 {
     $products = array();
     for ($i = 0; $i < count($ids); $i++) {
         $products[] = Products::find()->where(['id' => $ids[$i]])->one();
     }
     $price = 0;
     for ($i = 0; $i < count($ids); $i++) {
         $price += $products[$i]->price * $id_count[$i];
     }
     if (Yii::$app->session->get('value_of_code')) {
         Yii::$app->session->set('price', $price * Yii::$app->session->get('value_of_code'));
     } else {
         Yii::$app->session->set('price', $price);
     }
 }
Esempio n. 14
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'cost' => $this->cost]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Esempio n. 15
0
 public function actionProduct($id = null)
 {
     $product = Products::find()->where(['id' => $id])->one();
     $sec = Sections::find(['title'])->where(['id' => $product->section_id])->one();
     $others = Products::find()->orderBy(['date' => SORT_DESC])->where(['section_id' => $product->section_id])->andWhere(['not in', 'id', [$id]])->limit(4)->all();
     $comments = Comments::find()->where(['product_id' => $id])->orderBy(['id' => SORT_DESC])->all();
     $model = new CommentForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $com = new Comments();
         $com->product_id = $id;
         $com->login = Yii::$app->session->get('login');
         $com->comment = $model->comment;
         $com->save();
         return $this->redirect(Yii::$app->request->referrer);
     }
     return $this->render('product', ['product' => $product, 'section_title' => $sec, 'others' => $others, 'model' => $model, 'comments' => $comments]);
 }
 /**
  * Search products based on current criteria
  */
 public function searchAction()
 {
     $numberPage = 1;
     if ($this->request->isPost()) {
         $query = Criteria::fromInput($this->di, "App\\Models\\Products", $this->request->getPost());
         $this->persistent->searchParams = $query->getParams();
     } else {
         $numberPage = $this->request->getQuery("page", "int");
     }
     $parameters = array();
     if ($this->persistent->searchParams) {
         $parameters = $this->persistent->searchParams;
     }
     $products = Products::find($parameters);
     if (count($products) == 0) {
         $this->flash->notice("The search did not find any products");
         return $this->forward("products/index");
     }
     $paginator = new Paginator(array("data" => $products, "limit" => 10, "page" => $numberPage));
     $this->view->page = $paginator->getPaginate();
 }
Esempio n. 17
0
 public function actionIndex()
 {
     var_dump([]);
     exit;
     $data = [];
     $products = \app\models\Products::find()->all();
     foreach ($products as $product) {
         $prodData['product'] = $product;
         $categories = $product->categories;
         foreach ($categories as $category) {
             $prodData['categories'][] = $category;
         }
         $productPictures = $product->productPictures;
         foreach ($productPictures as $productPicture) {
             $prodData['pictures'][] = $productPicture;
         }
         $sales = $product->sales;
         foreach ($sales as $sale) {
             $prodData['sales'][] = $sale;
         }
         $data[] = $prodData;
     }
     return \yii\helpers\Json::encode($data);
 }
Esempio n. 18
0
 public function actionCart()
 {
     $ids = Yii::$app->session->get('ids');
     $id_count = Yii::$app->session->get('id_count');
     $products = array();
     for ($i = 0; $i < count($ids); $i++) {
         $products[] = Products::find()->where(['id' => $ids[$i]])->one();
     }
     $model = new DiscountForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if (!Yii::$app->session->get('value_of_code')) {
             $discount = Discounts::find(['value'])->where(['code' => $model->code])->one();
             if ($discount) {
                 Yii::$app->session->set('price', Yii::$app->session->get('price') * $discount->value);
                 Yii::$app->session->set('value_of_code', $discount->value);
             } else {
                 $error = 'Введен не существующий номер дисконта';
             }
         } else {
             $error = 'Вы уже вводили номер дисконта';
         }
     }
     return $this->render('cart', ['products' => $products, 'id_count' => $id_count, 'model' => $model, 'discount' => $discount, 'error' => $error]);
 }
 public function image($request)
 {
     if (!empty($request->product_id)) {
         $_model = Products::find($request->product_id);
         if ($request->hasFile('file')) {
             $_file = $request->file('file');
             if ($_model->image) {
                 Storage::delete($_model->image);
             }
             $filename = md5(time() . $_file->getClientOriginalName() . $request->product_id) . '.' . $_file->guessClientExtension();
             $request->file('file')->move(config('filesystems.disks.local.root'), $filename);
             $_model->image = $filename;
             $_model->save();
             Logs::create(['activity' => 'image', 'module' => 'products']);
             Cache::tags(['products'])->flush();
             return true;
         } else {
             return new \Exception("Parece que você não selecionou nenhum arquivo");
         }
     } else {
         return new \Exception("Produto não encontrado.");
     }
 }
 /**
  * Lists all Products models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Products::find()->with('productCategory')->asArray(), 'pagination' => ['pageSize' => 10]]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Esempio n. 21
0
 /**
  * Lists all Products models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Products::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Esempio n. 22
0
 public static function AllProducts()
 {
     $all = Products::find()->all();
     return $all;
 }
Esempio n. 23
0
 public function product($productId, Request $request)
 {
     $data = $this->userData($request);
     $product = Products::find($productId);
     $data['ItemCount'] = $this->itemCount($request);
     $data['Product'] = $product;
     $data['title'] = $product->product_name . ' - ' . $product->Author;
     $data['description'] = $product->description;
     return view($product->display_page, $data);
 }
Esempio n. 24
0
 public function destroy($id)
 {
     $product = Products::find($id);
     $product->delete();
     return ['status' => 'success', 'msg' => '删除成功'];
 }
Esempio n. 25
0
 public function setQuantity()
 {
     if (isset($_POST['key']) && isset($_POST['quantity']) && isset($_POST['info'])) {
         $buy_quantity = $_POST['quantity'];
         $product = Products::find($_POST['info']);
         $product_quantity = $product->quantity;
         if ($product_quantity >= $buy_quantity) {
             $line_id = $_POST['key'];
             $cartItem = ShoppingCard::find($line_id);
             $cartItem->quantity = $buy_quantity;
             $cartItem->save();
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Esempio n. 26
0
    function view_cat_products($arr, $parent_id = 0)
    {
        //Условия выхода из рекурсии
        if (empty($arr[$parent_id])) {
            return $this->tree;
        }
        $this->tree .= '<ul>';
        //перебираем в цикле массив и выводим на экран
        for ($i = 0; $i < count($arr[$parent_id]); $i++) {
            $products = Products::find()->where(['cat_id' => $arr[$parent_id][$i]['id']])->all();
            $product_list = '<ul>';
            foreach ($products as $key => $value) {
                $product_list .= '<li>товар:' . $value['name'] . '
                <a href="' . Url::to(['/products/edit', 'id' => $value['id']]) . '"><span class="glyphicon glyphicon-pencil" title="Редактировать"></span></a>
                <a href="' . Url::to(['/products/delete', 'id' => $value['id']]) . '"><span class="glyphicon glyphicon-trash" title="Удалить"></span></a>

                </li>';
            }
            $product_list .= '</ul>';
            $this->tree .= '<li>
                <span class="pl glyphicon glyphicon-chevron-down"></span>
                <a class="pll" href="#">' . $arr[$parent_id][$i]['name'] . '
                </a>

                 ' . (!empty($arr[$arr[$parent_id][$i]['id']]) ? '<b style="margin-left:3px;">Добавить нельзя</b>' : '
                  <a href="' . Url::to(['/products/create', 'parent_id' => $arr[$parent_id][$i]['id']]) . '">
                    <span style = "margin-left:5px;color:#4BBC07" class="glyphicon glyphicon-plus" title="Добавить"></span>
                </a>') . '
                 ';
            //рекурсия - проверяем нет ли дочерних категорий
            $this->view_cat_products($arr, $arr[$parent_id][$i]['id']);
            $this->tree .= $product_list . '</li>';
        }
        $this->tree .= '</ul>';
        return $this->tree;
    }
Esempio n. 27
0
 public function actionGetProductDetail()
 {
     /* @var $product Products */
     Yii::$app->response->format = 'json';
     $return_data = ['status' => 'error', 'data' => []];
     $is_purchase = false;
     if (Yii::$app->request->post('purchase') == 'yes') {
         $is_purchase = true;
     }
     if ($product = Products::find()->where(['barcode' => Yii::$app->request->post('valueBarcode')])->asArray()->one()) {
         if ($product['quantity'] <= 0 and !$is_purchase) {
             $return_data['status'] = 'error';
             $return_data['data'] = $product['name'] . ': Out of Stock';
         } else {
             $return_data['status'] = 'success';
             $product['available'] = $product['quantity'];
             $return_data['data'] = $product;
         }
     }
     return $return_data;
 }
Esempio n. 28
0
<div class="product-pictures-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

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

    <?php 
echo $form->field($model, 'imageFile')->fileInput();
?>

    <?php 
echo $form->field($model, 'product_id')->dropdownList(Products::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => 'Select product']);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Esempio n. 29
0
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\ProductImage */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="product-image-form">

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

    <?php 
echo $form->field($model, 'product_id')->dropDownList(ArrayHelper::map(Products::find()->all(), 'product_id', 'product_name'), ['prompt' => 'Select Product Name']);
?>

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

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

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

    <?php 
Esempio n. 30
0
                    <label for="warehouse_select" class="control-label">Select Warehouse</label>
                    <div class="">
                        <?php 
echo Html::dropDownList('warehouse_select', isset($posted_data['warehouse_select']) ? $posted_data['warehouse_select'] : null, ['0' => 'All'] + ArrayHelper::map(Warehouse::find()->all(), 'id', 'name'), ['class' => 'form-control', 'id' => 'warehouse_select']);
?>
                    </div>
                </div>
            </div>

            <div class="clearfix"></div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label for="products_select" class="control-label">Select Products</label>
                    <div class="">
                        <?php 
echo Select2::widget(['name' => 'products_select', 'value' => isset($posted_data['products_select']) ? $posted_data['products_select'] : 0, 'data' => ['0' => 'All'] + ArrayHelper::map(Products::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'Select Products ...', 'class' => 'form-control', 'id' => 'products_select']]);
?>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <?php 
echo Html::submitButton('Generate Reports', ['class' => 'btn btn-success ']);
?>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>

    <div class="box box-default" >
        <div class="box-body">