Skip to content
Open
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
31 changes: 31 additions & 0 deletions ios/RNMParticle/RNMParticle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,37 @@ - (void)logCommerceEvent:(JS::NativeMParticle::CommerceEvent &)commerceEvent {
}
[mpCommerceEvent addProducts:productsArray];
}

if (commerceEvent.impressions().has_value()) {
auto impressionsVector = commerceEvent.impressions().value();
for (size_t j = 0; j < impressionsVector.size(); j++) {
auto impressionStruct = impressionsVector[j];
NSString *listName = impressionStruct.impressionListName();
if (!listName) {
continue;
}
auto productsInImpression = impressionStruct.products();
for (size_t k = 0; k < productsInImpression.size(); k++) {
auto productStruct = productsInImpression[k];
NSMutableDictionary *productDict = [[NSMutableDictionary alloc] init];
if (productStruct.name()) productDict[@"name"] = productStruct.name();
if (productStruct.sku()) productDict[@"sku"] = productStruct.sku();
productDict[@"price"] = @(productStruct.price());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason price doesn't have a conditional whereas all the others do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmi22186 - I pretty much copied the same logic on for commerceEvent.products().has_value() in line 513, I can add the if statement for both to be on the safer side

if (productStruct.quantity().has_value()) productDict[@"quantity"] = @(productStruct.quantity().value());
if (productStruct.brand()) productDict[@"brand"] = productStruct.brand();
if (productStruct.couponCode()) productDict[@"couponCode"] = productStruct.couponCode();
if (productStruct.position().has_value()) productDict[@"position"] = @(productStruct.position().value());
if (productStruct.category()) productDict[@"category"] = productStruct.category();
if (productStruct.variant()) productDict[@"variant"] = productStruct.variant();
if (productStruct.customAttributes()) productDict[@"customAttributes"] = productStruct.customAttributes();

MPProduct *product = [self createMPProductFromDict:productDict];
if (product) {
[mpCommerceEvent addImpression:product listName:listName];
}
}
}
}

if (commerceEvent.transactionAttributes().has_value()) {
// Create transaction attributes from the struct
Expand Down
Loading