public function addmodels($id) { if ($this->isAdminRequest()) { //$id = $_POST['id']; // print_r($_POST); $rules = array('models' => 'required'); $validator = Validator::make(Input::all(), $rules); // process the login if ($validator->fails()) { return Redirect::to('admin/products/' . $id . '/models')->withErrors($validator)->with('productcategory', ProductCategory::find($id))->with('models', Products::where('product_category_id', '=', $id)->get())->withInput(Input::all()); } else { $models = Input::get('models'); $models_arr = explode(",", $models); foreach ($models_arr as $model) { $product_model = new Products(); $product_model->model_id = $model; $product_model->product_category_id = $id; $product_model->save(); } // // redirect Session::flash('message', 'Successfully added models.'); return Redirect::to('admin/products/' . $id . '/models'); } //$import = importmodels('boo'); // // $productcategory = ProductCategory::find($id); // $models = Products::where('product_category_id','=',$id)->get(); // return View::make('admin.products.models') // ->with('productcategory',$productcategory) // ->with('models',$models); // } } }
/** * Get all categories of product. * @return an array with contains information of product categories */ public function getProductCategories() { $categories = array(); $resultSet = ProductCategory::find(); foreach ($resultSet as $rowSet) { array_push($categories, array('productCategoryId' => $rowSet->getProductCategoryId(), 'productCategorySlug' => $rowSet->getProductCategorySlug(), 'productCategoryName' => (array) json_decode($rowSet->getProductCategoryName()))); } return $categories; }
/** * testResetDepths method * * Tests TreePlusBehavior::resetDepths(). * * @return void * @access public */ public function testResetDepths() { $this->ProductCategory->resetDepths(); $result = $this->ProductCategory->find('list', array('fields' => array('id', 'depth'), 'order' => array('id' => 'ASC'), 'recursive' => false)); $this->assertEqual(array_values($result), array(0, 1, 1, 0, 1, 1)); }
public function setdefault($id, $fileid) { // $default = ProductCategory::find($id); if ($default->default_image == $fileid) { $default->default_image = ''; } else { $default->default_image = $fileid; } $default->save(); Session::flash('message', 'Successfully set default status for ' . $default->title); return Redirect::to('admin/products/' . $id . '/files'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // if ($this->isAdminRequest()) { // delete $product = ProductCategory::find($id); $product->delete(); $product->products()->delete(); $product->children()->delete(); // redirect Session::flash('message', 'Successfully deleted the Product!'); return Redirect::to('admin/products'); } }