示例#1
0
文件: CartTest.php 项目: jamesdb/cart
 /**
  * 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);
 }
示例#2
0
文件: Cart.php 项目: jamesdb/cart
 /**
  * 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;
 }