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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Use list notation, and following prefixes:
- Bugfix - when fixing any major bug
- Docs - for any improvement to documentation

### Changes:
- Fix: No size available text instead of max size issue
- Fix: Virtusize widget recommended size incorrect

### 2.12.25
- Fix: Prevent send event userSawProduct when productValid = false or repeated product load

Expand Down
11 changes: 7 additions & 4 deletions Virtusize/Sources/Flutter/VirtusizeFlutter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,30 +140,33 @@ public class VirtusizeFlutter: Virtusize {
}

@objc private static func didReceiveSizeRecommendationData(_ notification: Notification) {

guard let notificationData = notification.userInfo as? [String: Any],
let sizeRecData = notificationData[NotificationKey.sizeRecommendationData] as? Virtusize.SizeRecommendationData else {
let sizeRecData = notificationData[NotificationKey.sizeRecommendationData] as? Virtusize.SizeRecommendationData
else {
return
}

let serverProduct = sizeRecData.serverProduct
let clientProductImageURL = self.storeProductSet.first(where: {product in product.externalId == serverProduct.externalId})?.imageURL
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,
bodyProfileWillFit
bodyProfileWillFit ?? true
)
flutterHandler?.onSizeRecommendationData(
externalId: serverProduct.externalId,
clientProductImageURL: clientProductImageURL?.absoluteString,
storeProduct: serverProduct,
bestUserProduct: bestUserProduct,
recommendationText: recommendationText,
willFit: bodyProfileWillFit
willFit: bodyProfileWillFit ?? true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public protocol VirtusizeFlutterProductEventHandler {
storeProduct: VirtusizeServerProduct,
bestUserProduct: VirtusizeServerProduct?,
recommendationText: String,
willFit: Bool?
willFit: Bool
)
func onLanguageClick(language: VirtusizeLanguage)
func onInPageError(externalId: String)
Expand Down
14 changes: 7 additions & 7 deletions Virtusize/Sources/Models/VirtusizeServerProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public class VirtusizeServerProduct: Codable {
_ sizeComparisonRecommendedSize: SizeComparisonRecommendedSize?,
_ bodyProfileRecommendedSizeName: String?,
_ trimType: VirtusizeI18nLocalization.TrimType = VirtusizeI18nLocalization.TrimType.ONELINE,
_ bodyProfileWillFit: Bool? = nil
_ bodyProfileWillFit: Bool
) -> String {
guard let i18nLocalization = i18nLocalization else {
return Localization.shared.localize("inpage_default_accessory_text")
Expand Down Expand Up @@ -157,11 +157,11 @@ public class VirtusizeServerProduct: Codable {

// 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 != false {
// If willFit is explicitly true, show the will fit message
if bodyProfileWillFit == true {
return i18nLocalization.getOneSizeBodyProfileText()
}
// If willFit is false or no recommended size, show "Your size not found"
// If willFit is false or nil (no willFit from API), show "Your size not found"
return i18nLocalization.getWillNotFitResultText()
}

Expand All @@ -186,15 +186,15 @@ public class VirtusizeServerProduct: Codable {

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

Expand Down
9 changes: 7 additions & 2 deletions Virtusize/Sources/UI/VirtusizeInPageMini.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,17 @@ public class VirtusizeInPageMini: VirtusizeInPageView {
self.sizeComparisonRecommendedSize = sizeRecData.sizeComparisonRecommendedSize
self.bodyProfileRecommendedSize = sizeRecData.bodyProfileRecommendedSize

let bodyProfileWillFit = sizeRecData.bodyProfileRecommendedSize?.willFit

setLoadingScreen(loading: false)
inPageMiniMessageLabel.attributedText = NSAttributedString(
string:
sizeRecData.serverProduct.getRecommendationText(
VirtusizeRepository.shared.i18nLocalization,
sizeComparisonRecommendedSize,
bodyProfileRecommendedSize?.getSizeName,
VirtusizeI18nLocalization.TrimType.ONELINE
VirtusizeI18nLocalization.TrimType.ONELINE,
bodyProfileWillFit ?? true
)
).lineSpacing(self.verticalMargin/2)
}
Expand Down Expand Up @@ -127,13 +130,15 @@ public class VirtusizeInPageMini: VirtusizeInPageView {
inPageMiniMessageLabel.text = Localization.shared.localize("inpage_error_short_text", language: language)
} else {
if let product = serverProduct {
let bodyProfileWillFit = bodyProfileRecommendedSize?.willFit
inPageMiniMessageLabel.attributedText = NSAttributedString(
string:
product.getRecommendationText(
VirtusizeRepository.shared.i18nLocalization!,
sizeComparisonRecommendedSize,
bodyProfileRecommendedSize?.getSizeName,
VirtusizeI18nLocalization.TrimType.ONELINE
VirtusizeI18nLocalization.TrimType.ONELINE,
bodyProfileWillFit ?? true
)
).lineSpacing(self.verticalMargin/2)
}
Expand Down
6 changes: 5 additions & 1 deletion Virtusize/Sources/UI/VirtusizeInPageStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,17 @@ public class VirtusizeInPageStandard: VirtusizeInPageView { // swiftlint:disable
return
}

let bodyProfileWillFit = bodyProfileRecommendedSize?.willFit

let trimType = VirtusizeI18nLocalization.TrimType.MULTIPLELINES
let recommendationText = serverProduct.getRecommendationText(
i18nLocalization,
sizeComparisonRecommendedSize,
bodyProfileRecommendedSize?.getSizeName,
trimType
trimType,
bodyProfileWillFit ?? true
)

let recommendationTextArray = recommendationText.components(separatedBy: trimType.rawValue)
if recommendationTextArray.count == 2 {
self.topMessageLabel.attributedText = NSAttributedString(
Expand Down
7 changes: 7 additions & 0 deletions Virtusize/Sources/UI/VirtusizeViewEventProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ extension VirtusizeViewEventProtocol {
Task {
VirtusizeRepository.shared.updateUserBodyRecommendedSize(recommendedSize)
VirtusizeRepository.shared.updateInPageRecommendation(type: .body)

await VirtusizeRepository.shared.fetchDataForInPageRecommendation(
shouldUpdateUserProducts: false,
shouldUpdateBodyProfile: true
)

VirtusizeRepository.shared.updateInPageRecommendation()
}
}

Expand Down
20 changes: 18 additions & 2 deletions Virtusize/Sources/Virtusize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,26 @@ public class Virtusize {
bodyProfileRecommendedSize: BodyProfileRecommendedSize?
)

/// Lock for thread-safe access to sizeRecData
private static let sizeRecDataLock = NSLock()

/// The backing storage for size recommendation data
private static var _sizeRecData: SizeRecommendationData?

/// The property to be set to updating the size recommendation data for InPage views.
internal static var sizeRecData: SizeRecommendationData? {
didSet {
if let sizeRecData = sizeRecData {
get {
sizeRecDataLock.lock()
defer { sizeRecDataLock.unlock() }
return _sizeRecData
}
set {
sizeRecDataLock.lock()
_sizeRecData = newValue
let value = _sizeRecData
sizeRecDataLock.unlock()

if let sizeRecData = value {
DispatchQueue.main.async {
NotificationCenter.default.post(
name: .sizeRecommendationData,
Expand Down
Loading