public function delete()
 {
     $id = \Input::get('id');
     $product = Products::find($id);
     $status = $product->delete() ? 1 : 0;
     return \Response::json($status);
 }
Пример #2
0
 /**
  * @param UpdateCartBindingModel $input
  * @param Products $product
  */
 public function update(UpdateCartBindingModel $input, Products $product)
 {
     $errors = [];
     foreach ($input->getQuantity() as $product_id => $item) {
         $check = $product->checkQuantity($product_id);
         if ($check < $item) {
             array_push($errors, "Product <b>" . $product->getName($product_id) . "</b> has max quantity: {$check}");
         }
     }
     if (count($errors) > 0) {
         $this->redirect->to('/cart')->withErrors($errors)->go();
     } else {
         $this->session->getSession()->cart = $input->getQuantity();
     }
     $this->redirect->to('/cart')->go();
 }
Пример #3
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');
     }
 }
Пример #4
0
 public static function get_slite_products($user_id)
 {
     //Redirect to view products
     $Prod = Products::where('user_id', '=', $user_id)->get();
     $Prod = json_decode(json_encode($Prod), true);
     //print_r($Prod);
     //die();
     return $Prod;
 }
 /**
  * Get statistic data.
  *
  * @return Response
  */
 public function monthStatistic($month, $year, Request $request)
 {
     $statistics = new \stdClass();
     $StatisticEndDate = Carbon::create($year, $month, 1, 0, 0, 0)->addMonth(1);
     $StatisticStartDate = Carbon::create($year, $month, 1, 0, 0, 0);
     $statistics->companies = [Companies::whereNull("Deleted")->where("Date_Created", "<", $StatisticEndDate)->where("Date_Created", ">", $StatisticStartDate)->get()->count(), Companies::whereNull("Deleted")->get()->count()];
     $statistics->products = [Products::whereNull("Deleted")->where("Date_Created", "<", $StatisticEndDate)->where("Date_Created", ">", $StatisticStartDate)->get()->count(), Products::whereNull("Deleted")->get()->count()];
     $statistics->news = [News::whereNull("Deleted")->where("Date_Created", "<", $StatisticEndDate)->where("Date_Created", ">", $StatisticStartDate)->get()->count(), News::whereNull("Deleted")->get()->count()];
     $statistics->people = [People::whereNull("Deleted")->where("Date_Created", "<", $StatisticEndDate)->where("Date_Created", ">", $StatisticStartDate)->get()->count(), People::whereNull("Deleted")->get()->count()];
     return json_encode($statistics);
 }
Пример #6
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 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;
 }
 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]);
     }
 }
Пример #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;
 }
Пример #10
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;
 }
Пример #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, '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;
 }
Пример #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->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;
 }
Пример #13
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;
 }
Пример #14
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;
 }
Пример #15
0
 public function buyItem(Request $request)
 {
     $subTotal = 0;
     $data = $request->input('products');
     Session::put('product_info', $data);
     $payer = Paypalpayment::payer();
     $payer->setPaymentMethod("paypal");
     $products = Products::whereIn('id', array_keys($data))->get();
     foreach ($products as $product) {
         $quantity = $data[$product->id]['quantity'];
         $quantity = $product->quantity < $quantity ? $product->quantity : $quantity;
         $product_list[] = Paypalpayment::item()->setName($product->name)->setDescription($product->id)->setCurrency('USD')->setQuantity($quantity)->setPrice($product->price);
         $subTotal += $product->price * $quantity;
     }
     $itemList = Paypalpayment::itemList();
     $itemList->setItems($product_list);
     $details = Paypalpayment::details();
     $details->setShipping("100")->setTax("10")->setSubtotal($subTotal);
     //Payment Amount
     $amount = Paypalpayment::amount();
     $amount->setCurrency("USD")->setTotal($subTotal + 110)->setDetails($details);
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $transaction = Paypalpayment::transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
     // ### Payment
     // A Payment Resource; create one using
     // the above types and intent as 'sale'
     $baseUrl = url();
     $redirectUrls = Paypalpayment::redirectUrls();
     $redirectUrls->setReturnUrl("{$baseUrl}/paypal/ok")->setCancelUrl("{$baseUrl}/paypal/error");
     $payment = Paypalpayment::payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         // ### Create Payment
         // Create a payment by posting to the APIService
         // using a valid ApiContext
         // The return object contains the status;
         $payment->create($this->_apiContext);
     } catch (\PPConnectionException $ex) {
         return "Exception: " . $ex->getMessage() . PHP_EOL;
         exit(1);
     }
     //dd($payment);
     return redirect($payment->getApprovalLink());
 }
Пример #16
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;
 }
Пример #17
0
 public function search($input)
 {
     $query = Products::query();
     $columns = Schema::getColumnListing('products');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
Пример #18
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;
 }
Пример #19
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);
     }
 }
Пример #20
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]);
 }
Пример #21
0
 function get_tovar_url($id)
 {
     $tovar = Products::findOne(['id' => $id]);
     $cat = ModArendaTree::findOne(['id' => $tovar->cat_id]);
     $url = [];
     $url[] = $cat->url;
     while ($cat->parent_id != 0) {
         $cat = ModArendaTree::findOne(['id' => $cat->parent_id]);
         $url[] = strtolower($cat->url);
     }
     $total_url = '/catalog';
     for ($i = count($url) - 1; $i >= 0; $i--) {
         $total_url .= '/' . $url[$i];
     }
     $total_url .= '/' . strtolower($this->translit($tovar->name)) . '-' . $tovar->id;
     return $total_url;
 }
Пример #22
0
 public function actionIndex($id)
 {
     assert($id > 0);
     $product = Products::findOne($id);
     assert(isset($product));
     $model = new OrderForm();
     if (Yii::$app->request->isPost) {
         //POST
         $model->load(Yii::$app->request->post());
         if ($model->validate()) {
             //TODO: store order in DB
             $order = new Order();
             //etc.............
             return $this->render('success');
         } else {
             $errors = $model->errors;
         }
     } else {
         //GET
     }
     $model->Product = $product;
     return $this->render('index', ['model' => $model]);
 }
Пример #23
0
 public function Search()
 {
     if (!empty($_POST['search-control'])) {
         $search = $_POST['search-control'];
         $products = Products::where('products_name', 'LIKE', '%' . $search . '%')->get();
         $test = count($products);
         if ($test != 0) {
             foreach ($products as $product) {
                 echo $product->product_title;
                 echo $product->product_image;
                 echo $product->products_name;
                 echo $product->product_desc;
                 echo $product->Products_price;
                 echo $product->product_desc;
             }
         } else {
             // Make redirect to 404 page
             echo "404 page";
         }
     } else {
         echo "Empty field";
     }
 }
Пример #24
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);
 }
Пример #25
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]);
 }
Пример #26
0
 public function addCart()
 {
     if (count(Session::get('user_id')) == 0) {
         return redirect('Login');
     } else {
         $Pros = Products::leftJoin('shoppingcart', 'products_id', '=', 'prod_id')->where("products_id", "=", Input::get('btn_hidden_id'))->get();
         foreach ($Pros as $Pro) {
             if ($Pro->prod_id == true && $Pro->cart_user_id == true) {
                 for ($this->qtyC = $Pro->cart_pro_qty; $this->qtyC <= $Pro->cart_pro_qty; $this->qtyC++) {
                     $qtyCart = $this->qtyC += 1;
                     $this->getFullPriceProd = $Pro->Products_price * $this->qtyC;
                     DB::table('shoppingcart')->where('prod_id', "=", Input::get('btn_hidden_id'))->update(array('cart_pro_qty' => $qtyCart, 'full_prise_prod' => $this->getFullPriceProd));
                 }
                 return redirect('Shoppingcart');
                 exit;
             } else {
                 $this->qtyC = '1';
                 $this->getFullPriceProd = $Pro->Products_price * $this->qtyC;
                 DB::table('shoppingcart')->insert(['shoppingcart_prod_name' => $Pro->products_name, 'shoppingcart_prod_price' => $Pro->Products_price, 'full_prise_prod' => $this->getFullPriceProd, 'shoppingcart_prod_title' => $Pro->product_title, 'shoppingcart_prod_label' => $Pro->products_label, 'shoppingcart_prod_img' => $Pro->product_image, 'cart_pro_qty' => $this->qtyC, 'cart_user_id' => Session::get('user_id'), 'prod_id' => $Pro->products_id]);
                 return redirect('Shoppingcart');
             }
         }
     }
 }
Пример #27
0
    <a href="" id="page"></a>

    <div class="container-fluid review-bg">
        <div class="title"> <?php 
echo Products::reviews($item->id, 2) . ' ' . Yii::t('easyii', 'reviews');
?>
 </div>
        <p class="product-star text-center">
           
            <input value="<?php 
echo $totalreviews;
?>
" type="number" class="rating" min=0 max=5 step=0.5 data-size="xs" readonly="readonly">
          <?php 
echo Products::reviews($item->id);
?>

        </p>
        <button class="btn dry-btn center-block" data-toggle="modal" data-target="#writeReview">
            <i class="fa fa-pencil fa-lg"></i> <?php 
echo Yii::t('easyii', 'Write a review');
?>
</button>
        <!-- Modal -->

<div class="modal fade" id="writeReview" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Пример #28
0
 public function syncData()
 {
     $user_id = Auth::user()->id;
     $store_name = $this->get_store_name($user_id);
     $shopify = new Shopify(Token::$shopify_api_key, Token::$shopify_secret_key, $store_name);
     $rAllProducts = $shopify->get_all_products('GET');
     $rVariants = array();
     $sValues = "";
     $rInsert = array();
     foreach ($rAllProducts as $rP) {
         foreach ($rP as $rPP) {
             $rVariants[] = $rPP['variants'];
         }
     }
     foreach ($rVariants as $rV) {
         foreach ($rV as $rVV) {
             $rInsert[] = array('sku' => $rVV['sku'], 'product_name' => $rVV['title'], 'quantity' => $rVV['inventory_quantity'], 'price' => $rVV['price']);
         }
     }
     //print_r($rInsert);
     $rProd = Products::where('user_id', '=', $user_id)->get();
     $rProd = json_decode(json_encode($rProd), true);
     //Make SKU the key
     $rData = array();
     foreach ($rProd as $rP) {
         $key = $rP['sku'];
         $rData[$key]['product_name'] = $rP['product_name'];
         $rData[$key]['quantity'] = $rP['quantity'];
         $rData[$key]['price'] = $rP['price'];
     }
     $rDiff = array();
     $rNew = array();
     //print_r($rInsert);
     //die();
     //Compare both arrays now to see any difference and get the difference in new array
     foreach ($rInsert as $rI) {
         if (isset($rData[$rI['sku']])) {
             //Check for product_name, quantity,price
             if ($rI['product_name'] != $rData[$rI['sku']]['product_name']) {
                 $rDiff[$rI['sku']]['product_name'] = $rI['product_name'];
             }
             if ($rI['quantity'] != $rData[$rI['sku']]['quantity']) {
                 $rDiff[$rI['sku']]['quantity'] = $rI['quantity'];
             }
             if ($rI['price'] != $rData[$rI['sku']]['price']) {
                 $rDiff[$rI['sku']]['price'] = $rI['price'];
             }
         } else {
             $rNew[$rI['sku']]['product_name'] = $rI['product_name'];
             $rNew[$rI['sku']]['quantity'] = $rI['quantity'];
             $rNew[$rI['sku']]['price'] = $rI['price'];
         }
     }
     //Update each changed entry
     foreach ($rDiff as $rK => $rV) {
         $sQ = "update lookup_products set ";
         foreach ($rV as $rKK => $rVV) {
             $sQ .= "{$rKK} = '{$rVV}',";
         }
         $sQ = substr($sQ, 0, -1);
         $sQ .= " where sku = ?";
         DB::update($sQ, [$rK]);
     }
     //Add new Entry
     foreach ($rNew as $rK => $rV) {
         $sQ = "insert into lookup_products (sku,product_name,quantity,price,user_id) values (?, ?, ?, ?, ?)";
         DB::insert($sQ, [$rK, $rV['product_name'], $rV['quantity'], $rV['price'], $user_id]);
     }
     //Redirect to view products
     $Prod = Products::where('user_id', '=', $user_id)->get();
     return view('products.index', ['lookup_products' => $Prod]);
 }
Пример #29
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;
    }
Пример #30
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $product = Products::findOrFail($id);
     $product->fill(["Deleted" => Carbon::now()])->save();
     return redirect(route('admin.products.index'));
 }