Skip to content

Commit 41a663d

Browse files
authored
Merge pull request #211 from virtusize/bugfix/NSDK-383-no-size
NSDK-383 no size test issue
2 parents 088b034 + fe9517a commit 41a663d

8 files changed

Lines changed: 102 additions & 20 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Use list notation, and following prefixes:
1010
- Bugfix - when fixing any major bug
1111
- Docs - for any improvement to documentation
1212

13+
### Changes
14+
- Fix: issue with no size found text
1315

1416
### 2.12.21
1517
- Bugfix: Added async Task cancellation to fix concurrency crash

Virtusize/Sources/Flutter/VirtusizeFlutter.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,23 @@ public class VirtusizeFlutter: Virtusize {
146146

147147
let serverProduct = sizeRecData.serverProduct
148148
let clientProductImageURL = self.storeProductSet.first(where: {product in product.externalId == serverProduct.externalId})?.imageURL
149-
149+
150150
let bestUserProduct = sizeRecData.sizeComparisonRecommendedSize?.bestUserProduct
151+
let bodyProfileWillFit = sizeRecData.bodyProfileRecommendedSize?.willFit
151152
let recommendationText = serverProduct.getRecommendationText(
152153
VirtusizeRepository.shared.i18nLocalization!,
153154
sizeRecData.sizeComparisonRecommendedSize,
154155
sizeRecData.bodyProfileRecommendedSize?.getSizeName,
155-
VirtusizeI18nLocalization.TrimType.MULTIPLELINES
156+
VirtusizeI18nLocalization.TrimType.MULTIPLELINES,
157+
bodyProfileWillFit
156158
)
157159
flutterHandler?.onSizeRecommendationData(
158160
externalId: serverProduct.externalId,
159161
clientProductImageURL: clientProductImageURL?.absoluteString,
160162
storeProduct: serverProduct,
161163
bestUserProduct: bestUserProduct,
162-
recommendationText: recommendationText
164+
recommendationText: recommendationText,
165+
willFit: bodyProfileWillFit
163166
)
164167
}
165168

Virtusize/Sources/Flutter/VirtusizeFlutterProductEventHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public protocol VirtusizeFlutterProductEventHandler {
3232
clientProductImageURL: String?,
3333
storeProduct: VirtusizeServerProduct,
3434
bestUserProduct: VirtusizeServerProduct?,
35-
recommendationText: String
35+
recommendationText: String,
36+
willFit: Bool?
3637
)
3738
func onLanguageClick(language: VirtusizeLanguage)
3839
func onInPageError(externalId: String)

Virtusize/Sources/Models/VirtusizeI18nLocalization.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,9 @@ public class VirtusizeI18nLocalization {
122122
let willFitResultText = self.willFitResultText ?? Localization.shared.localize("inpage_will_fit_result")
123123
return "\(willFitResultText) %{boldStart}\(bodyProfileRecommendedSizeName)%{boldEnd}"
124124
}
125+
126+
/// Gets the "will not fit" text when body data is provided but no size fits
127+
internal func getWillNotFitResultText() -> String {
128+
return Localization.shared.localize("inpage_will_not_fit_result")
129+
}
125130
}

Virtusize/Sources/Models/VirtusizeServerProduct.swift

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public class VirtusizeServerProduct: Codable {
118118
_ i18nLocalization: VirtusizeI18nLocalization?,
119119
_ sizeComparisonRecommendedSize: SizeComparisonRecommendedSize?,
120120
_ bodyProfileRecommendedSizeName: String?,
121-
_ trimType: VirtusizeI18nLocalization.TrimType = VirtusizeI18nLocalization.TrimType.ONELINE
121+
_ trimType: VirtusizeI18nLocalization.TrimType = VirtusizeI18nLocalization.TrimType.ONELINE,
122+
_ bodyProfileWillFit: Bool? = nil
122123
) -> String {
123124
guard let i18nLocalization = i18nLocalization else {
124125
return Localization.shared.localize("inpage_default_accessory_text")
@@ -128,9 +129,9 @@ public class VirtusizeServerProduct: Codable {
128129
if isAccessory() {
129130
text = accessoryText(i18nLocalization, sizeComparisonRecommendedSize)
130131
} else if self.sizes.count == 1 {
131-
text = oneSizeText(i18nLocalization, sizeComparisonRecommendedSize, bodyProfileRecommendedSizeName)
132+
text = oneSizeText(i18nLocalization, sizeComparisonRecommendedSize, bodyProfileRecommendedSizeName, bodyProfileWillFit)
132133
} else {
133-
text = multiSizeText(i18nLocalization, sizeComparisonRecommendedSize, bodyProfileRecommendedSizeName)
134+
text = multiSizeText(i18nLocalization, sizeComparisonRecommendedSize, bodyProfileRecommendedSizeName, bodyProfileWillFit)
134135
}
135136
return text.trimI18nText(trimType)
136137
}
@@ -148,29 +149,57 @@ public class VirtusizeServerProduct: Codable {
148149
private func oneSizeText(
149150
_ i18nLocalization: VirtusizeI18nLocalization,
150151
_ sizeComparisonRecommendedSize: SizeComparisonRecommendedSize?,
151-
_ bodyProfileRecommendedSizeName: String?
152+
_ bodyProfileRecommendedSizeName: String?,
153+
_ bodyProfileWillFit: Bool?
152154
) -> String {
153-
if bodyProfileRecommendedSizeName != nil {
154-
return i18nLocalization.getOneSizeBodyProfileText()
155-
}
155+
// Check if body data is provided (bodyProfileRecommendedSizeName is not nil means body data was provided)
156+
let hasBodyData = bodyProfileRecommendedSizeName != nil
157+
158+
// For one-size products with body data provided
159+
if hasBodyData {
160+
// If willFit is true and we have a recommended size, show the will fit message
161+
if bodyProfileWillFit == true {
162+
return i18nLocalization.getOneSizeBodyProfileText()
163+
}
164+
// If willFit is false or no recommended size, show "Your size not found"
165+
return i18nLocalization.getWillNotFitResultText()
166+
}
167+
168+
// No body data provided, check for product comparison
156169
if let sizeComparisonRecommendedSize = sizeComparisonRecommendedSize, sizeComparisonRecommendedSize.isValid() {
157170
return i18nLocalization.getOneSizeProductComparisonText(sizeComparisonRecommendedSize)
158171
}
172+
173+
// No data at all, show body data empty message
159174
return i18nLocalization.getBodyDataEmptyText()
160175
}
161176

162177
/// Gets the text for a multi-size product
163178
private func multiSizeText(
164179
_ i18nLocalization: VirtusizeI18nLocalization,
165180
_ sizeComparisonRecommendedSize: SizeComparisonRecommendedSize?,
166-
_ bodyProfileRecommendedSizeName: String?
181+
_ bodyProfileRecommendedSizeName: String?,
182+
_ bodyProfileWillFit: Bool?
167183
) -> String {
168-
if let bodyProfileRecommendedSizeName = bodyProfileRecommendedSizeName {
169-
return i18nLocalization.getMultiSizeBodyProfileText(bodyProfileRecommendedSizeName)
170-
}
184+
// Check if body data is provided
185+
let hasBodyData = bodyProfileRecommendedSizeName != nil
186+
187+
// For multi-size products with body data provided
188+
if hasBodyData {
189+
// If willFit is true and we have a recommended size, show it
190+
if bodyProfileWillFit == true, let bodyProfileRecommendedSizeName = bodyProfileRecommendedSizeName, !bodyProfileRecommendedSizeName.isEmpty {
191+
return i18nLocalization.getMultiSizeBodyProfileText(bodyProfileRecommendedSizeName)
192+
}
193+
// If willFit is false or no recommended size, show "Your size not found"
194+
return i18nLocalization.getWillNotFitResultText()
195+
}
196+
197+
// No body data provided, check for product comparison
171198
if let sizeComparisonRecommendedSizeName = sizeComparisonRecommendedSize?.bestStoreProductSize?.name {
172199
return i18nLocalization.getMultiSizeProductionComparisonText(sizeComparisonRecommendedSizeName)
173200
}
201+
202+
// No data at all, show body data empty message
174203
return i18nLocalization.getBodyDataEmptyText()
175204
}
176205

Virtusize/Tests/VirtusizeServerProductTests.swift

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,44 @@ class VirtusizeServerProductTests: XCTestCase {
179179
oneSizeProduct!.getRecommendationText(
180180
i18nLocalization,
181181
nil,
182-
bodyProfileRecommendedSizeName
182+
bodyProfileRecommendedSizeName,
183+
VirtusizeI18nLocalization.TrimType.ONELINE,
184+
true
183185
).contains(i18nLocalization.oneSizeWillFitResultText!)
184186
)
185187
XCTAssertTrue(
186188
oneSizeProduct!.getRecommendationText(
187189
i18nLocalization,
188190
nil,
189-
bodyProfileRecommendedSizeName
191+
bodyProfileRecommendedSizeName,
192+
VirtusizeI18nLocalization.TrimType.ONELINE,
193+
true
190194
).contains(i18nLocalization.oneSizeWillFitResultText!)
191195
)
192196
}
193197

198+
func testGetRecommendationText_oneSizeProduct_bodyProfileRecommendedSizeNotFit_returnOneSizeBodyProfileText() {
199+
let bodyProfileRecommendedSizeName = "Small"
200+
XCTAssertTrue(
201+
oneSizeProduct!.getRecommendationText(
202+
i18nLocalization,
203+
nil,
204+
bodyProfileRecommendedSizeName,
205+
VirtusizeI18nLocalization.TrimType.ONELINE,
206+
false
207+
).contains(i18nLocalization.willNotFitResultText!)
208+
)
209+
XCTAssertTrue(
210+
oneSizeProduct!.getRecommendationText(
211+
i18nLocalization,
212+
nil,
213+
bodyProfileRecommendedSizeName,
214+
VirtusizeI18nLocalization.TrimType.ONELINE,
215+
false
216+
).contains(i18nLocalization.willNotFitResultText!)
217+
)
218+
}
219+
194220
func testGetRecommendationText_multiSizeProduct_hasSizeComparisonRecommendedSize_returnMultiSizeComparisonText() {
195221
let storeProduct1 = TestFixtures.getStoreProduct(productType: 1, gender: nil)
196222
var sizeComparisonRecommendedSize = SizeComparisonRecommendedSize()
@@ -211,11 +237,27 @@ class VirtusizeServerProductTests: XCTestCase {
211237
storeProduct4!.getRecommendationText(
212238
i18nLocalization,
213239
nil,
214-
bodyProfileRecommendedSizeName
240+
bodyProfileRecommendedSizeName,
241+
VirtusizeI18nLocalization.TrimType.ONELINE,
242+
true
215243
).contains(i18nLocalization.willFitResultText!)
216244
)
217245
}
218246

247+
func testGetRecommendationText_multiSizeProduct_bodyProfileRecommendedSizeNotFit_returnMultiSizeBodyProfileText() {
248+
let storeProduct4 = TestFixtures.getStoreProduct(productType: 4, gender: nil)
249+
let bodyProfileRecommendedSizeName = "S"
250+
XCTAssertTrue(
251+
storeProduct4!.getRecommendationText(
252+
i18nLocalization,
253+
nil,
254+
bodyProfileRecommendedSizeName,
255+
VirtusizeI18nLocalization.TrimType.ONELINE,
256+
false
257+
).contains(i18nLocalization.willNotFitResultText!)
258+
)
259+
}
260+
219261
func testGetRecommendationText_multiSizeProduct_noRecommendedSizes_returnBodyDataEmptyText() {
220262
let storeProduct7 = TestFixtures.getStoreProduct(productType: 7, gender: nil)
221263
XCTAssertEqual(

Virtusize/Tests/i18n_en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"errorTextShort": "Virtusize is not available at the moment.",
2424
"oneSizeText": "There is only size %{value}",
2525
"details": "Details",
26-
"willNotFitResult": "Check how it fits you",
26+
"willNotFitResult": "Your size not found",
2727
"tryItOn": "Try it on",
2828
"accessoriesEmpty": "See what fits inside",
2929
"hasProductAccessoryText": "See the size difference from %{boldStart}your own item%{boldEnd}",

VirtusizeCore/Sources/Resources/Localizations/en.lproj/VirtusizeLocalizable.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"inpage_multi_size_comparison_text" = "The closest size to your item is";
1515
"inpage_body_data_empty_text" = "Find your right size";
1616
"inpage_will_fit_result" = "Your recommended size is";
17-
"inpage_will_not_fit_result" = "Check how it fits you";
17+
"inpage_will_not_fit_result" = "Your size not found";
1818
"inpage_loading_text" = "Analyzing the size";
1919
"inpage_error_long_text" = "Virtusize is not available at the moment.\nPlease enjoy shopping without us.";
2020
"inpage_error_short_text" = "Virtusize is not available at the moment.";

0 commit comments

Comments
 (0)