Inheritance: extends Illuminate\Database\Eloquent\Model
 public function actionPayment()
 {
     if (\Yii::$app->session->has('customer')) {
         $modelCustomer = new Customer();
         $infoCustomer = $modelCustomer->getInformation($_SESSION['customer']);
         $modelOrder = new Order();
         $modelOrderDetail = new OrderDetail();
         $modelProduct = new Product();
         $ids = array();
         foreach ($_SESSION['cart_items'] as $id => $quantity) {
             array_push($ids, $id);
         }
         $products = $modelProduct->getWithIDs($ids);
         if (\Yii::$app->request->post()) {
             $modelOrder->load(\Yii::$app->request->post());
             $modelOrder->save();
             $orderId = $modelOrder->id;
             foreach ($_SESSION['cart_items'] as $id => $quantity) {
                 $unitPrice = $modelProduct->getPrice($id) * $quantity;
                 \Yii::$app->db->createCommand()->insert('order_detail', ['orderId' => $orderId, 'productId' => $id, 'unitPrice' => $unitPrice, 'quantity' => $quantity])->execute();
             }
             \Yii::$app->session->remove('cart_items');
             return $this->redirect(['cart/index', 'success' => 'Thanh toán thành công! Chúng tôi sẽ liên hệ bạn trong thời gian sớm nhất! Xin cảm ơn!']);
         } else {
             return $this->render('payment', ['infoCustomer' => $infoCustomer, 'modelOrder' => $modelOrder, 'products' => $products]);
         }
     } else {
         $this->redirect(['customer/login', 'error' => 'Vui lòng đăng nhập trước khi thanh toán']);
     }
 }
 /**
  * Execute the job.
  */
 public function handle()
 {
     /**
      * Create Extra
      * @var Extra $extra
      */
     $extra = $this->product->extras()->create($this->data);
     $aspectDir = @$this->data['aspect_ratio'] ?: '16x9';
     /**
      * Move Extra Content to folder
      */
     $path = '/image/products-extras/';
     $extraID = $extra->getAttribute('id');
     $productCode = $this->product->getAttribute('code');
     $filename = $productCode . '-extra-image-' . $extraID . '.' . $this->image->guessExtension();
     $image = $this->image->move(base_path() . $path, $filename);
     $extra->setAttribute('image', $path . $filename);
     $filename = $productCode . '-extra-video-' . $extraID . '.' . $this->video->guessExtension();
     $video = $this->video->move(base_path() . $path . $aspectDir . '/', $filename);
     $extra->setAttribute('video', $filename);
     $extra->save();
     /**
      * Announce ExtraWasCreated
      */
     event(new ExtraWasCreated($extra));
 }
Exemple #3
0
 public function updatingListProducts($data)
 {
     //pr($data);
     $productModel = new Product();
     foreach ($data as $key => &$element) {
         if (isset($element['GK.site_id'])) {
             $check = $productModel->comparePrice('GK', $key, isset($element['GK.enabled']) ? $element['GK.enabled'] : null, isset($element['GK.yandex_enabled']) ? $element['GK.yandex_enabled'] : null, isset($element['GK.price']) ? addComma($element['GK.price']) : null, isset($element['GK.currency']) ? $element['GK.currency'] : null);
             if ($check) {
                 $element['GK.to_export'] = 1;
             }
         }
         if (isset($element['TV.site_id'])) {
             $check = $productModel->comparePrice('TV', $key, isset($element['TV.enabled']) ? $element['TV.enabled'] : null, isset($element['TV.yandex_enabled']) ? $element['TV.yandex_enabled'] : null, isset($element['TV.price']) ? addComma($element['TV.price']) : null, isset($element['TV.currency']) ? $element['TV.currency'] : null);
             if ($check) {
                 $element['TV.to_export'] = 1;
             }
         }
         if (isset($element['MK.site_id'])) {
             $check = $productModel->comparePrice('MK', $key, isset($element['MK.enabled']) ? $element['MK.enabled'] : null, isset($element['MK.yandex_enabled']) ? $element['MK.yandex_enabled'] : null, isset($element['MK.price']) ? addComma($element['MK.price']) : null, isset($element['MK.currency']) ? $element['MK.currency'] : null);
             if ($check) {
                 $element['MK.to_export'] = 1;
             }
         }
         $this->leftJoin('price_GK as GK', 'products.id', '=', 'GK.product_id')->leftJoin('price_TV as TV', 'products.id', '=', 'TV.product_id')->leftJoin('price_MK as MK', 'products.id', '=', 'MK.product_id')->where('products.id', $key)->update($element);
     }
     /*pr($data,true);*/
 }
Exemple #4
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $pro = new Product();
     $adSlotObj = new Adslot();
     $catObj = new Category();
     $brandObj = new Brand();
     /*getting all products for all slots(currently we have 7 slots)*/
     $adSlot_data = $adSlotObj->with(['products'])->get();
     /*t1-t7*/
     // dd($adSlot_data[4]['products'][0]);
     $category_temp_data = $catObj->orderBy('created_at')->take(10)->get();
     /*f1-f10*/
     $brand_data = $brandObj->with(['products'])->get();
     $category_data = [];
     foreach ($category_temp_data as $cat_id) {
         $cat_latest_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('photo_1');
         $cat_latest_product_id = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('id');
         $cat_random_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy(DB::raw('RAND()'))->take(6)->get();
         $cat_brands = $pro->with(['brand'])->where('category_id', '=', $cat_id['id'])->take(5)->get();
         $cat_products_random_photos = [];
         foreach ($cat_random_product as $photo) {
             $cat_products_random_photos[] = $photo;
         }
         $category_data[] = ['color' => $cat_id['color'], 'floor' => $cat_id['floor'], 'name' => $cat_id['name'], 'desc' => $cat_id['description'], 'logo' => $cat_id['logo'], 'latest_photo_id' => $cat_latest_product_id, 'latest_photo' => $cat_latest_product, 'random_photos' => $cat_products_random_photos, 'brands' => $cat_brands];
     }
     return view('landing_page', compact(['adSlot_data', 'category_data']));
 }
 public function setUp()
 {
     parent::setUp();
     $this->shared('product', function () {
         $product = new Product(["product_name" => "iPhone 6", "product_desc" => "iPhone 6", "status" => "available", "options" => [["name" => "颜色", "options" => ["深空灰", "银色", "金色"]], ["name" => "容量", "options" => ["16GB", "64GB", "128GB"]]], "specifications" => [["attr_name" => "高度", "attr_group" => "重量和尺寸", "attr_value" => "138.1 毫米(5.44 英寸)"], ["attr_name" => "宽度", "attr_group" => "重量和尺寸", "attr_value" => "67.0 毫米 (2.64 英寸)"], ["attr_name" => "厚度", "attr_group" => "重量和尺寸", "attr_value" => "6.9 毫米 (0.27 英寸)"], ["attr_name" => "重量", "attr_group" => "重量和尺寸", "attr_value" => "129 克 (4.55 盎司)"]]]);
         $product->save();
         return $product;
     });
 }
 public function actionIndex()
 {
     $product = new Product('jielun', 50);
     print_r($product->getProductName());
     print_r('<br>---------------<br>');
     $cdProduct = new CdProduct('jay', 20);
     print_r($cdProduct->getProductName());
     //print_r($cdProduct->getAddress());   //子类无法使用parent::$address访问父类的私有属性
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Product $product, Request $request)
 {
     if ($request->ajax()) {
         $request = $request->all();
         $products = $product->filter($request, $this->itemsCount);
         $i = 1;
         return view('admin._response.products-index')->with('products', $products)->with('i', $i);
     }
 }
 /**
  * Execute the job.
  * @param Excel $excel
  */
 public function handle(Excel $excel)
 {
     $excel->create($this->product->code, function ($excel) {
         $excel->sheet($this->product->code, function ($sheet) {
             $codes = $this->codes or $this->product->codes()->get(['code']);
             $sheet->fromArray($codes);
         });
     })->download('xlsx');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(UpdateProductRequest $request, Product $product)
 {
     $data = $request->input();
     $product->fill($data);
     $product->save();
     $this->savePhoto($product, $request);
     $product->categories()->detach($product->categories()->lists('id')->toArray());
     $product->categories()->attach($data['categories']);
     return Redirect()->route('home');
 }
 public function findModel($id)
 {
     $search = new Product();
     $search->scenario = Product::SCENARIO_READ;
     if (($model = $search->findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 protected function buildFromInput(Product $product, $input)
 {
     $title = $input->get('title');
     // #TODO: Shouldn't really be optional
     $imageUrl = $input->has('image_url') ? $input->get('image_url') : null;
     $product->setTitle($title);
     $product->setImageUrl($imageUrl);
     EntityManager::persist($product);
     EntityManager::flush();
     return $product;
 }
Exemple #12
0
 public function show($cat, $prod = '')
 {
     !preg_match("|^[a-z0-9]+\$|", $cat) && exit;
     $prod && !preg_match("|^[a-z0-9]+\$|", $prod) && exit;
     $product = new Product();
     $view = new View();
     $cat && ($result = $product->showCatalog($cat, $prod)) ? $view->display($result, $cat) : (($result = $product->showProduct($prod)) ? $view->display($result, 'prod') : ($this->error = true));
     if ($this->error) {
         throw new Exception('Что то пошло не так... Скорее всего таблица пуста!');
     }
 }
 public function deleteProduct(Product $product)
 {
     event(new DeleteUnpublishedNotification($product->barcode));
     if ($product->countOrganizations == 1) {
         $product->delete();
     } else {
         $product->organizations()->detach($this->user->organization->id);
     }
     flash()->info('Διεγράφη', 'το συγκεκριμένο προϊόν διεγράφη με επιτυχία από τον Οργανισμό');
     return redirect()->route('Admin::Unpublished::index');
 }
 public function actionSearchProducts()
 {
     $modelForm = new Product();
     $results = null;
     if ($modelForm->load(Yii::$app->request->post())) {
         $results = $modelForm->giveAllProductsByName($modelForm->name);
         Yii::$app->session->setFlash('contactFormSubmitted');
         return $this->render('searchProducts', ['modelForm' => $modelForm, 'results' => $results]);
     } else {
         return $this->render('searchProducts', ['modelForm' => $modelForm, 'results' => $results]);
     }
 }
Exemple #15
0
 protected function fakeProduct()
 {
     $fakeProduct = new Product();
     $fakeProduct->serial_number = "P1284724";
     $fakeProduct->primary_name = "Fake Product";
     $fakeProduct->product_type_id = $this->fakeProductType()->product_type_id;
     $fakeProduct->currency_id = $this->fakeCurrency()->currency_id;
     $fakeProduct->client_id = $this->fakeClient()->client_id;
     $fakeProduct->supplier_id = $this->fakeSupplier()->supplier_id;
     $fakeProduct->save();
     return $fakeProduct;
 }
 public function actionProduct($id)
 {
     $modelProduct = new Product();
     foreach ($modelProduct->getProduct($id) as $product) {
         $idProduct = $product['id'];
         $nameProduct = $product['name'];
         $typeProduct = $product['type'];
         $priceProduct = $product['price'];
         $descriptionProduct = $product['description'];
         $imageProduct = $product['image'];
     }
     return $this->render('product', ['idProduct' => $idProduct, 'nameProduct' => $nameProduct, 'typeProduct' => $typeProduct, 'priceProduct' => $priceProduct, 'descriptionProduct' => $descriptionProduct, 'imageProduct' => $imageProduct]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $product = new Product();
     $product->name = $request->input('name');
     $product->price = $request->input('price');
     $product->description = $request->input('description');
     $product->save();
     for ($i = 0; $i < $request->input('stock'); $i++) {
         $item = new ProductItem();
         $item->code = date('YmdHis') . '.' . $i;
         $item = $product->item()->save($item);
     }
 }
 /**
  * Display Generator Page
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function show(Request $request)
 {
     /** @var $product Product */
     if (!($product = $this->product->whereCode($request->get('product_id'))->orWhere('id', $request->get('product_id'))->first())) {
         return response()->json(['error' => 'invalid_code']);
     }
     /**
      * Encode Image if necessary
      */
     if (filter_var($request->get('encode_image', false), FILTER_VALIDATE_BOOLEAN) === true) {
         $product->setAttribute('image', dispatch(new EncodeImageJob(substr($product->getAttribute('image'), 1))));
     }
     return response()->json($product->load('extras', 'profile'));
 }
 public function saveTags(Product $product, array $tags)
 {
     $results = [];
     foreach ($tags as $tag) {
         $tag = trim($tag);
         $find = Tag::where('name', $tag)->first();
         if (!$find) {
             $find = Tag::create(['name' => $tag]);
         }
         $results[] = $find;
     }
     $product_ids = collect($results)->pluck('id');
     $product->tags()->attach($product_ids->toArray());
     return $results;
 }
 public function run()
 {
     DB::table('products')->truncate();
     $faker = Faker\Factory::create();
     $lorem = new Faker\Provider\Lorem($faker);
     $random = new Faker\Provider\Base($faker);
     for ($i = 0; $i < 500; $i++) {
         $name = $lorem->word();
         $product = new Product();
         $product->slug = Str::slug($name);
         $product->name = ucfirst($name);
         $product->price = $random->randomNumber(2);
         $product->save();
     }
 }
 public function store(Request $request)
 {
     $input = $request->json()->all();
     unset($input['categories']);
     $product = new Product($input);
     $product->save();
     if (($categories = $request->json()->get('categories')) && !empty($categories)) {
         if (is_string($categories)) {
             $categories = explode(',', $categories);
         }
         $product->categories()->attach($categories);
     }
     $product->load('categories');
     return response()->created($product);
 }
 public function setUp()
 {
     parent::setUp();
     $this->resetEvents('App\\Models\\Product', 'App\\Models\\ProductStock', 'App\\Models\\ProductPhoto', 'App\\Models\\UploadFile');
     $this->shared('product', function () {
         $product = new Product(["product_name" => "iPhone 6", "product_desc" => "iPhone 6", "status" => "available", "options" => [["name" => "颜色", "options" => ["深空灰", "银色", "金色"]], ["name" => "容量", "options" => ["16GB", "64GB", "128GB"]]], "specifications" => [["attr_name" => "高度", "attr_group" => "重量和尺寸", "attr_value" => "138.1 毫米(5.44 英寸)"], ["attr_name" => "宽度", "attr_group" => "重量和尺寸", "attr_value" => "67.0 毫米 (2.64 英寸)"], ["attr_name" => "厚度", "attr_group" => "重量和尺寸", "attr_value" => "6.9 毫米 (0.27 英寸)"], ["attr_name" => "重量", "attr_group" => "重量和尺寸", "attr_value" => "129 克 (4.55 盎司)"]]]);
         $product->save();
         return $product;
     });
     $this->shared('stock', function () {
         return $this->product->stocks()->save(new ProductStock(["option" => ["深空灰", "16GB"], "sku" => uniqid(), "stocks" => 100, "price" => 5288]));
         $stock->save();
         return $stock;
     });
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $categories = Categories::where('parent_id', '>=', 0)->get();
     $baseUrl = 'http://7xkn9n.com1.z0.glb.clouddn.com/img/';
     $string = file_get_contents(__DIR__ . "/../data/products.json");
     $products = json_decode($string, true);
     $cate_ids = [];
     foreach ($categories as $category) {
         $cate_ids[] = $category->id;
     }
     foreach ($products as $productData) {
         try {
             $name = $productData['meta']['title'];
             $content = '';
             if (isset($productData['content'])) {
                 $content = str_replace('<h2 class="title">百科词条</h2>', '', $productData['content']);
             }
             $klass = $productData['meta']['class']['text'];
             $category = Categories::where('name', $klass)->get();
             $description = substr($content, 0, 100);
             $cid = $faker->randomElement($cate_ids);
             if ($category->count() == 1) {
                 $cid = $category[0]->id;
             }
             $pieces = preg_split("/\\//i", $productData['meta']['image']);
             $product = Product::create(['name' => $name, 'slug' => $name, 'description' => $description, 'keywords' => $klass, 'cover' => $baseUrl . $pieces[count($pieces) - 1], 'category_id' => $cid, 'user_id' => 1]);
             $detailTopic = Topic::create(['title' => $name, 'slug' => $name, 'product_id' => $product->id, 'user_id' => 1, 'keywords' => $name, 'description' => $description, 'content' => $content, 'is_product_detail_topic' => true]);
             $product->detail_topic_id = $detailTopic->id;
             $product->save();
         } catch (Exception $e) {
             throw $e;
         }
     }
 }
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $user = User::find($this->userId)->first();
     $product = Product::find($this->productId);
     //        dd($user, $product);
     $user->products()->save($product, ['mod' => '1']);
 }
Exemple #25
0
 public function getPrice($id)
 {
     foreach (Product::find('price')->where(['id' => $id])->all() as $product) {
         $productPrice = $product['price'];
     }
     return $productPrice;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     foreach (range(1, 50) as $index) {
         Product::create(['title' => $faker->sentence, 'description' => $faker->paragraph(4), 'primary_image_path' => 'main_image_' . rand(1, 4) . '.jpeg', 'delivery' => $faker->boolean(50), 'pickup' => $faker->boolean(50), 'free' => $faker->boolean(50), 'price' => $faker->numberBetween(0, 100), 'user_id' => rand(1, 29), 'university_id' => rand(2, 149)]);
     }
 }
Exemple #27
0
 public function actionAjaxAdd()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $request = Yii::$app->request;
     $id = $request->get('id');
     $color = $request->get('color');
     $size = $request->get('size');
     $number = $request->get('num');
     $model = Product::findOne($id);
     if (!Yii::$app->session->isActive) {
         Yii::$app->session->open();
     }
     $cart = new Cart();
     $cart->session_id = Yii::$app->session->id;
     $cart->user_id = Yii::$app->user->isGuest ? 0 : Yii::$app->user->id;
     $cart->product_id = $id;
     $cart->name = $model->name;
     $cart->color = $color;
     $cart->size = $size;
     $cart->number = $number;
     $cart->price = $model->price;
     if ($cart->save()) {
         return ['status' => 1, 'productId' => $id, 'size' => $size, 'color' => $color];
     } else {
         return ['status' => -2, 'productId' => $id, 'size' => $size, 'color' => $color];
     }
 }
Exemple #28
0
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function detail($slug)
 {
     $explodeSlug = explode('-', $slug);
     $product_id = explode('.', end($explodeSlug))[0];
     if (!$product_id) {
         return View::make('errors/503');
     }
     $model = new Product();
     $product = $model->getAll()->where('id', $product_id)->first();
     if (empty($product)) {
         return View::make('errors/503');
     }
     $relatedProduct = $model->getAll()->where('category_id', $product->category_id)->get();
     $data = ["title" => $product ? $product->name : '', 'product' => $product, 'keywords' => $product ? $product->keywords : '', "description" => $product ? $product->description : '', 'releated_product' => $relatedProduct];
     return View::make('user/detail_product', $data);
 }
 public function archive($publicId)
 {
     $product = Product::scope($publicId)->firstOrFail();
     $product->delete();
     Session::flash('message', trans('texts.archived_product'));
     return Redirect::to('company/products');
 }
Exemple #30
0
 /**
  * Lists all Images models.
  * @return mixed
  */
 public function actionIndex($itemId)
 {
     if (!Product::find()->where(['item_id' => $itemId])->exists()) {
         throw new NotFoundHttpException();
     }
     $form = new MultipleUploadForm();
     $searchModel = new ImagesSearch();
     $searchModel->item_id = $itemId;
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if (Yii::$app->request->isPost) {
         $form->files = UploadedFile::getInstances($form, 'files');
         if ($form->files && $form->validate()) {
             foreach ($form->files as $file) {
                 $images = new Images();
                 $images->item_id = $itemId;
                 if ($images->save()) {
                     // writes file name to images table
                     $images->big_image = $images->getUrl();
                 }
                 if ($images->save()) {
                     // saves file to folder
                     $file->saveAs($images->getPath());
                 }
             }
         }
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'uploadForm' => $form]);
 }