BigcommerceApi
使用方法
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
。
要求
使用 Bigcommerce API 需要您有访问 Bigcommerce 商店 API 的权限。该 API 实现了私有应用 API,并需要在您要访问的商店中设置用户和令牌。
有关设置访问权限的详细信息,请参阅 Bigcommerce 开发者网站。
- iOS 9.0+
- Xcode 10.2+
- Swift 5.0+
安装
BigcommerceApi 通过 CocoaPods 提供。要安装它,请简单地将以下行添加到您的 Podfile 中:
pod "BigcommerceApi"
设置凭证
在调用其他API之前,请在API管理器的共享实例上调用set credentials方法。由于它在调用之间维护凭证,因此您只需要调用一次共享实例。
let apiUsername = "YOUR-USERNAME"
let apiToken = "YOUR-TOKEN"
let apiStoreBaseUrl = "https://www.yourstoreurl.com/api/v2/"
BigcommerceApi.sharedInstance.setCredentials(apiUsername, token: apiToken, storeBaseUrl: apiStoreBaseUrl)
获取最近订单
通过计数和页码获取最近订单
let page = 0
let limit = 50
BigcommerceApi.sharedInstance.getOrdersMostRecent { (orders, error) -> () in
if(error == nil) {
print("Got \(orders.count) most recent orders!")
} else {
print("Error getting orders: \(error!.localizedDescription)")
}
}
获取订单状态选项
获取可用订单状态的选项
BigcommerceApi.sharedInstance.getOrderStatuses { (orderStatuses, error) -> () in
//Check for an error and then load
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil) {
print("Got \(orderStatuses.count) order statuses")
} else {
print("Error loading order statuses: \(error!.localizedDescription)")
}
})
}
获取指定状态订单
获取具有特定状态的最近的50个订单。可以通过getOrderStatuses方法获取可能的状态ID。
let orderStatusFilterId = 0
BigcommerceApi.sharedInstance.getOrdersWithStatus(orderStatusFilterId, completion: { (orders, error) -> () in
if(error == nil) {
print("Got \(orders.count) most recent orders!")
} else {
print("Error getting orders: \(error!.localizedDescription)")
}
}
通过ID获取特定订单
通过特定的订单ID(字符串)获取订单记录
let orderId = "an-order-id"
BigcommerceApi.sharedInstance.getOrder(orderId: orderId) { (order, error) -> () in
//Check for error
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error != nil || order == nil) {
print("order ID not found: \(error!.localizedDescription)")
} else {
print("got order with ID \(orderId)")
}
})
}
更新订单状态
更新订单状态
let orderId = "an-order-id"
let newStatusId = 0
BigcommerceApi.sharedInstance.updateOrderStatus(orderId, newStatusId: newStatusId, completion: { (error) -> () in
//Check for error
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil) {
print("Successfully update order status for order with ID \(orderId)")
} else {
print("Error updating order status: \(error!.localizedDescription)")
}
})
})
更新订单员工备注
更新订单的员工备注
let orderId = "an-order-id"
let notes = "staff notes :)"
BigcommerceApi.sharedInstance.updateOrderStaffNotes(orderId, staffNotes: notes, completion: { (error) -> () in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
//Show an error or dismiss
if(error == nil) {
print("Successfully updated staff notes.")
} else {
print("Error updating staff notes: \(error!.localizedDescription)")
}
})
})
更新订单客户留言
更新订单的客户留言
let orderId = "an-order-id"
let customerMessage = "message :)"
BigcommerceApi.sharedInstance.updateOrderCustomerMessage(orderIdString, customerMessage: notes, completion: { (error) -> () in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
//Show an error or dismiss
if(error == nil) {
print("Successfully updated staff notes.")
} else {
print("Error updating customer message: \(error!.localizedDescription)")
}
})
})
获取订单的产品
BigcommerceApi.sharedInstance.getProductsForOrder(order, completion: { (orderProducts, error) -> () in
if(error == nil) {
print("Successfully loaded \(orderProducts.count) order products")
} else {
print("Error loading order products: \(error!.localizedDescription)")
}
})
获取订单的发货地址
BigcommerceApi.sharedInstance.getShippingAddressesForOrder(order, completion: { (orderShippingAddresses, error) -> () in
if(error == nil) {
print("loaded \(orderShippingAddresses.count) shipping addresses for order")
} else {
print("Error loading order shipping addresses: \(error!.localizedDescription)")
}
})
获取订单的物流信息
BigcommerceApi.sharedInstance.getShipmentsForOrder(order) { (orderShipments, error) -> () in
if(error == nil) {
print("loaded \(orderShipments.count) shipments for order.")
} else {
print("Error loading order shipments: \(error!.localizedDescription)")
}
}
获取产品
BigcommerceApi.sharedInstance.getProducts { (products, error) -> () in
//Check for error
dispatch_async(dispatch_get_main_queue(), { () -> Void in=
if(error == nil) {
print("loaded \(products.count) products")
} else {
print("Error getting products: \(error!.localizedDescription)")
}
})
}
通过SKU获取产品
BigcommerceApi.sharedInstance.getProductsWithSku(searchText, completion: { (products, error) -> () in
//Check for error
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil) {
print("loaded \(products.count) products")
} else {
print("Error getting products: \(error!.localizedDescription)")
}
})
})
通过关键字获取产品
BigcommerceApi.sharedInstance.getProductsWithKeyword(searchText) { (products, error) -> () in
//Check for error
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil) {
print("loaded \(products.count) products")
} else {
print("Error getting products: \(error!.localizedDescription)")
}
})
}
更新产品库存
BigcommerceApi.sharedInstance.updateProductInventory(productId, trackInventory: trackInventoryType, newInventoryLevel: level, newLowLevel: lowLevel, completion: { (error) -> () in
//Handle error and dismiss view controller
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil) {
print("successfully updated product inventory")
} else {
print("Error updating product inventory: \(error!.localizedDescription)")
}
})
})
更新产品定价
BigcommerceApi.sharedInstance.updateProductPricing(productIdString, price: price, costPrice: cost, retailPrice: retailPrice, salePrice: salePrice, completion: { (error) -> () in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil) {
print("successfully updated product pricing")
} else {
print("Error updating product pricing: \(error!.localizedDescription)")
}
})
})
获取产品图片
BigcommerceApi.sharedInstance.getProductImages(productId, completion: { (productImages, error) -> () in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil) {
print("Loaded \(productImages.count) images.")
} else {
print("Error loading product images: \(error!.localizedDescription)")
}
})
})
获取客户信息
BigcommerceApi.sharedInstance.getCustomers { (customers, error) -> () in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil) {
print("Loaded \(customers.count) customers.")
} else {
print("Error loading customers: \(error!.localizedDescription)")
}
})
}
获取客户地址
BigcommerceApi.sharedInstance.getCustomerAddresses(customerId, completion: { (customerAddresses, error) -> () in
if(error == nil) {
print("Loaded \(customerAddresses.count) customer addresses.")
} else {
print("Error loading customer addresses: \(error!.localizedDescription)")
}
})
获取订单消息
BigcommerceApi.sharedInstance.getOrderMessages(orderIdString, completion: { (orderMessages, error) -> () in
if(error == nil) {
print("Loaded \(orderMessages.count) order messages.")
} else {
print("Error getting order messages: \(error!.localizedDescription)")
}
})
获取商店
BigcommerceApi.sharedInstance.getStore()
作者
The BigcommerceApi项目是一个独立的计划,以任何方式都与Bigcommerce无正式关联。
许可
BigcommerceApi在MIT许可下提供。有关更多信息,请参阅LICENSE文件。