public function getAddBag($id) { $bag = new Bag(); $bag->user_id = Auth::user()->id; $bag->product_id = $id; $bag->quantity = 1; $bag->save(); $product = Product::where('id', '=', $id)->first(); // Flash and redirect. Session::flash('alert', $product->name . ' was added to your bag.'); return Redirect::to('/collection/' . $product->slug); }
function add() { if (isset($this->data) && !empty($this->data)) { $this->data['Character']['user_id'] = $this->Auth->user('id'); $this->data['Character']['area_id'] = '74'; if ($this->Character->save($this->data)) { // Save a default bag for this character App::import('Model', 'Bag'); $Bag = new Bag(); $Bag->save(array('Bag' => array('item_id' => '421', 'character_id' => $this->Character->id, 'index' => '1'))); // Stats @ App::import('Model', 'CharactersStat'); $CharactersStat = new CharactersStat(); $basicStats = array(); $basisStats[] = array('character_id' => $this->Character->id, 'stat_id' => '1', 'amount' => '80'); // Health $basisStats[] = array('character_id' => $this->Character->id, 'stat_id' => '2', 'amount' => '100'); // Mana $basisStats[] = array('character_id' => $this->Character->id, 'stat_id' => '5', 'amount' => '1'); // Min damage $basisStats[] = array('character_id' => $this->Character->id, 'stat_id' => '6', 'amount' => '3'); // Max damage $basisStats[] = array('character_id' => $this->Character->id, 'stat_id' => '8', 'amount' => '0'); // Experience $basisStats[] = array('character_id' => $this->Character->id, 'stat_id' => '9', 'amount' => '5000'); // Charisma $CharactersStat->saveAll($basisStats); $this->redirect('/characters'); } } $this->crumbs[] = array('name' => __('Characters', true), 'link' => '/characters'); $this->crumbs[] = array('name' => __('Create', true), 'link' => '/characters/add'); $pages = $this->Interface->getWebsiteMenus(); $this->Character->contain('Type', 'Avatar'); $types = $this->Character->Type->find('list'); $avatars = $this->Character->Avatar->find('all'); $this->title_for_layout = 'Naxasius: Create character'; $this->set('types', $types); $this->set('avatars', $avatars); $this->set('pages', $pages); }