コード例 #1
0
ファイル: SizeController.php プロジェクト: ikliko/Maxverf
 public function getSizeColors($id)
 {
     $size = ProductSize::find($id);
     $size['discount'] = $size->promoPrice(0);
     $size->colors;
     return Response::json(array('data' => $size));
 }
コード例 #2
0
ファイル: ProductSize.php プロジェクト: ikliko/Maxverf
 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'];
 }
コード例 #3
0
ファイル: CartController.php プロジェクト: ikliko/Maxverf
 /**
  * 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();
 }
コード例 #4
0
 /**
  * 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!');
 }
コード例 #5
0
 public function update(Request $request, $id)
 {
     $productSize = ProductSize::find($id);
     if (empty($productSize)) {
         return $this->failure_noexists();
     }
     $keys = 'attr_id,size_type,price,count';
     $data = $this->autoValidate($request, 'product-stock.store', $keys, $productSize);
     if ($this->validProductUnique($this->_pid, $request->get('attr_id'), $request->get('size_type'), $id)) {
         $productSize->update($data);
         return $this->success();
     } else {
         return $this->failure_validate(new MessageBag(array('size_type' => '同一件商品同一属性同一大小的条目已存在')));
     }
 }
コード例 #6
0
 /**
  * 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();
 }