@@ -20,9 +20,10 @@ - (void)setUserId:(NSNumber *)userId;
2020@end
2121
2222// Forward declare so New Arch `logCommerceEvent` can use the same JS→native
23- // product action mapping as `RCTConvert MPCommerceEvent: ` (defined later in this file).
23+ // mappings as `RCTConvert ( MPCommerceEvent) ` (defined later in this file).
2424@interface RCTConvert (MPCommerceEvent)
2525+ (MPCommerceEventAction)MPCommerceEventAction : (id )json ;
26+ + (MPPromotionAction)MPPromotionAction : (id )json ;
2627@end
2728
2829@implementation RNMParticle
@@ -457,7 +458,10 @@ - (void)logCommerceEvent:(JS::NativeMParticle::CommerceEvent &)commerceEvent {
457458 }
458459
459460 if (commerceEvent.promotionActionType ().has_value ()) {
460- mpCommerceEvent.promotionContainer = [[MPPromotionContainer alloc ] initWithAction: (MPPromotionAction)commerceEvent.promotionActionType ().value () promotion: nil ];
461+ MPPromotionAction promotionAction =
462+ [RCTConvert MPPromotionAction: @(commerceEvent.promotionActionType ().value ())];
463+ mpCommerceEvent.promotionContainer =
464+ [[MPPromotionContainer alloc ] initWithAction: promotionAction promotion: nil ];
461465 }
462466
463467 if (commerceEvent.products ().has_value ()) {
@@ -926,6 +930,7 @@ + (MPPromotion *)MPPromotion:(id)json;
926930+ (MPTransactionAttributes *)MPTransactionAttributes : (id )json ;
927931+ (MPProduct *)MPProduct : (id )json ;
928932+ (MPCommerceEventAction)MPCommerceEventAction : (id )json ;
933+ + (MPPromotionAction)MPPromotionAction : (id )json ;
929934+ (MPIdentityApiRequest *)MPIdentityApiRequest : (id )json ;
930935+ (MPIdentityApiResult *)MPIdentityApiResult : (id )json ;
931936+ (MPAliasRequest *)MPAliasRequest : (id )json ;
@@ -995,7 +1000,7 @@ + (MPCommerceEvent *)MPCommerceEvent:(id)json {
9951000}
9961001
9971002+ (MPPromotionContainer *)MPPromotionContainer : (id )json {
998- MPPromotionAction promotionAction = (MPPromotionAction)[ json[@" promotionActionType" ] intValue ];
1003+ MPPromotionAction promotionAction = [RCTConvert MPPromotionAction: json[@" promotionActionType" ]];
9991004 MPPromotionContainer *promotionContainer = [[MPPromotionContainer alloc ] initWithAction: promotionAction promotion: nil ];
10001005 NSArray *jsonPromotions = json[@" promotions" ];
10011006 [jsonPromotions enumerateObjectsUsingBlock: ^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
@@ -1045,6 +1050,20 @@ + (MPProduct *)MPProduct:(id)json {
10451050 return product;
10461051}
10471052
1053+ + (MPPromotionAction)MPPromotionAction : (NSNumber *)json {
1054+ // JS `PromotionActionType`: View = 0, Click = 1 (js/index.tsx).
1055+ // Apple `MPPromotionAction`: Click = 0, View = 1 (MPPromotion.h).
1056+ switch ([json intValue ]) {
1057+ case 0 :
1058+ return MPPromotionActionView;
1059+ case 1 :
1060+ return MPPromotionActionClick;
1061+ default :
1062+ // Match Android `convertPromotionActionType`: non-zero → Click
1063+ return MPPromotionActionClick;
1064+ }
1065+ }
1066+
10481067+ (MPCommerceEventAction)MPCommerceEventAction : (NSNumber *)json {
10491068 int actionInt = [json intValue ];
10501069 MPCommerceEventAction action;
0 commit comments