public function showProduct($brandname, $catname)
 {
     $brandname = urlunslug($brandname);
     $catname = urlunslug($catname);
     $brand = Brand::where('name', '=', $brandname)->first();
     $productcat = Productcategory::where('brand_id', '=', $brand->id)->where('name', '=', $catname)->select('id', 'type')->first();
     $productsObj = Productcategory::find($productcat->id)->products();
     $mode = Input::get('mode', 'retail');
     $products = $productsObj->select('id', 'productcat_id', 'brand_id', 'barcodeid', 'name', 'quantity', 'almost_finished', 'costprice', 'published', $mode . '_price as price', $mode . '_discount as discount', $mode . '_discountedprice as discountedprice', $mode . '_totalprice as totalprice');
     if ($products == null) {
         return $this->callErrorPage(404);
     }
     $products = $products->orderBy('id', 'desc')->get();
     $data['products'] = $products->toArray();
     $data['sum_total'] = $this->_sumTotalprice($data['products']);
     $data['sum_cost'] = $this->_sumTotalcost($data['products']);
     $data['profit_margin'] = $data['sum_total'] - $data['sum_cost'];
     $data['addProductLink'] = array('brand_id' => $brand->id, 'productcat_id' => $productcat->id);
     $data['mode'] = $mode;
     $data['brand'] = $brand;
     $data['cat'] = $catname;
     Larasset::start('footer')->js('dataTables-min', 'dataTables-bootstrap', 'bootstrap_editable');
     Larasset::start('header')->css('bootstrap_editable');
     if (!Request::ajax()) {
         $data['modes'] = Mode::listModes();
         $this->layout->title = $brand['name'] . ' - ' . $catname;
         $blade = $productcat->type === 'service' ? 'showservice' : 'tab_showproduct';
         $this->layout->content = View::make('admin.liststock.' . $blade, $data);
     } else {
         return View::make('admin.liststock.showproduct', $data);
     }
 }
 public function showCategory($brandname)
 {
     $brandname = urlunslug($brandname);
     $brand = Brand::where('name', '=', $brandname)->first();
     //This will trigger 404 Error page if The brand requested does not exit
     if ($brand == null) {
         return $this->callErrorPage(404);
     }
     $ids = Productcategory::where('brand_id', '=', $brand->id)->lists('id');
     $this->_monitorChildrenStatus($ids);
     $category = Brand::find($brand->id)->categories->toArray();
     $data['category'] = $category;
     $data['brand'] = $brand;
     $this->layout->title = $brand->name . " - Categories";
     $this->layout->content = View::make('admin.liststock.showcategory', $data);
     Larasset::start('header')->css('bootstrap_editable');
     Larasset::start('footer')->js('bootstrap_editable');
 }
 public function delete_brand()
 {
     $id = Request::segment(4);
     $brand = Brand::find($id);
     Brand::where('id', $id)->delete();
     $message = "Successfully deleted the brand";
     $type = "success";
     return Redirect::to('/admin/brands')->with('type', $type)->with('message', $message);
 }
Example #4
0
 public function validarNoRepit($text)
 {
     $brands = Brand::where('nombre', '=', $text)->orWhere('shortname', '=', $text)->first();
     return $brands;
 }
Example #5
0
 public function post_product_add()
 {
     $data = Input::all();
     $sessionArr = array("name" => "", "price" => "", "attrs" => array());
     $attributes = array();
     //check that product model is exist!
     $productCheck = Product::where('model', '=', $data['p_model'])->first();
     if (empty($productCheck)) {
         //first we fetch the brand and get the ID
         if (empty($data['p_brand_other'])) {
             $brand = $data['p_brand'];
             //e.g $brand = 3;
         } else {
             //here we get brand ID by brand_other's input if the brand_other is filled
             $brandCheck = Brand::where("name", '=', $data['p_brand_other'])->first();
             if (empty($brandCheck)) {
                 $brand = DB::table('brands')->insert_get_id(array('name' => $data['p_brand_other'], 'alias' => Str::slug($data['p_brand_other'])));
             } else {
                 $brand = $brandCheck->id;
             }
         }
         $brandName = Brand::where("id", '=', $brand)->only('name');
         $brandalias = Brand::where("id", '=', $brand)->only('alias');
         $imageIDs = array();
         //pic
         $images = $data["userfile"];
         $mainImg = $data["active"];
         $CategoryfurImages = Category::with('getDescriptions')->where("id", "=", $data['p_category'])->first();
         for ($i = 0; $i < sizeof($images['name']); $i++) {
             $img = array('name' => $images['name'][$i], 'type' => $images["type"][$i], "tmp_name" => $images["tmp_name"][$i], "error" => $images["error"][$i], "size" => $images["size"][$i]);
             try {
                 array_push($imageIDs, $this->imageSizer($img, $CategoryfurImages));
             } catch (Exception $e) {
                 Session::flash('status', 'Resim eklemede hata oluştu Ürünü tekrar ekleyiniz!\\r\\n' . $e->getMessage());
                 return Redirect::to('admin/product/new');
             }
         }
         //now insert the product, first things first.
         $product = DB::table('products')->insert_get_id(array('brand_id' => $brand, 'model' => $data['p_model'], 'price' => ceil($data['p_price'] / 1.18), 'quantity' => $data['p_qty'], 'tax_class_id' => $data['p_tax'], 'barcode' => $data['p_barcode'], 'alias' => trim(Str::slug($brandalias . ' ' . $data['p_model'])), 'created_at' => DB::raw('NOW()'), 'updated_at' => DB::raw('NOW()')));
         //inserting pictures
         for ($i = 0; $i < count($imageIDs); $i++) {
             $imagesSql = DB::table('product_images')->insert(array('product_id' => $product, 'main' => $mainImg[$i] == 1 ? 1 : 0, 'unique_id' => $imageIDs[$i]));
         }
         $productDescription = DB::table('product_descriptions')->insert_get_id(array('product_id' => $product, 'name' => $brandName . ' ' . $data['p_model'], 'description' => $data['p_description'], 'variant' => $data['p_variant'], 'tag' => $data['p_tag']));
         $sessionArr["name"] = $brandName . ' ' . $data['p_model'];
         $sessionArr["price"] = ceil($data['p_price'] / 1.18);
         //we insert the product now we set the category where the product belong
         $cagetory = DB::table('map_product_category')->insert_get_id(array('product_id' => $product, 'category_id' => $data['p_category']));
         $attr_other = $data['attr_other'];
         $attrs = array();
         $check = true;
         foreach ($data['attr'] as $k => $v) {
             if (!empty($data['attr_other'][$k])) {
                 $CheckTheAttr = Attribute::where_attribute_group_id_and_value($k, $attr_other[$k])->first();
                 if ($CheckTheAttr == null) {
                     $attrotherID = DB::table('attributes')->insert_get_id(array('attribute_group_id' => $k, 'value' => $data['attr_other'][$k]));
                     array_push($attributes, "Ekstra eklenen ve girilen ürün özelliği : " . $attr_other[$k]);
                     $attrs[$k] = $attrotherID;
                 } else {
                     $attrs[$k] = $v;
                 }
             } else {
                 array_push($attributes, "Girilen ürün özelliği : " . $v);
                 $attrs[$k] = $v;
             }
         }
         array_push($sessionArr["attrs"], $attributes);
         $attrsOrdered = array();
         foreach ($attrs as $k => $v) {
             $attrsOrdered[] = array('product_id' => $product, 'attribute_id' => $v);
         }
         $attrs = DB::table('map_product_attribute')->insert($attrsOrdered);
     } else {
         Session::flash('status', 'Bu ürün daha önce sisteme eklenmiş!');
         return Redirect::to('admin/product/new');
     }
     return Redirect::to('admin/product/new')->with("result", $sessionArr);
 }
 public function deleteBrands()
 {
     $ids = explode(',', Input::get('javascriptArrayString'));
     //$ids = (!is_array($ids)) ? array($ids) : $ids;
     foreach ($ids as $id) {
         //Lets fetch the Brand Image name
         $logo = Brand::where('id', $id)->pluck('brandlogo');
         //Lets check if the file exists
         $file = Config::get('software.dir_upload_logo');
         if ($logo !== '' and file_exists($file . $logo)) {
             unlink($file . $logo);
         }
         //tt($logo);
     }
     Brand::destroy($ids);
     $data['status'] = 'success';
     $data['message'] = 'Deleted successfully';
     return Response::json($data);
 }