/** * Setup initial data for use in tests */ public function setup() { parent::setup(); $this->seed('RedminSeeder'); // Add membership $membership = new Membership(); $membership->name = "Gold"; $membership->rank = 5; $membership->save(); // Add module $module = new Module(); $module->name = 'This is title'; $module->sku = 'UNIQUESKU001'; $module->short_description = 'This is body'; $module->long_description = 'This is long body'; $module->featured = true; $module->active = true; $module->category_id = 1; $module->save(); // Create a new Pricelist for use later $pricelist = new Pricelist(); $pricelist->price = 0; $pricelist->module_id = 1; $pricelist->membership_id = 1; $pricelist->save(); }
/** * Setup initial data for use in tests */ public function setup() { parent::setup(); // Add membership $membership = new Membership(); $membership->name = "Gold"; $membership->rank = 5; $membership->save(); // Add module $module = new Module(); $module->name = 'This is title'; $module->sku = 'UNIQUESKU001'; $module->short_description = 'This is body'; $module->long_description = 'This is long body'; $module->featured = true; $module->active = true; $module->category_id = 1; $module->save(); // Create a new Pricelist for use later $pricelist = new Pricelist(); $pricelist->module_id = 1; $pricelist->membership_id = 1; $pricelist->price = 1; $pricelist->save(); // Create a new Product for use later $product = new Product(); $product->name = 'This is the title'; $product->sku = 'UNIQUESKU001'; $product->short_description = 'This is the body'; $product->category_id = 1; $product->active = true; $product->save(); // Create a new Category for use later $category = new Category(); $category->name = 'This is a name'; $category->short_description = 'This is short description'; $category->long_description = 'This is long description'; $category->active = true; $category->order = 1; $category->save(); }
public function getCreate() { $products = Product::where('active', true)->orderBy('name')->lists('name', 'id'); $bundles = Bundle::where('active', true)->orderBy('name')->lists('name', 'id'); $coupons = Coupon::orderBy('code')->lists('code', 'id'); $pricelists = array(); $pricelists_get = Pricelist::join('modules', 'modules.id', '=', 'pricelists.module_id')->join('memberships', 'memberships.id', '=', 'pricelists.membership_id')->where('modules.active', true)->orderBy('modules.name')->orderBy('memberships.rank', 'desc')->select('pricelists.*')->get(); foreach ($pricelists_get as $pricelist) { $pricelists[$pricelist->id] = $pricelist->name; } $payment_statuses = config('redminportal::payment_statuses'); return view('redminportal::orders/create')->with('products', $products)->with('bundles', $bundles)->with('coupons', $coupons)->with('pricelists', $pricelists)->with('payment_statuses', $payment_statuses); }
public function postStore() { $sid = \Input::get('id'); $rules = array('pricelist_id' => 'required|integer', 'transaction_id' => 'required', 'payment_status' => 'required', 'paid' => 'numeric', 'email' => 'required|email'); $validation = \Validator::make(\Input::all(), $rules); $redirect_url = isset($sid) ? 'admin/purchases/edit/' . $sid : 'admin/purchases/create'; if ($validation->fails()) { return redirect($redirect_url)->withErrors($validation)->withInput(); } $pricelist_id = \Input::get('pricelist_id'); $transaction_id = \Input::get('transaction_id'); $payment_status = \Input::get('payment_status'); $paid = \Input::get('paid'); $email = \Input::get('email'); $pricelist = Pricelist::find($pricelist_id); // No such pricelist if ($pricelist == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('pricelistError', "The Module/Membership may have been deleted. Please try again."); return redirect($redirect_url)->withErrors($errors)->withInput(); } $user = User::where('email', $email)->first(); if ($user == null) { // No such user $errors = new \Illuminate\Support\MessageBag(); $errors->add('userError', "The user may have been deleted. Please try again."); return redirect($redirect_url)->withErrors($errors)->withInput(); } // Check if user_pricelist already exist $existing = UserPricelist::join('order_pricelist', 'orders.id', '=', 'order_pricelist.id')->where('orders.user_id', $user->id)->where('order_pricelist.pricelist_id', $pricelist->id)->count(); if ($existing > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('userpricelistError', $email . " has already purchased " . $pricelist->module->name . " (" . $pricelist->membership->name . ")."); return redirect($redirect_url)->withErrors($errors)->withInput(); } $new_purchase = new UserPricelist(); $new_purchase->user_id = $user->id; $new_purchase->pricelist_id = $pricelist->id; $new_purchase->paid = $paid; $new_purchase->transaction_id = $transaction_id; $new_purchase->payment_status = $payment_status; $new_purchase->save(); return redirect('admin/purchases'); }
/** * Test (Pass): access postStore to create with input, price for 1 membership and medias */ public function testStoreMediasPass() { // Add membership $membership = new Membership(); $membership->name = "Gold"; $membership->rank = 5; $membership->save(); // Add media $media = new Media(); $media->name = 'This is the title'; $media->path = 'path/to/somewhere'; $media->sku = 'UNIQUESKU001'; $media->short_description = 'This is the body'; $media->category_id = 1; $media->active = true; $media->save(); $input = array('name' => 'This is title', 'short_description' => 'This is body', 'cn_name' => 'CN name', 'cn_short_description' => 'CN short body', 'category_id' => 1, 'sku' => 'UNIQUESKU001', 'price_1' => 99.98999999999999, 'media_checkbox' => array('1_1'), 'price_active_1' => true); $this->call('POST', '/admin/modules/store', $input); $this->assertRedirectedTo('/admin/modules'); $pricelist = Pricelist::where('module_id', 1)->where('membership_id', 1)->first(); $this->assertTrue($pricelist != null); $this->assertTrue($pricelist->module_id == 1); $this->assertTrue($pricelist->membership_id == 1); $this->assertTrue($pricelist->price == 99.98999999999999); $this->assertTrue($pricelist->active == true); $modMediaMembership = ModuleMediaMembership::where('module_id', 1)->where('membership_id', 1)->where('media_id', 1)->first(); $this->assertTrue($modMediaMembership != null); }
public function getPricelistAttribute() { $result = Pricelist::join('order_pricelist', 'pricelists.id', '=', 'order_pricelist.pricelist_id')->where('order_id', $this->id)->first(); return $result; }
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'); }
public function postStore() { $sid = \Input::get('id'); $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'name' => 'required|unique:modules,name' . (isset($sid) ? ',' . $sid : ''), 'short_description' => 'required', 'sku' => 'required|alpha_dash|unique:modules,sku' . (isset($sid) ? ',' . $sid : ''), 'category_id' => 'required', 'tags' => 'regex:/^[a-z,0-9 -]+$/i'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->passes()) { $name = \Input::get('name'); $sku = \Input::get('sku'); $short_description = \Input::get('short_description'); $long_description = \Input::get('long_description'); $image = \Input::file('image'); $featured = \Input::get('featured') == '' ? false : true; $active = \Input::get('active') == '' ? false : true; $category_id = \Input::get('category_id'); $tags = \Input::get('tags'); $module = isset($sid) ? Module::find($sid) : new Module(); 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::to('/admin/modules')->withErrors($errors); } $module->name = $name; $module->sku = $sku; $module->short_description = $short_description; $module->long_description = $long_description; $module->featured = $featured; $module->active = $active; $module->category_id = $category_id; // Create or save changes $module->save(); // Save translations $translations = \Config::get('redminportal::translation'); foreach ($translations as $translation) { $lang = $translation['lang']; if ($lang == 'en') { continue; } $translated_content = array('name' => \Input::get($lang . '_name'), 'short_description' => \Input::get($lang . '_short_description'), 'long_description' => \Input::get($lang . '_long_description')); // Check if lang exist $translated_model = $module->translations->where('lang', $lang)->first(); if ($translated_model == null) { $translated_model = new Translation(); } $translated_model->lang = $lang; $translated_model->content = json_encode($translated_content); $module->translations()->save($translated_model); } // Save pricelist foreach (Membership::all() as $membership) { $pricelist = Pricelist::where('module_id', $module->id)->where('membership_id', $membership->id)->first(); if ($pricelist == null) { $pricelist = new Pricelist(); $pricelist->module_id = $module->id; $pricelist->membership_id = $membership->id; } $price_active = \Input::get('price_active_' . $membership->id) == '' ? false : true; $price = \Input::get('price_' . $membership->id); if (!empty($price)) { $pricelist->active = $price_active; $pricelist->price = $price; $pricelist->save(); } else { // Empty price means to delete, but check that it is not used $pricelist_used = UserPricelist::where('pricelist_id', $pricelist->id)->get(); if (count($pricelist_used) == 0) { $pricelist->delete(); } } } // Save medias $media_checkbox = \Input::get('media_checkbox'); if (isset($sid)) { // Remove all existing medias $existing_medias = ModuleMediaMembership::where('module_id', $module->id)->get(); foreach ($existing_medias as $remove_media) { $remove_media->delete(); } } if (is_array($media_checkbox)) { foreach ($media_checkbox as $check) { $media_pair = explode('_', $check); $media_id = $media_pair[0]; $membership_id = $media_pair[1]; $modMediaMembership = new ModuleMediaMembership(); $modMediaMembership->module_id = $module->id; $modMediaMembership->membership_id = $membership_id; $modMediaMembership->media_id = $media_id; $modMediaMembership->save(); } } if (!empty($tags)) { // Delete old tags $module->tags()->detach(); // Save tags foreach (explode(',', $tags) as $tagName) { Tag::addTag($module, $tagName); } } if (\Input::hasFile('image')) { //Upload the file $helper_image = new RImage(); $filename = $helper_image->upload($image, 'modules/' . $module->id, true); if ($filename) { // create photo $newimage = new Image(); $newimage->path = $filename; // save photo to the loaded model $module->images()->save($newimage); } } //if it validate } else { if (isset($sid)) { return \Redirect::to('admin/modules/edit/' . $sid)->withErrors($validation)->withInput(); } else { return \Redirect::to('admin/modules/create')->withErrors($validation)->withInput(); } } return \Redirect::to('admin/modules'); }
public function postStore() { $sid = \Input::get('id'); if (isset($sid)) { $url = 'admin/bundles/edit/' . $sid; } else { $url = 'admin/bundles/create'; } $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'name' => 'required|unique:products,name' . (isset($sid) ? ',' . $sid : ''), 'short_description' => 'required', 'price' => 'numeric', 'sku' => 'required|alpha_dash|unique:bundles,sku' . (isset($sid) ? ',' . $sid : ''), 'category_id' => 'required', 'tags' => 'regex:/^[a-z,0-9 -]+$/i'); $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)) { $bundle = Bundle::find($sid); if ($bundle == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('bundleError', "The bundle does not exist or may have been deleted."); return redirect('admin/bundles')->withErrors($errors); } } $name = Input::get('name'); $sku = Input::get('sku'); $price = Input::get('price'); $short_description = Input::get('short_description'); $long_description = Input::get('long_description'); $image = Input::file('image'); $featured = Input::get('featured') == '' ? false : true; $active = Input::get('active') == '' ? false : true; $category_id = Input::get('category_id'); $tags = Input::get('tags'); $apply_to_models = array(); $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; } } } // 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 Product or Membership/Module under Bundled Items."); return redirect($url)->withErrors($errors)->withInput(); } $newBundle = isset($sid) ? $bundle : new Bundle(); $newBundle->name = $name; $newBundle->sku = $sku; $newBundle->price = isset($price) ? $price : 0; $newBundle->short_description = $short_description; $newBundle->long_description = $long_description; $newBundle->featured = $featured; $newBundle->active = $active; $newBundle->category_id = $category_id > 0 ? $category_id : null; $newBundle->save(); // Remove all existing relationships first if (isset($sid)) { $newBundle->pricelists()->detach(); $newBundle->products()->detach(); } foreach ($apply_to_models as $apply_to_model) { $apply_to_model->bundles()->save($newBundle); } // Save translations $translations = \Config::get('redminportal::translation'); foreach ($translations as $translation) { $lang = $translation['lang']; if ($lang == 'en') { continue; } $translated_content = array('name' => \Input::get($lang . '_name'), 'short_description' => \Input::get($lang . '_short_description'), 'long_description' => \Input::get($lang . '_long_description')); // Check if lang exist $translated_model = $newBundle->translations->where('lang', $lang)->first(); if ($translated_model == null) { $translated_model = new Translation(); } $translated_model->lang = $lang; $translated_model->content = json_encode($translated_content); $newBundle->translations()->save($translated_model); } if (!empty($tags)) { // Delete old tags $newBundle->tags()->detach(); // Save tags foreach (explode(',', $tags) as $tagName) { Tag::addTag($newBundle, $tagName); } } if (Input::hasFile('image')) { //Upload the file $helper_image = new RImage(); $filename = $helper_image->upload($image, 'bundles/' . $newBundle->id, true); if ($filename) { // create photo $newimage = new Image(); $newimage->path = $filename; // save photo to the loaded model $newBundle->images()->save($newimage); } } return redirect('admin/bundles'); }