Skip to content

Commit 1ed1cdd

Browse files
Merge pull request #644 from wordpress-mobile/task/21780-no-site-cart
Add support for no-site carts
2 parents 836b85e + 00c748e commit 1ed1cdd

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ _None._
5454
### New Features
5555

5656
- Add optional `tag` parameter to `PostServiceRemoteOptions` [#640]
57+
- Add support for creating a shopping cart that's not tied to a specific site. [#644]
5758

5859
## 8.9.1
5960

WordPressKit/TransactionsServiceRemote.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ import WordPressShared
4141
/// - siteID: id of the current site
4242
/// - products: an array of products to be added to the newly created cart
4343
/// - temporary: true if the card is temporary, false otherwise
44-
public func createShoppingCart(siteID: Int,
44+
public func createShoppingCart(siteID: Int?,
4545
products: [TransactionsServiceProduct],
4646
temporary: Bool,
4747
success: @escaping (CartResponse) -> Void,
4848
failure: @escaping (Error) -> Void) {
49-
50-
let endPoint = "me/shopping-cart/\(siteID)"
49+
let siteIDString = siteID != nil ? "\(siteID ?? 0)" : "no-site"
50+
let endPoint = "me/shopping-cart/\(siteIDString)"
5151
let urlPath = path(forEndpoint: endPoint, withVersion: ._1_1)
5252

5353
var productsDictionary: [[String: AnyObject]] = []
@@ -151,12 +151,12 @@ public enum TransactionsServiceProduct {
151151

152152
public struct CartResponse {
153153
let blogID: Int
154-
let cartKey: Int
154+
let cartKey: Any // cart key can be either Int or String
155155
let products: [Product]
156156

157157
init?(jsonDictionary: [String: AnyObject]) {
158158
guard
159-
let cartKey = jsonDictionary["cart_key"] as? Int,
159+
let cartKey = jsonDictionary["cart_key"],
160160
let blogID = jsonDictionary["blog_id"] as? Int,
161161
let products = jsonDictionary["products"] as? [[String: AnyObject]]
162162
else {

0 commit comments

Comments
 (0)