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

Commit 332a52b

Browse files
committed
feat: ability to edit items
1 parent 1ca5c87 commit 332a52b

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ public function addItem($cartId, $sku, $quantity)
5353
]);
5454
}
5555

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

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)