File tree Expand file tree Collapse file tree 6 files changed +151
-4
lines changed Expand file tree Collapse file tree 6 files changed +151
-4
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \Quote \Api ;
9
+
10
+ use Magento \Framework \Exception \CouldNotSaveException ;
11
+ use Magento \Framework \Exception \InputException ;
12
+ use Magento \Framework \Exception \NoSuchEntityException ;
13
+ use Magento \Quote \Api \Data \CartItemInterface ;
14
+
15
+ /**
16
+ * Interface AddCartItemInterface
17
+ * @api
18
+ */
19
+ interface AddCartItemInterface
20
+ {
21
+ /**
22
+ * Add the specified cart item.
23
+ *
24
+ * @param CartItemInterface $cartItem The item.
25
+ * @return CartItemInterface
26
+ * @throws NoSuchEntityException The specified cart does not exist.
27
+ * @throws CouldNotSaveException The specified item could not be saved to the cart.
28
+ * @throws InputException The specified item or cart is not valid.
29
+ */
30
+ public function execute (CartItemInterface $ cartItem );
31
+ }
Original file line number Diff line number Diff line change @@ -29,6 +29,11 @@ public function getList($cartId);
29
29
* @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist.
30
30
* @throws \Magento\Framework\Exception\CouldNotSaveException The specified item could not be saved to the cart.
31
31
* @throws \Magento\Framework\Exception\InputException The specified item or cart is not valid.
32
+ *
33
+ * @deprecated Post and put endpoint should be separated
34
+ *
35
+ * @see \Magento\Quote\Api\AddCartItemInterface
36
+ * @see \Magento\Quote\Api\UpdateCartItemInterface
32
37
*/
33
38
public function save (\Magento \Quote \Api \Data \CartItemInterface $ cartItem );
34
39
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \Quote \Api ;
9
+
10
+ use Magento \Framework \Exception \CouldNotSaveException ;
11
+ use Magento \Framework \Exception \InputException ;
12
+ use Magento \Framework \Exception \NoSuchEntityException ;
13
+ use Magento \Quote \Api \Data \CartItemInterface ;
14
+
15
+ /**
16
+ * Interface AddCartItemInterface
17
+ * @api
18
+ */
19
+ interface UpdateCartItemInterface
20
+ {
21
+ /**
22
+ * Update the specified cart item.
23
+ *
24
+ * @param CartItemInterface $cartItem The item.
25
+ * @return CartItemInterface Item.
26
+ * @throws NoSuchEntityException The specified cart does not exist.
27
+ * @throws CouldNotSaveException The specified item could not be saved to the cart.
28
+ * @throws InputException The specified item or cart is not valid.
29
+ */
30
+ public function execute (CartItemInterface $ cartItem );
31
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \Quote \Model \Quote \Item ;
9
+
10
+ use Magento \Quote \Api \AddCartItemInterface ;
11
+ use Magento \Quote \Api \Data \CartItemInterface ;
12
+
13
+ /**
14
+ * Add the specified cart item
15
+ */
16
+ class AddCartItem implements AddCartItemInterface
17
+ {
18
+ /**
19
+ * @var Repository
20
+ */
21
+ private $ quoteItemRepository ;
22
+
23
+ /**
24
+ * @param Repository $quoteItemRepository
25
+ */
26
+ public function __construct (Repository $ quoteItemRepository )
27
+ {
28
+ $ this ->quoteItemRepository = $ quoteItemRepository ;
29
+ }
30
+
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ public function execute (CartItemInterface $ cartItem )
35
+ {
36
+ if (isset ($ cartItem [CartItemInterface::KEY_ITEM_ID ])) {
37
+ unset($ cartItem [CartItemInterface::KEY_ITEM_ID ]);
38
+ }
39
+
40
+ return $ this ->quoteItemRepository ->save ($ cartItem );
41
+ }
42
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \Quote \Model \Quote \Item ;
9
+
10
+ use Magento \Quote \Api \AddCartItemInterface ;
11
+ use Magento \Quote \Api \Data \CartItemInterface ;
12
+
13
+ /**
14
+ * Update the specified cart item
15
+ */
16
+ class UpdateCartItem implements AddCartItemInterface
17
+ {
18
+ /**
19
+ * @var Repository
20
+ */
21
+ private $ quoteItemRepository ;
22
+
23
+ /**
24
+ * @param Repository $quoteItemRepository
25
+ */
26
+ public function __construct (Repository $ quoteItemRepository )
27
+ {
28
+ $ this ->quoteItemRepository = $ quoteItemRepository ;
29
+ }
30
+
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ public function execute (CartItemInterface $ cartItem )
35
+ {
36
+ return $ this ->quoteItemRepository ->save ($ cartItem );
37
+ }
38
+ }
Original file line number Diff line number Diff line change 177
177
</resources >
178
178
</route >
179
179
<route url =" /V1/carts/:quoteId/items" method =" POST" >
180
- <service class =" Magento\Quote\Api\CartItemRepositoryInterface " method =" save " />
180
+ <service class =" Magento\Quote\Api\AddCartItemInterface " method =" execute " />
181
181
<resources >
182
182
<resource ref =" Magento_Cart::manage" />
183
183
</resources >
184
184
</route >
185
185
<route url =" /V1/carts/:cartId/items/:itemId" method =" PUT" >
186
- <service class =" Magento\Quote\Api\CartItemRepositoryInterface " method =" save " />
186
+ <service class =" Magento\Quote\Api\UpdateCartItemInterface " method =" execute " />
187
187
<resources >
188
188
<resource ref =" Magento_Cart::manage" />
189
189
</resources >
232
232
</data >
233
233
</route >
234
234
<route url =" /V1/carts/mine/items" method =" POST" >
235
- <service class =" Magento\Quote\Api\CartItemRepositoryInterface " method =" save " />
235
+ <service class =" Magento\Quote\Api\AddCartItemInterface " method =" execute " />
236
236
<resources >
237
237
<resource ref =" self" />
238
238
</resources >
241
241
</data >
242
242
</route >
243
243
<route url =" /V1/carts/mine/items/:itemId" method =" PUT" >
244
- <service class =" Magento\Quote\Api\CartItemRepositoryInterface " method =" save " />
244
+ <service class =" Magento\Quote\Api\UpdateCartItemInterface " method =" execute " />
245
245
<resources >
246
246
<resource ref =" self" />
247
247
</resources >
You can’t perform that action at this time.
0 commit comments