/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $product = Product::findOrFail($id);
     $category = Category::findOrFail($product->category_id);
     $product_sizes = ProductSize::where('product_id', '=', $id)->get();
     return view('product.show', compact('product', 'category', 'product_sizes'));
 }
Beispiel #2
0
 public function getSizeColors($id)
 {
     $size = ProductSize::find($id);
     $size['discount'] = $size->promoPrice(0);
     $size->colors;
     return Response::json(array('data' => $size));
 }
Beispiel #3
0
 public static function manage($data, $id = null)
 {
     if ($id) {
         $data['id'] = $id;
     }
     $rules = $id ? self::rules(true) : self::rules();
     $messages = $id ? self::messages(true) : self::messages();
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->fails()) {
         return ['error' => ['type' => 'validation', 'messages' => $validator]];
     }
     try {
         $size = $id ? ProductSize::find($id) : new ProductSize();
         $size->size = $data['size'];
         $size->price = $data['price'];
         $size->product_id = $data['product_id'];
         $size->price = $data['price'];
         $size->promo_type = $data['promo_type'];
         $size->promo = $data['promo'];
         $promo = $data['promo'] + 0;
         if ($promo) {
             $product = Product::findOrFail($data['product_id']);
             $product->setOnPromo();
             var_dump($product);
         }
         $size->save();
     } catch (\Exception $ex) {
         return ['error' => ['type' => 'saving', 'messages' => $ex->getMessage(), 'trace' => $ex->getTraceAsString()]];
     }
     return ['error' => ['type' => 'no'], 'success' => 'You successfully added size'];
 }
Beispiel #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $product = Product::find($data['product_id']);
     if (!$product) {
         return redirect()->back();
     }
     //exc.: no exist product
     if (!$product->price && !array_key_exists('size_id', $data)) {
         return redirect()->back();
     }
     //exc. no size selected
     if ($product->price && count($product->colors) && !array_key_exists('color_id', $data)) {
         return redirect()->back();
     }
     //exc. no color selected
     $options = ['discount' => 0, 'product' => $product];
     if (count($product->colors)) {
         $color = ProductColor::find($data['color_id']);
         if (!$color) {
             return redirect()->back();
         }
         //exc. no exist color echo 'error no exist color'; //
         $options['color'] = $color;
     }
     if (count($product->sizes)) {
         $size = ProductSize::find($data['size_id']);
         if (!$size) {
             return redirect()->back();
         }
         //exc. no exist size echo 'error no exist size'; //
         $options['size'] = $size;
         if (count($size->colors)) {
             if (!array_key_exists('color_id', $data)) {
                 return redirect()->back();
             }
             //exc. no color selected
             $color = ProductColor::find($data['color_id']);
             if (!$color) {
                 return redirect()->back();
             }
             //exc. no exist color echo 'error no exist color in size'; //
             $options['color'] = $color;
         }
     }
     if (isset($size)) {
         $options['size'] = $size;
     }
     if (isset($color)) {
         $options['color'] = $color;
     }
     if ($product->promoPrice() + 0) {
         $options['discount'] = $product->promo;
         $options['discount_type'] = $product->promo_type;
     }
     $price = $product->currentPrice(0);
     Cart::instance('shopping')->add($product->id, $product->name, array_key_exists('qty', $data) ? $data['qty'] : 1, $price, $options);
     return redirect()->back();
 }
 private function getSizessAsArray()
 {
     $sizes = ProductSize::all();
     $arr = ['no size selected'];
     foreach ($sizes as $size) {
         $arr[$size->id] = $size->size . ' of product ' . $size->product->name;
     }
     return $arr;
 }
Beispiel #6
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $extra = Extra::findOrFail($id);
     $product_size = ProductSize::findOrFail($extra->product_size_id);
     $product = Product::findOrFail($product_size->product_id);
     $category = Category::findOrFail($product->category_id);
     $product_sizes = ProductSize::where('product_id', '=', $product->id)->lists('size', 'id');
     return view('extra.edit', compact('product_size', 'product', 'category', 'product_sizes', 'extra'));
 }
 public function edit($id_product, $id)
 {
     $variant = ProductVariant::find($id);
     $prod = Product::find($id_product);
     $size = ProductSize::where('id_variants', $id)->get();
     $check = $variant->publish;
     if ($check == 0) {
         $checks = '';
     } else {
         $checks = 'checked';
     }
     $categories = Category::all();
     return view('dropmin/variant/edit')->with('variant', $variant)->with('check', $checks)->with('size', $size)->with('prod', $prod);
 }
Beispiel #8
0
 public function addCart(Request $request)
 {
     $keys = 'psid,count,quickly';
     $data = $this->tipsValidate($request, 'order.cart', $keys);
     $psid = $data['psid'];
     DB::beginTransaction();
     $ps = ProductSize::where('id', $psid)->lockForUpdate()->first();
     //库存不足
     if ($ps->count < $data['count']) {
         DB::rollback();
         return $this->failure('order.failure_cart_stock_less');
     }
     //快速购买模式
     if ($data['quickly']) {
         DB::rollback();
         return $this->success('order.success_quickly', url('m/to/order') . '?cart[]=' . $psid . '&buy_cnt[' . $psid . ']=' . $data['count']);
     } else {
         //加入购物车
         Cart::firstOrCreate(['psid' => $psid, 'uid' => $this->user->getKey()])->increment('count', $data['count']);
         DB::commit();
         return $this->success('order.success_cart', FALSE);
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $validation = Validator::make($request->all(), ['name' => 'required|max:15', 'stock' => 'required|numeric']);
     $cur_clean = preg_replace('/\\./', '', $request->input('price'));
     $kg = preg_replace('/\\,/', '.', $request->input('weight'));
     $gram = $kg * 1000;
     // Check if it fails //
     if ($validation->fails()) {
         return redirect()->back()->withInput()->with('errors', $validation->errors());
     }
     if ($request->input('publish') == "") {
         $publish = 0;
     } else {
         $publish = 1;
     }
     $author = Auth::user()->id;
     $size = ProductSize::find($id);
     $seo = $request->input('name');
     $seotitle = SeoHelper::seotitle($seo);
     // save size data into database //
     $size->name = $request->input('name');
     $size->add_price = $cur_clean;
     $size->add_weight = $gram;
     $size->stock = $request->input('stock');
     $size->publish = $publish;
     $size->save();
     Alert::success('Success Update ' . $request->input('name') . '!')->persistent("Close");
     return redirect('dropmin/product/variant/edit/' . $request->input('id_product') . '/' . $request->input('id_variant'))->with('message', 'You just updated an size!');
 }
 private function validProductUnique($pid, $attr_id, $clothes_type, $main_id = '')
 {
     $productSize = new ProductSize();
     $builder = $productSize->newQuery()->where('pid', '=', $pid)->where('attr_id', '=', $attr_id)->where('size_type', '=', $clothes_type);
     if (!empty($main_id)) {
         $builder->where('id', '!=', $main_id);
     }
     return $builder->count() ? false : true;
 }
Beispiel #11
0
 public function canceled($transaction = TRUE)
 {
     $transaction && DB::beginTransaction();
     $order = static::where($this->getKeyName(), $this->getKey())->lockForUpdate()->first();
     if ($order->status != static::INIT && $order->status != static::REFUSED) {
         $transaction && DB::rollback();
         return false;
     }
     //归还库存
     $details = $order->details->keyBy('psid')->toArray();
     //dd($details);
     $productSize = ProductSize::whereIn('id', array_keys($details))->lockForUpdate()->get();
     foreach ($productSize as $id => $ps) {
         $ps->increment('count', $details[$ps->getKey()]['count']);
     }
     if (intval($order->bonus_id) > 0) {
         $bonus = ActivityBonus::where('id', $order->bonus_id)->lockForUpdate()->first();
         $bonus->status = 0;
         //恢复红包
         $bonus->save();
     }
     $order->status = static::CANCELED;
     $order->save();
     $transaction && DB::commit();
     return true;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     ProductSize::destroy($id);
     return redirect()->back();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     if (!Auth::check()) {
         return redirect()->to('panel/login');
     }
     $size = ProductSize::find($id);
     $existChecker = self::isSizeExist($size, $id);
     if ($existChecker['error']) {
         return view('panel.errors.404', $existChecker['data']);
     }
     $colors = $size->colors();
     foreach ($colors as $color) {
         $color->delete();
     }
     $size->delete();
     return redirect()->back();
 }