File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 88 },
99 "require-dev" : {
1010 "phpunit/phpunit" : " ^9.3.9" ,
11- "orchestra/testbench" : " ^6.0.0 " ,
11+ "orchestra/testbench" : " ^6.15.1 " ,
1212 "laravel/legacy-factories" : " ^1.0.4"
1313 },
1414 "license" : " MIT" ,
Original file line number Diff line number Diff line change @@ -93,6 +93,27 @@ protected function existenceCheckFor($cartItemIndex)
9393 }
9494 }
9595
96+ /**
97+ * Set the quantity of a cart item.
98+ *
99+ * @param int Index of the cart item
100+ * @param int quantity to be increased
101+ * @return array
102+ */
103+ public function setQuantityAt ($ cartItemIndex , $ quantity )
104+ {
105+ $ this ->existenceCheckFor ($ cartItemIndex );
106+
107+ $ this ->items [$ cartItemIndex ]->quantity = $ quantity ;
108+
109+ $ this ->cartDriver ->setCartItemQuantity (
110+ $ this ->items [$ cartItemIndex ]->id ,
111+ $ this ->items [$ cartItemIndex ]->quantity
112+ );
113+
114+ return $ this ->cartUpdates ();
115+ }
116+
96117 /**
97118 * Increments the quantity of a cart item.
98119 *
Original file line number Diff line number Diff line change @@ -62,6 +62,16 @@ public function remove_an_item_from_cart()
6262 $ this ->assertTrue (cart ()->isEmpty ());
6363 }
6464
65+ /** @test */
66+ public function cart_item_input_quantity_update ()
67+ {
68+ $ this ->addACartItem ();
69+
70+ $ cart = cart ()->setQuantityAt (0 , 5 );
71+
72+ $ this ->assertSame (5 , $ cart ['items ' ][0 ]['quantity ' ]);
73+ }
74+
6575 /** @test */
6676 public function increment_cart_item_quantity ()
6777 {
You can’t perform that action at this time.
0 commit comments