Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Use list notation, and following prefixes:
- Bugfix - when fixing any major bug
- Docs - for any improvement to documentation

### Changes
- Fix: issue with no size found text

### 2.12.21
- Bugfix: Added async Task cancellation to fix concurrency crash
Expand Down
9 changes: 6 additions & 3 deletions Virtusize/Sources/Flutter/VirtusizeFlutter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,23 @@ public class VirtusizeFlutter: Virtusize {

let serverProduct = sizeRecData.serverProduct
let clientProductImageURL = self.storeProductSet.first(where: {product in product.externalId == serverProduct.externalId})?.imageURL

let bestUserProduct = sizeRecData.sizeComparisonRecommendedSize?.bestUserProduct
let bodyProfileWillFit = sizeRecData.bodyProfileRecommendedSize?.willFit
let recommendationText = serverProduct.getRecommendationText(
VirtusizeRepository.shared.i18nLocalization!,
sizeRecData.sizeComparisonRecommendedSize,
sizeRecData.bodyProfileRecommendedSize?.getSizeName,
VirtusizeI18nLocalization.TrimType.MULTIPLELINES
VirtusizeI18nLocalization.TrimType.MULTIPLELINES,
bodyProfileWillFit
)
flutterHandler?.onSizeRecommendationData(
externalId: serverProduct.externalId,
clientProductImageURL: clientProductImageURL?.absoluteString,
storeProduct: serverProduct,
bestUserProduct: bestUserProduct,
recommendationText: recommendationText
recommendationText: recommendationText,
willFit: bodyProfileWillFit
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public protocol VirtusizeFlutterProductEventHandler {
clientProductImageURL: String?,
storeProduct: VirtusizeServerProduct,
bestUserProduct: VirtusizeServerProduct?,
recommendationText: String
recommendationText: String,
willFit: Bool?
)
func onLanguageClick(language: VirtusizeLanguage)
func onInPageError(externalId: String)
Expand Down
5 changes: 5 additions & 0 deletions Virtusize/Sources/Models/VirtusizeI18nLocalization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ public class VirtusizeI18nLocalization {
let willFitResultText = self.willFitResultText ?? Localization.shared.localize("inpage_will_fit_result")
return "\(willFitResultText) %{boldStart}\(bodyProfileRecommendedSizeName)%{boldEnd}"
}

/// Gets the "will not fit" text when body data is provided but no size fits
internal func getWillNotFitResultText() -> String {
return Localization.shared.localize("inpage_will_not_fit_result")
}
}
51 changes: 40 additions & 11 deletions Virtusize/Sources/Models/VirtusizeServerProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public class VirtusizeServerProduct: Codable {
_ i18nLocalization: VirtusizeI18nLocalization?,
_ sizeComparisonRecommendedSize: SizeComparisonRecommendedSize?,
_ bodyProfileRecommendedSizeName: String?,
_ trimType: VirtusizeI18nLocalization.TrimType = VirtusizeI18nLocalization.TrimType.ONELINE
_ trimType: VirtusizeI18nLocalization.TrimType = VirtusizeI18nLocalization.TrimType.ONELINE,
_ bodyProfileWillFit: Bool? = nil
) -> String {
guard let i18nLocalization = i18nLocalization else {
return Localization.shared.localize("inpage_default_accessory_text")
Expand All @@ -128,9 +129,9 @@ public class VirtusizeServerProduct: Codable {
if isAccessory() {
text = accessoryText(i18nLocalization, sizeComparisonRecommendedSize)
} else if self.sizes.count == 1 {
text = oneSizeText(i18nLocalization, sizeComparisonRecommendedSize, bodyProfileRecommendedSizeName)
text = oneSizeText(i18nLocalization, sizeComparisonRecommendedSize, bodyProfileRecommendedSizeName, bodyProfileWillFit)
} else {
text = multiSizeText(i18nLocalization, sizeComparisonRecommendedSize, bodyProfileRecommendedSizeName)
text = multiSizeText(i18nLocalization, sizeComparisonRecommendedSize, bodyProfileRecommendedSizeName, bodyProfileWillFit)
}
return text.trimI18nText(trimType)
}
Expand All @@ -148,29 +149,57 @@ public class VirtusizeServerProduct: Codable {
private func oneSizeText(
_ i18nLocalization: VirtusizeI18nLocalization,
_ sizeComparisonRecommendedSize: SizeComparisonRecommendedSize?,
_ bodyProfileRecommendedSizeName: String?
_ bodyProfileRecommendedSizeName: String?,
_ bodyProfileWillFit: Bool?
) -> String {
if bodyProfileRecommendedSizeName != nil {
return i18nLocalization.getOneSizeBodyProfileText()
}
// Check if body data is provided (bodyProfileRecommendedSizeName is not nil means body data was provided)
let hasBodyData = bodyProfileRecommendedSizeName != nil

// For one-size products with body data provided
if hasBodyData {
// If willFit is true and we have a recommended size, show the will fit message
if bodyProfileWillFit == true {
return i18nLocalization.getOneSizeBodyProfileText()
}
// If willFit is false or no recommended size, show "Your size not found"
return i18nLocalization.getWillNotFitResultText()
}

// No body data provided, check for product comparison
if let sizeComparisonRecommendedSize = sizeComparisonRecommendedSize, sizeComparisonRecommendedSize.isValid() {
return i18nLocalization.getOneSizeProductComparisonText(sizeComparisonRecommendedSize)
}

// No data at all, show body data empty message
return i18nLocalization.getBodyDataEmptyText()
}

/// Gets the text for a multi-size product
private func multiSizeText(
_ i18nLocalization: VirtusizeI18nLocalization,
_ sizeComparisonRecommendedSize: SizeComparisonRecommendedSize?,
_ bodyProfileRecommendedSizeName: String?
_ bodyProfileRecommendedSizeName: String?,
_ bodyProfileWillFit: Bool?
) -> String {
if let bodyProfileRecommendedSizeName = bodyProfileRecommendedSizeName {
return i18nLocalization.getMultiSizeBodyProfileText(bodyProfileRecommendedSizeName)
}
// Check if body data is provided
let hasBodyData = bodyProfileRecommendedSizeName != nil

// For multi-size products with body data provided
if hasBodyData {
// If willFit is true and we have a recommended size, show it
if bodyProfileWillFit == true, let bodyProfileRecommendedSizeName = bodyProfileRecommendedSizeName, !bodyProfileRecommendedSizeName.isEmpty {
return i18nLocalization.getMultiSizeBodyProfileText(bodyProfileRecommendedSizeName)
}
// If willFit is false or no recommended size, show "Your size not found"
return i18nLocalization.getWillNotFitResultText()
}

// No body data provided, check for product comparison
if let sizeComparisonRecommendedSizeName = sizeComparisonRecommendedSize?.bestStoreProductSize?.name {
return i18nLocalization.getMultiSizeProductionComparisonText(sizeComparisonRecommendedSizeName)
}

// No data at all, show body data empty message
return i18nLocalization.getBodyDataEmptyText()
}

Expand Down
48 changes: 45 additions & 3 deletions Virtusize/Tests/VirtusizeServerProductTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,44 @@ class VirtusizeServerProductTests: XCTestCase {
oneSizeProduct!.getRecommendationText(
i18nLocalization,
nil,
bodyProfileRecommendedSizeName
bodyProfileRecommendedSizeName,
VirtusizeI18nLocalization.TrimType.ONELINE,
true
).contains(i18nLocalization.oneSizeWillFitResultText!)
)
XCTAssertTrue(
oneSizeProduct!.getRecommendationText(
i18nLocalization,
nil,
bodyProfileRecommendedSizeName
bodyProfileRecommendedSizeName,
VirtusizeI18nLocalization.TrimType.ONELINE,
true
).contains(i18nLocalization.oneSizeWillFitResultText!)
)
}

func testGetRecommendationText_oneSizeProduct_bodyProfileRecommendedSizeNotFit_returnOneSizeBodyProfileText() {
let bodyProfileRecommendedSizeName = "Small"
XCTAssertTrue(
oneSizeProduct!.getRecommendationText(
i18nLocalization,
nil,
bodyProfileRecommendedSizeName,
VirtusizeI18nLocalization.TrimType.ONELINE,
false
).contains(i18nLocalization.willNotFitResultText!)
)
XCTAssertTrue(
oneSizeProduct!.getRecommendationText(
i18nLocalization,
nil,
bodyProfileRecommendedSizeName,
VirtusizeI18nLocalization.TrimType.ONELINE,
false
).contains(i18nLocalization.willNotFitResultText!)
)
}

func testGetRecommendationText_multiSizeProduct_hasSizeComparisonRecommendedSize_returnMultiSizeComparisonText() {
let storeProduct1 = TestFixtures.getStoreProduct(productType: 1, gender: nil)
var sizeComparisonRecommendedSize = SizeComparisonRecommendedSize()
Expand All @@ -211,11 +237,27 @@ class VirtusizeServerProductTests: XCTestCase {
storeProduct4!.getRecommendationText(
i18nLocalization,
nil,
bodyProfileRecommendedSizeName
bodyProfileRecommendedSizeName,
VirtusizeI18nLocalization.TrimType.ONELINE,
true
).contains(i18nLocalization.willFitResultText!)
)
}

func testGetRecommendationText_multiSizeProduct_bodyProfileRecommendedSizeNotFit_returnMultiSizeBodyProfileText() {
let storeProduct4 = TestFixtures.getStoreProduct(productType: 4, gender: nil)
let bodyProfileRecommendedSizeName = "S"
XCTAssertTrue(
storeProduct4!.getRecommendationText(
i18nLocalization,
nil,
bodyProfileRecommendedSizeName,
VirtusizeI18nLocalization.TrimType.ONELINE,
false
).contains(i18nLocalization.willNotFitResultText!)
)
}

func testGetRecommendationText_multiSizeProduct_noRecommendedSizes_returnBodyDataEmptyText() {
let storeProduct7 = TestFixtures.getStoreProduct(productType: 7, gender: nil)
XCTAssertEqual(
Expand Down
2 changes: 1 addition & 1 deletion Virtusize/Tests/i18n_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"errorTextShort": "Virtusize is not available at the moment.",
"oneSizeText": "There is only size %{value}",
"details": "Details",
"willNotFitResult": "Check how it fits you",
"willNotFitResult": "Your size not found",
"tryItOn": "Try it on",
"accessoriesEmpty": "See what fits inside",
"hasProductAccessoryText": "See the size difference from %{boldStart}your own item%{boldEnd}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"inpage_multi_size_comparison_text" = "The closest size to your item is";
"inpage_body_data_empty_text" = "Find your right size";
"inpage_will_fit_result" = "Your recommended size is";
"inpage_will_not_fit_result" = "Check how it fits you";
"inpage_will_not_fit_result" = "Your size not found";
"inpage_loading_text" = "Analyzing the size";
"inpage_error_long_text" = "Virtusize is not available at the moment.\nPlease enjoy shopping without us.";
"inpage_error_short_text" = "Virtusize is not available at the moment.";
Loading