public function anyManageShop() { $product_types = ProductTypes::where('hidden', 0)->orderBy('name', 'ASC')->get(); $success_msg = []; $error_msg = []; $rules = ['product_name' => 'required', 'product_category' => 'required', 'short_description' => 'required', 'product_description' => 'required', 'price' => 'required', 'quantity' => 'required|numeric']; $validator = Validator::make(Input::all(), $rules); if (Request::method() == 'POST') { if (!$validator->fails()) { $category_select = Input::get('product_category'); $category = ProductTypes::find($category_select); if ($category) { /** @var Products $product */ $product = new Products(); $product->uid = Uuid::generate()->string; $product->name = Input::get('product_name'); $product->short_description = Input::get('short_description'); $product->description = Input::get('product_description'); $product->price_in_cents = Input::get('price') * 100; $product->quantity = Input::get('quantity'); $product->product_type_id = $category->id; $product->allow_review = 1; $product->save(); if ($product->save()) { if (Input::file('main_product_image')) { $filename = Input::file('main_product_image')->getClientOriginalName(); $destination = storage_path() . '/app/upload/'; $file_path = Input::file('main_product_image')->move($destination, $filename); // $diskLocal = Storage::disk('local'); $product_image = new ProductImages(); $product_image->url = $filename; $product_image->product_id = $product->id; $product_image->name = $filename; $product_image->is_primary = 1; $product_image->save(); } } $success_msg[] = 'Product Added!'; } else { $error_msg[] = 'Whoops! Sorry, product category not found'; } } else { return Redirect::back()->withErrors($validator->messages())->withInput(Input::all()); } } return View::make('shop.manage_store', ['product_types' => $product_types, 'success_msg' => $success_msg, 'error_msg' => $error_msg]); }
/** * Initialize the products form */ public function initialize($entity = null, $options = array()) { if (!isset($options['edit'])) { $element = new Text("id"); $this->add($element->setLabel("Id")); } else { $this->add(new Hidden("id")); } $name = new Text("name"); $name->setLabel("Name"); $name->setFilters(array('striptags', 'string')); $name->addValidators(array(new PresenceOf(array('message' => 'Name is required')))); $this->add($name); $type = new Select('product_types_id', ProductTypes::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => '')); $type->setLabel('Type'); $this->add($type); $price = new Text("price"); $price->setLabel("Price"); $price->setFilters(array('float')); $price->addValidators(array(new PresenceOf(array('message' => 'Price is required')), new Numericality(array('message' => 'Price is required')))); $this->add($price); }
/** * Search producttype based on current criteria */ public function searchAction() { $numberPage = 1; if ($this->request->isPost()) { $query = Criteria::fromInput($this->di, "App\\Models\\ProductTypes", $this->request->getPost()); $this->persistent->searchParams = $query->getParams(); } else { $numberPage = $this->request->getQuery("page", "int"); } $parameters = array(); if ($this->persistent->searchParams) { $parameters = $this->persistent->searchParams; } $productTypes = ProductTypes::find($parameters); if (count($productTypes) == 0) { $this->flash->notice("The search did not find any product types"); return $this->forward("producttypes/index"); } $paginator = new Paginator(array("data" => $productTypes, "limit" => 10, "page" => $numberPage)); $this->view->page = $paginator->getPaginate(); $this->view->productTypes = $productTypes; }