Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ Returns information for the cart for the authenticated customer. Must use a sing
Magento::api('carts')->mine();
```

`/V1/carts/mine/coupons/{couponCode}`

Apply a coupon to a specified cart.
```php
Magento::api('carts')->couponCode($couponCode);
```

#### Cart Items (quoteCartItemRepositoryV1)

`/V1/carts/mine/items/`
Expand Down Expand Up @@ -225,6 +232,13 @@ Estimate shipping by address and return list of available shipping methods.
Magento::api('guestCarts')->estimateShippingMethods($cartId);
```

`/V1/guest-carts/{cartId}/coupons/{couponCode}`

Apply a coupon to a specified cart.
```php
Magento::api('guestCarts')->couponCode($cartId, $couponCode);
```

<a id="orders"></a>
### Orders (salesOrderRepositoryV1)

Expand Down
21 changes: 21 additions & 0 deletions src/Api/Carts.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,25 @@ public function paymentInformation($body = [])

return $this->post('/carts/mine/payment-information', $body);
}

/**
* Apply a coupon to a specified cart.
*
* @param string $couponCode
* @return void
*/
public function couponCode($couponCode)
{
return $this->put('/carts/mine/coupons/'.$couponCode);
}

/**
* Removes coupon(s) from specified cart.
*
* @return void
*/
public function removeCoupons()
{
return $this->delete('/carts/mine/coupons');
}
}
22 changes: 22 additions & 0 deletions src/Api/GuestCarts.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,26 @@ public function removeItem($cartId, $itemId)
{
return $this->delete('/guest-carts/'.$cartId.'/items/'.$itemId);
}

/**
* Apply a coupon to a specified cart.
*
* @param string $cartId
* @param string $couponCode
* @return void
*/
public function couponCode($cartId, $couponCode)
{
return $this->put('/guest-carts/'.$cartId.'/coupons/'.$couponCode);
}

/**
* Removes coupon(s) from specified cart.
*
* @return void
*/
public function removeCoupons($cartId)
{
return $this->delete('/guest-carts/'.$cartId.'/coupons');
}
}
22 changes: 22 additions & 0 deletions tests/Api/CartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,26 @@ public function test_must_pass_a_single_store_code_to_payment_information()

MagentoFacade::api('carts')->paymentInformation([]);
}

public function test_can_add_coupon_code()
{
Http::fake([
'*rest/default/V1/carts/mine/coupons/foo' => Http::response('foo', 200),
]);

$api = MagentoFacade::setStoreCode('default')->api('carts')->couponCode('foo');

$this->assertTrue($api->ok());
}

public function test_can_remove_coupon_code()
{
Http::fake([
'*rest/default/V1/carts/mine/coupons' => Http::response('foo', 200),
]);

$api = MagentoFacade::setStoreCode('default')->api('carts')->removeCoupons();

$this->assertTrue($api->ok());
}
}
22 changes: 22 additions & 0 deletions tests/Api/GuestCartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,26 @@ public function test_can_remove_items_from_cart()

$this->assertTrue($api->ok());
}

public function test_can_add_coupon()
{
Http::fake([
'*rest/all/V1/guest-carts/foo/coupons/bar' => Http::response([], 200),
]);

$api = MagentoFacade::api('guestCarts')->couponCode('foo', 'bar');

$this->assertTrue($api->ok());
}

public function test_can_remove_coupon()
{
Http::fake([
'*rest/all/V1/guest-carts/foo/coupons' => Http::response([], 200),
]);

$api = MagentoFacade::api('guestCarts')->removeCoupons('foo');

$this->assertTrue($api->ok());
}
}