Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 1302c04

Browse files
Update: Add support for no-site carts
1 parent ae2d7a1 commit 1302c04

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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
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"] as? Any,
160160
let blogID = jsonDictionary["blog_id"] as? Int,
161161
let products = jsonDictionary["products"] as? [[String: AnyObject]]
162162
else {

0 commit comments

Comments
 (0)