Skip to content

Commit

Permalink
Added sort order for product types in SKHelperProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
russell-archer committed Oct 14, 2024
1 parent b762f8f commit c3f968a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/SKHelper/Core/SKHelper+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public extension SKHelper {
var allSKHelperPurchasedProducts: [SKHelperProduct] { products.filter { $0.hasEntitlement }}

/// A collection of all localized `Product` returned by the App Store. An empty collection will be returned if products have not been successfully returned fromt he App Store.
var allProducts: [Product] { products.map { $0.product }}
var allProducts: [Product] { products.sorted { $0.sortOrder < $1.sortOrder }.map { $0.product }}

/// A collection of all configured `ProductId`.
var allProductIds: [ProductId] { products.map { $0.id }}
Expand Down
10 changes: 10 additions & 0 deletions Sources/SKHelper/Core/SKHelperProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SKHelperProduct: Identifiable, Equatable {
/// The group level of the subscription, or Int.max if this is not a subscription. Subscriptions with a lower group level indicate a higher level of service.
/// For example, if someone subscribes to a subscription with a group level lower than their current subscription, this would be an upgrade.
public let groupLevel: Int

/// The sort order for this product when shown in a list with other types of product.
public let sortOrder: Int

/// A cached entitlement to use the product.
public var hasEntitlement: Bool
Expand All @@ -43,6 +46,13 @@ public class SKHelperProduct: Identifiable, Equatable {
self.groupName = product.subscription?.groupDisplayName
self.groupId = product.subscription?.subscriptionGroupID
self.groupLevel = product.subscription?.groupLevel ?? Int.max

switch product.type {
case .nonConsumable: self.sortOrder = 0
case .consumable: self.sortOrder = 1
case .autoRenewable: self.sortOrder = 2
default : self.sortOrder = 3
}
}

nonisolated public static func == (lhs: SKHelperProduct, rhs: SKHelperProduct) -> Bool { lhs.id == rhs.id }
Expand Down

0 comments on commit c3f968a

Please sign in to comment.