public function test_updating_a_cart()
 {
     $repository = new CartRepository();
     $product1 = Factory::create(new Product());
     $product2 = Factory::create(new Product());
     $inventory1 = Factory::create(new Inventory(), ['product_id' => $product1->id, 'quantity' => 5]);
     $inventory2 = Factory::create(new Inventory(), ['product_id' => $product2->id, 'quantity' => 5]);
     $repository->addToCart($product1->id, [], 1);
     $repository->addToCart($product2->id, [], 2);
     // Set product 1 to quantity: 3, and delete product 2
     $repository->updateCart([1 => 3, 2 => 0]);
     $this->assertEquals(3, $repository->getItemCount());
     $this->assertEquals($product1->id, $repository->getItems()->first()->id);
 }
Exemple #2
0
 /**
  * Returns the cart items
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function items()
 {
     $this->repository->loadProducts();
     return $this->repository->getItems();
 }