Beispiel #1
0
 /**
  * Add an inventory to the cart
  *
  * @return void
  */
 public function onAddToCart()
 {
     $quantity = input('quantity', 1);
     $productId = input('product');
     $selectionIds = input('selections', []);
     $this->repository->addToCart($productId, $selectionIds, $quantity);
 }
 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);
 }