Exemplo n.º 1
0
 public function testMagicGet()
 {
     $bag = new Bag();
     $this->assertNull($bag->foo);
     $container = new Container();
     $container["foo"] = "FOO";
     $bag->setContainer($container);
     $this->assertEquals("FOO", $bag->foo);
 }
Exemplo n.º 2
0
 public function testArrayAccess()
 {
     $bag = new Bag();
     $bag['foo'] = 'bar';
     $this->assertTrue(isset($bag['foo']));
     $this->assertEquals('bar', $bag['foo']);
     $this->assertEquals('bar', $bag->get('foo'));
     unset($bag['foo']);
     $this->assertEquals(null, $bag->get('foo'));
     $this->assertFalse(isset($bag['foo']));
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 public function get($field, $default = null)
 {
     if (!$this->get->has($field)) {
         if (!$this->post->has($field)) {
             if (!$this->cookie->has($field)) {
                 if ($default === null) {
                     throw new RequestParameterNotFoundException();
                 }
                 return $default;
             } else {
                 return $this->cookie->get($field);
             }
         } else {
             return $this->post->get($field);
         }
     } else {
         return $this->get->get($field);
     }
 }
Exemplo n.º 5
0
Arquivo: User.php Projeto: Fash1/Fash1
 public function getBagPrice()
 {
     $bag = Bag::with('product')->where('user_id', '=', Auth::user()->id)->get();
     $price = 0;
     if (!$bag->isEmpty()) {
         foreach ($bag as $key => $bag_item) {
             $price = $price + $bag_item->product->price;
         }
     }
     return $price;
 }
Exemplo n.º 6
0
 public function getCheckout()
 {
     // Get the bag items.
     $bag = Bag::with('product.product_media.media')->where('user_id', '=', Auth::user()->id)->get();
     // Get the cards.
     $cards = Stripe::getCards();
     // Get the addresses.
     $addresses = Address::where('user_id', '=', Auth::user()->id)->get();
     // Render the view.
     return View::make('brochure.my.checkout', ['bag' => $bag, 'cards' => $cards->data, 'addresses' => $addresses]);
 }
 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);
 }
Exemplo n.º 8
0
 public static function charge($data)
 {
     self::init();
     // Calculate the total price.
     $bag = Bag::with('product')->where('user_id', '=', Auth::user()->id)->get();
     $total = 0;
     foreach ($bag as $key => $bag_item) {
         $total = $total + $bag_item->product->price;
     }
     // Create the charge.
     $charge = \Stripe\Charge::create(array("amount" => $total, "currency" => "gbp", "customer" => Auth::user()->stripe_key, "description" => "Payment for Fash1 cart items, user_id: " . Auth::user()->id));
     if ($charge->paid == 1) {
         return true;
     }
     return false;
 }
Exemplo n.º 9
0
 /**
  * @param $name
  * @param bool $raw
  * @param null $callback
  * @return mixed|string
  */
 public function get($name, $raw = false, $callback = null)
 {
     return parent::get(strtolower(str_replace('_', '-', $name)), $raw, $callback);
 }
Exemplo n.º 10
0
 public function remove($path)
 {
     $parts = explode('/', $path);
     if (count($parts) <= 1) {
         return parent::remove($path);
     }
     // Loop to collection above item to remove
     $previousKey = null;
     $current = $this;
     while (count($parts) > 1) {
         $key = array_shift($parts);
         if (!Utils::isArrayAccessible($current)) {
             throw new \RuntimeException("Trying to remove path {$path}, " . "but {$previousKey} is not array accessible");
         }
         $previousKey = $key;
         if (!isset($current[$key])) {
             return null;
         }
         $current =& $this->getSubCollection($current, $key);
     }
     // $key currently is key of current collection.
     // We need the key of the item to remove in current collection.
     $key = array_shift($parts);
     if (!Utils::isArrayAccessible($current)) {
         throw new \RuntimeException("Trying to remove path {$path}, " . "but {$previousKey} is not array accessible");
     }
     if ($current instanceof Bag) {
         return $current->remove($key);
     }
     unset($current[$key]);
     return null;
 }
Exemplo n.º 11
0
 /**
  * @dataProvider crappyAddMessageArgumentsProvider
  * @expectedException \InvalidArgumentException
  */
 public function testIfStoringCrapWorks($message, $type)
 {
     $this->bag->addMessage($message, $type);
 }
Exemplo n.º 12
0
 /**
  * Set the item taxes
  *
  * @param Bag $value
  * @return Item
  */
 public function setTaxes($value)
 {
     if (is_array($value)) {
         $bag = new Bag();
         foreach ($value as $taxParameters) {
             $bag->add(new Tax($taxParameters));
         }
         $value = $bag;
     }
     return $this->setParameter('taxes', $value);
 }
Exemplo n.º 13
0
 /**
  * Calculates the free space of a character. If the item can stack
  * to another item it will be allowed to loot.
  * @todo set this place somewhere else. E.g. bag.
  *
  * @param int $character_id the ID of the current character
  * @param int $item_id the ID of the lootable item
  * @param boolean $returnBagIndex set true to return an array with a `bag_id` and `index`
  * @return array|boolean if there is not space left it returns a false. @see $returnBagIndex for array
  */
 function hasFreeSpace($character_id = null, $item_id = null, $returnBagIndex = false)
 {
     App::import('Model', 'Bag');
     $Bag = new Bag();
     $Bag->unbindModelAll();
     $Bag->bindModel(array('belongsTo' => array('Item')));
     $Bag->Item->unbindModelAll();
     $Bag->Item->bindModel(array('hasAndBelongsToMany' => array('Stat')));
     $Bag->recursive = 2;
     $bags = $Bag->find('all', array('conditions' => array('Bag.character_id' => $character_id)));
     $total_slots = 0;
     $total_slots_filled = 0;
     $bag_ids = array();
     $firstBagIndex = array();
     $bag_counts = array();
     $bag_indexes = array();
     foreach ($bags as $bag) {
         $bag_ids[] = $bag['Bag']['id'];
         $total_slots += $bag['Item']['StatNamed']['slots'];
         $bag_counts[$bag['Bag']['id']] = $bag['Item']['StatNamed']['slots'];
     }
     App::import('Model', 'Inventory');
     $Inventory = new Inventory();
     $inventories = $Inventory->getBag($bag_ids);
     foreach ($inventories as $inventory) {
         if ($inventory['Item']['id'] == $item_id && $inventory['Item']['stackable'] > $inventory[0]['count']) {
             if ($returnBagIndex == true) {
                 return array('bag_id' => $inventory['Inventory']['bag_id'], 'index' => $inventory['Inventory']['index']);
             } else {
                 return true;
             }
         }
         $bag_indexes[$inventory['Inventory']['bag_id']][$inventory['Inventory']['index']] = 1;
         $total_slots_filled++;
     }
     if ($total_slots_filled < $total_slots) {
         if ($returnBagIndex == true) {
             foreach ($bag_counts as $bag_id => $count) {
                 if ($count > 0) {
                     asort($bag_indexes);
                     $last_index = 0;
                     for ($i = 1; $i <= $bag_counts[$bag_id]; $i++) {
                         if (!isset($bag_indexes[$bag_id][$i])) {
                             $firstBagIndex = array('bag_id' => $bag_id, 'index' => $i);
                             break 2;
                         }
                     }
                 }
             }
             $firstBagIndex['bag_id'] = !isset($firstBagIndex['bag_id']) || $firstBagIndex['bag_id'] == 0 ? $bag_ids[0] : $firstBagIndex['bag_id'];
             $firstBagIndex['index'] = !isset($firstBagIndex['index']) || $firstBagIndex['index'] == 0 ? 1 : $firstBagIndex['index'];
             return $firstBagIndex;
         } else {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 14
0
 /**
  * ServerAttribute constructor.
  * @param array $bag
  */
 public function __construct(array $bag)
 {
     parent::__construct($bag);
 }