Exemple #1
0
 /**
  * Ensure generated row ids are excluding quantities.
  */
 public function testRowIdCreationIgnoresQuantity()
 {
     $item1 = new CartItem(['id' => 32, 'name' => '100 Rubber Ducks', 'price' => 4995]);
     $item2 = new CartItem(['id' => 32, 'name' => '100 Rubber Ducks', 'price' => 4995, 'quantity' => 6]);
     $this->assertSame($item1->getRowId(), $item2->getRowId());
     $this->assertSame($item1->rowid, $item2->rowid);
 }
Exemple #2
0
 /**
  * Add an item.
  *
  * @param  \jamesdb\Cart\CartItem $item
  *
  * @return string
  */
 public function add(CartItem $item)
 {
     $rowId = $item->getRowId();
     if ($row = $this->getItem($rowId)) {
         $row->quantity += $item->quantity;
     } else {
         $this->contents[$rowId] = $item;
     }
     $this->storage->store($this->identifier, serialize($this->toArray()));
     $this->getEventEmitter()->emit(new CartEvent\CartItemAddEvent($this, $item));
     return $rowId;
 }