@@ -31,14 +31,15 @@ struct ProductsTabProductViewModel {
3131 productVariation: ProductVariation ? = nil ,
3232 isSelected: Bool = false ,
3333 isDraggable: Bool = false ,
34+ isSKUShown: Bool = false ,
3435 imageService: ImageService = ServiceLocator . imageService) {
3536
3637 imageUrl = product. images. first? . src
3738 name = product. name. isEmpty ? Localization . noTitle : product. name
3839 self . productVariation = productVariation
3940 self . isSelected = isSelected
4041 self . isDraggable = isDraggable
41- detailsAttributedString = EditableProductModel ( product: product) . createDetailsAttributedString ( )
42+ detailsAttributedString = EditableProductModel ( product: product) . createDetailsAttributedString ( isSKUShown : isSKUShown )
4243
4344 self . imageService = imageService
4445 }
@@ -57,16 +58,18 @@ struct ProductsTabProductViewModel {
5758}
5859
5960private extension EditableProductModel {
60- func createDetailsAttributedString( ) -> NSAttributedString {
61+ func createDetailsAttributedString( isSKUShown : Bool ) -> NSAttributedString {
6162 let statusText = createStatusText ( )
6263 let stockText = createStockText ( )
6364 let variationsText = createVariationsText ( )
6465
6566 let detailsText = [ statusText, stockText, variationsText]
6667 . compactMap ( { $0 } )
6768 . joined ( separator: " • " )
69+ let skuText = isSKUShown ? createSKUText ( ) : nil
70+ let text = [ detailsText, skuText] . compactMap { $0 } . joined ( separator: " \n " )
6871
69- let attributedString = NSMutableAttributedString ( string: detailsText ,
72+ let attributedString = NSMutableAttributedString ( string: text ,
7073 attributes: [
7174 . foregroundColor: UIColor . textSubtle,
7275 . font: StyleManager . footerLabelFont
@@ -97,6 +100,13 @@ private extension EditableProductModel {
97100 plural: Localization . VariationCount. plural)
98101 return String . localizedStringWithFormat ( format, numberOfVariations)
99102 }
103+
104+ func createSKUText( ) -> String ? {
105+ guard let sku = product. sku, sku. isNotEmpty else {
106+ return nil
107+ }
108+ return String . localizedStringWithFormat ( Localization . skuFormat, sku)
109+ }
100110}
101111
102112// MARK: Localization
@@ -109,6 +119,7 @@ private extension EditableProductModel {
109119 static let plural = NSLocalizedString ( " %1$ld variations " ,
110120 comment: " Label about number of variations shown on Products tab. Reads, `2 variations` " )
111121 }
122+ static let skuFormat = NSLocalizedString ( " SKU: %1$@ " , comment: " Label about the SKU of a product in the product list. Reads, `SKU: productSku` " )
112123 }
113124}
114125
0 commit comments