Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 962c6b3

Browse files
authored
Merge pull request #47 from grayloon/edit-items
Add endpoints to edit items
2 parents 1ca5c87 + 59ccbf5 commit 962c6b3

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ Add/update the specified cart item with a customer token. Must have a store code
131131
Magento::api('cartItems')->addItem($cartId, $sku, $quantity);
132132
```
133133

134+
`put` - `/V1/carts/mine/items/{itemId}`
135+
136+
Update the specified cart item with a customer token. Must have a store code.
137+
```php
138+
Magento::api('cartItems')->editItem($itemId, $body = []);
139+
```
140+
134141
Remove the specified cart item with a customer token. Must have a store code.
135142
```php
136143
Magento::api('cartItems')->removeItem($itemId);
@@ -220,6 +227,13 @@ Add/update the specified cart item.
220227
Magento::api('guestCarts')->addItem($cartId, $sku, $quantity);
221228
```
222229

230+
`put` - `/V1/guest-carts/{cartId}/items/{itemId}`
231+
232+
Update the specified cart item.
233+
```php
234+
Magento::api('guestCarts')->editItem($cartId, $itemId, $body = []);
235+
```
236+
223237
Remove the specified cart item.
224238
```php
225239
Magento::api('guestCarts')->removeItem($cartId, $itemId);

src/Api/CartItems.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ public function addItem($quoteId, $sku, $quantity)
3737
]);
3838
}
3939

40+
/**
41+
* Update the specified cart item.
42+
*
43+
* @param int $itemId
44+
* @param array $body
45+
* @return array
46+
*/
47+
public function editItem($itemId, $body = [])
48+
{
49+
$this->validateSingleStoreCode();
50+
51+
return $this->put('/carts/mine/items/'.$itemId, $body);
52+
}
53+
4054
/**
4155
* Remove the specified cart item.
4256
*

src/Api/GuestCarts.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ public function addItem($cartId, $sku, $quantity)
5353
]);
5454
}
5555

56+
/**
57+
* Add/update the specified cart item.
58+
*
59+
* @param string $cartId
60+
* @param int $itemId
61+
* @param array $body
62+
* @return array
63+
*/
64+
public function editItem($cartId, $itemId, $body = [])
65+
{
66+
return $this->put('/guest-carts/'.$cartId.'/items/'.$itemId, $body);
67+
}
68+
5669
/**
5770
* Return quote totals data for a specified cart.
5871
*

tests/Api/CartItemsTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,15 @@ public function test_can_call_cart_item_remove_item()
5555

5656
$this->assertTrue($api->ok());
5757
}
58+
59+
public function test_can_edit_cart_item()
60+
{
61+
Http::fake([
62+
'*rest/default/V1/carts/mine/items/foo' => Http::response([], 200),
63+
]);
64+
65+
$api = MagentoFacade::setStoreCode('default')->api('cartItems')->editItem('foo', []);
66+
67+
$this->assertTrue($api->ok());
68+
}
5869
}

tests/Api/GuestCartsTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,15 @@ public function test_can_remove_coupon()
145145

146146
$this->assertTrue($api->ok());
147147
}
148+
149+
public function test_can_edit_item()
150+
{
151+
Http::fake([
152+
'*rest/all/V1/guest-carts/foo/items/bar' => Http::response([], 200),
153+
]);
154+
155+
$api = MagentoFacade::api('guestCarts')->editItem('foo', 'bar', []);
156+
157+
$this->assertTrue($api->ok());
158+
}
148159
}

0 commit comments

Comments
 (0)