public function getEdit($sid) { // Find the module using the user id $module = Module::find($sid); // No such id if ($module == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('editError', "The module cannot be found because it does not exist or may have been deleted."); return redirect('/admin/modules')->withErrors($errors); } $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get(); $tagString = ""; foreach ($module->tags as $tag) { if (!empty($tagString)) { $tagString .= ","; } $tagString .= $tag->name; } $translated = array(); foreach ($module->translations as $translation) { $translated[$translation->lang] = json_decode($translation->content); } $pricelists = array(); foreach (Membership::orderBy('rank')->get() as $membership) { $pricelist = Pricelist::where('module_id', $module->id)->where('membership_id', $membership->id)->first(); if ($pricelist == null) { $pricelists[] = array('id' => $membership->id, 'name' => $membership->name, 'price' => '', 'active' => false); } else { $pricelists[] = array('id' => $membership->id, 'name' => $membership->name, 'price' => $pricelist->price, 'active' => $pricelist->active); } } return \View::make('redminportal::modules/edit')->with('module', $module)->with('translated', $translated)->with('categories', $categories)->with('tagString', $tagString)->with('pricelists', $pricelists)->with('imagine', new RImage()); }
public function getEdit($sid) { // Find the product using the user id $product = Product::find($sid); // No such id if ($product == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('errorNoSuchProduct', Lang::get('redminportal::messages.error_no_such_product')); return redirect($this->pageRoute)->withErrors($errors); } $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get(); $tagString = ""; foreach ($product->tags as $tag) { if (!empty($tagString)) { $tagString .= ","; } $tagString .= $tag->name; } $translated = array(); foreach ($product->translations as $translation) { $translated[$translation->lang] = json_decode($translation->content); } $data = array('product' => $product, 'translated' => $translated, 'categories' => $categories, 'tagString' => $tagString, 'imagine' => new RImage(), 'weight_units' => $this->weight_units, 'volume_units' => $this->volume_units); return view('redminportal::products/edit', $data); }
public function testCreateSubCategory() { $this->createNew(); $model = Category::find(1); $new_model = new Category(); $new_model->name = 'This is sub category'; $new_model->short_description = 'This is the body 1'; $new_model->active = true; $model->categories()->save($new_model); $new_model_2 = new Category(); $new_model_2->name = 'This is another sub category'; $new_model_2->short_description = 'This is the body 2'; $new_model_2->active = true; $model->categories()->save($new_model_2); $this->assertTrue($model->categories->count() == 2); $this->assertTrue(Category::where('category_id', $model->id)->count() == 2); foreach ($model->categories as $cat) { if ($cat->name == 'This is sub category') { $this->assertTrue($cat->short_description == 'This is the body 1'); } elseif ($cat->name == 'This is another sub category') { $this->assertTrue($cat->short_description == 'This is the body 2'); } else { $this->assertTrue(false); } } // Delete main category will delete all sub categories $model->delete(); $this->assertTrue(Category::where('category_id', $model->id)->count() == 0); }
public function getEdit($sid) { // Find the post using the user id $post = Post::find($sid); if ($post == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('editError', "The post cannot be found because it does not exist or may have been deleted."); return redirect('admin/posts')->withErrors($errors); } $translated = array(); foreach ($post->translations as $translation) { $translated[$translation->lang] = json_decode($translation->content); } $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get(); return view('redminportal::posts/edit')->with('post', $post)->with('translated', $translated)->with('imagine', new RImage())->with('categories', $categories); }
public function getEdit($sid) { $bundle = Bundle::find($sid); if ($bundle == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('editError', "The bundle cannot be found because it does not exist or may have been deleted."); return redirect('/admin/bundles')->withErrors($errors); } $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get(); $products = Product::where('active', true)->lists('name', 'id'); $membermodules = array(); $pricelists = Pricelist::join('modules', 'modules.id', '=', 'pricelists.module_id')->join('memberships', 'memberships.id', '=', 'pricelists.membership_id')->where('pricelists.active', true)->orderBy('modules.name')->orderBy('memberships.rank', 'desc')->select('pricelists.*')->get(); foreach ($pricelists as $pricelist) { $membermodules[$pricelist->id] = $pricelist->module->name . " (" . $pricelist->membership->name . ")"; } $product_id = array(); foreach ($bundle->products as $product) { $product_id[$product->id] = $product->id; } $pricelist_id = array(); foreach ($bundle->pricelists as $pricelist) { $pricelist_id[$pricelist->id] = $pricelist->id; } $tagString = ""; foreach ($bundle->tags as $tag) { if (!empty($tagString)) { $tagString .= ","; } $tagString .= $tag->name; } $translated = array(); foreach ($bundle->translations as $translation) { $translated[$translation->lang] = json_decode($translation->content); } $data = array('categories' => $categories, 'products' => $products, 'membermodules' => $membermodules, 'bundle' => $bundle, 'product_id' => $product_id, 'pricelist_id' => $pricelist_id, 'translated' => $translated, 'categories' => $categories, 'tagString' => $tagString, 'imagine' => new RImage()); return view('redminportal::bundles/edit', $data); }
public function getEdit($sid) { // Find the product using the user id $product = Product::find($sid); // No such id if ($product == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('editError', "The product cannot be found because it does not exist or may have been deleted."); return redirect('/admin/products')->withErrors($errors); } $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get(); $tagString = ""; foreach ($product->tags as $tag) { if (!empty($tagString)) { $tagString .= ","; } $tagString .= $tag->name; } $translated = array(); foreach ($product->translations as $translation) { $translated[$translation->lang] = json_decode($translation->content); } return view('redminportal::products/edit')->with('product', $product)->with('translated', $translated)->with('categories', $categories)->with('tagString', $tagString)->with('imagine', new RImage()); }
public function getEdit($sid) { // Find the page using the user id $page = Page::find($sid); if ($page == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('editError', "The page cannot be found because it does not exist or may have been deleted."); return redirect('admin/pages')->withErrors($errors); } $translated = array(); foreach ($page->translations as $translation) { $translated[$translation->lang] = json_decode($translation->content); } $categories = Category::where('active', true)->where('category_id', 0)->orWhere('category_id', null)->orderBy('name')->get(); $tagString = ""; foreach ($page->tags as $tag) { if (!empty($tagString)) { $tagString .= ","; } $tagString .= $tag->name; } $data = ['page' => $page, 'translated' => $translated, 'imagine' => new RImage(), 'categories' => $categories, 'tagString' => $tagString]; return view('redminportal::pages/edit', $data); }
public function getDelete($sid) { // Find the category using the user id $category = Category::find($sid); if ($category == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The category cannot be found because it does not exist or may have been deleted."); return redirect('/admin/categories')->withErrors($errors); } // Find if there's any child $children = Category::where('category_id', $sid)->count(); if ($children > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The category '" . $category->name . "' cannot be deleted because it has " . $children . " children categories."); return redirect('/admin/categories')->withErrors($errors); } // Check in use by media $medias = Media::where('category_id', $sid)->get(); if (count($medias) > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The category '" . $category->name . "' cannot be deleted because it is in used."); return redirect('/admin/categories')->withErrors($errors); } // Delete the category $category->delete(); return redirect('admin/categories'); }
public function postStore() { $sid = \Input::get('id'); if (isset($sid)) { $url = 'admin/coupons/edit/' . $sid; } else { $url = 'admin/coupons/create'; } $rules = array('code' => 'required', 'amount' => 'required', 'start_date' => 'required', 'end_date' => 'required', 'amount' => 'numeric', 'min_spent' => 'numeric', 'max_spent' => 'numeric'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->fails()) { return redirect($url)->withErrors($validation)->withInput(); } // If id is set, check that it exists if (isset($sid)) { $coupon = Coupon::find($sid); if ($coupon == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('couponError', "The coupon does not exist or may have been deleted."); return redirect('admin/coupons')->withErrors($errors); } } $code = \Input::get('code'); $description = \Input::get('description'); $amount = \Input::get('amount'); $is_percent = \Input::get('is_percent') == '' ? false : true; $start_date = \DateTime::createFromFormat('d/m/Y h:i A', \Input::get('start_date')); $end_date = \DateTime::createFromFormat('d/m/Y h:i A', \Input::get('end_date')); $max_spent = \Input::get('max_spent'); $min_spent = \Input::get('min_spent'); $limit_per_coupon = \Input::get('usage_limit_per_coupon'); $limit_per_user = \Input::get('usage_limit_per_user'); $multiple_coupons = \Input::get('multiple_coupons') == '' ? false : true; $exclude_sale_item = \Input::get('exclude_sale_item') == '' ? false : true; $automatically_apply = \Input::get('automatically_apply') == '' ? false : true; // Check that end date is after start date if ($end_date <= $start_date) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('dateRangeError', "Please enter an End date later than Start date."); return redirect($url)->withErrors($errors)->withInput(); } // Check if max spent is less than min spent, only if both not null if ($max_spent and $min_spent) { if ((double) $max_spent < (double) $min_spent) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('spentRangeError', "Max spent cannot be less than Min spent."); return redirect($url)->withErrors($errors)->withInput(); } } $apply_to_models = array(); $categories = \Input::get('category_id'); if (count($categories) > 0) { foreach ($categories as $item) { $model = Category::find($item); if ($model != null) { $apply_to_models[] = $model; } } } $products = \Input::get('product_id'); if (count($products) > 0) { foreach ($products as $item) { $model = Product::find($item); if ($model != null) { $apply_to_models[] = $model; } } } $pricelists = \Input::get('pricelist_id'); if (count($pricelists) > 0) { foreach ($pricelists as $item) { $model = Pricelist::find($item); if ($model != null) { $apply_to_models[] = $model; } } } $bundles = \Input::get('bundle_id'); if (count($bundles) > 0) { foreach ($bundles as $item) { $model = Bundle::find($item); if ($model != null) { $apply_to_models[] = $model; } } } // In the worst scenario, all select items have been deleted if (count($apply_to_models) == 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('applyToError', "You have not selected any Category, Product or Membership/Module under Restricted To."); return redirect($url)->withErrors($errors)->withInput(); } $newCoupon = isset($sid) ? $coupon : new Coupon(); $newCoupon->code = $code; $newCoupon->description = $description; $newCoupon->amount = $amount; $newCoupon->is_percent = $is_percent; $newCoupon->start_date = $start_date; $newCoupon->end_date = $end_date; $newCoupon->max_spent = $max_spent == 0 ? null : $max_spent; $newCoupon->min_spent = $min_spent == 0 ? null : $min_spent; $newCoupon->usage_limit_per_coupon = $limit_per_coupon == 0 ? null : $limit_per_coupon; $newCoupon->usage_limit_per_user = $limit_per_user == 0 ? null : $limit_per_user; $newCoupon->multiple_coupons = $multiple_coupons; $newCoupon->exclude_sale_item = $exclude_sale_item; $newCoupon->automatically_apply = $automatically_apply; $newCoupon->save(); // Remove all existing relationships first if (isset($sid)) { $coupon->categories()->detach(); $coupon->pricelists()->detach(); $coupon->products()->detach(); $coupon->bundles()->detach(); } foreach ($apply_to_models as $apply_to_model) { $apply_to_model->coupons()->save($newCoupon); } return redirect('admin/coupons'); }
/** * Test (Fail): store with just category that doesn't exist */ public function testStoreWithOnlyCategoryFail() { // Remove all categories to produce an error $categories = Category::all(); foreach ($categories as $cat) { $cat->delete(); } $input = array('code' => 'ABC123', 'description' => 'This is a description', 'amount' => '10.99', 'is_percent' => true, 'start_date' => '02/05/2016 05:39 PM', 'end_date' => '03/05/2016 05:39 PM', 'max_spent' => '200.99', 'min_spent' => '199.88', 'usage_limit_per_coupon' => 10, 'usage_limit_per_user' => 1, 'multiple_coupons' => true, 'exclude_sale_item' => true, 'usage_limit_per_coupon_count' => 0, 'category_id' => array(1)); $this->call('POST', $this->page . '/store', $input); $this->assertRedirectedTo($this->page . '/create'); $this->assertSessionHasErrors(); // Fail because the category doesn't exist }
public static function getAllActiveOrdered() { return Category::where('active', '=', '1')->orderBy('order', 'desc')->orderBy('name')->get(); }
public function getDelete($sid) { // Find the category using the user id $category = Category::find($sid); if ($category == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', Lang::get('redminportal::messages.category_error_category_not_found')); return redirect()->back()->withErrors($errors); } // Find if there's any child $children = Category::where('category_id', $sid)->count(); if ($children > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', Lang::get('redminportal::messages.category_error_cannot_delete_has_child', ['name' => $category->name, 'children' => $children])); return redirect()->back()->withErrors($errors); } // Delete the category $category->delete(); return redirect()->back(); }