Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MBL-1601] Filter Rewards By Selected Shipping Location #2114

Merged
merged 7 commits into from
Aug 12, 2024

Conversation

scottkicks
Copy link
Contributor

@scottkicks scottkicks commented Aug 6, 2024

📲 What

Filters the displayed rewards based on the selected shipping location.

🤔 Why

We only want users to select rewards that they can actually get.

🛠 How

The shipping dropdown is already on this screen. We need to filter based on the currently selected location.
The types of rewards are:

  • No-reward/Digital only
  • Local Pickup only
  • Ships anywhere in the world:
  • Ships to selected countries

Right now, we pull in a project's rewards using this GraphQL Query FetchProjectRewardsById.
This returns all rewards for a project and has an option to includeShippingRules.
Flipping this to true allows us to compare individual reward shipping info to the selected location and filter accordingly.

👀 See

I created a test project, A Really Cool Proj, that has the following reward types.

  1. No Reward: Should always show
  2. Digital: Should always show
  3. Local: Only show if the selected country matches the pickup country (United States)
  4. Ships to select countries: Shows if the selected country is United States, Aruba, or Antarctica
  5. Ships anywhere: Should always show

Simulator Screen Recording - iPhone 15 Pro Max - 2024-08-06 at 15 05 46

✅ Acceptance criteria

  • When there are only digital rewards, only the no-reward and digital-only rewards are shown, and no shipping location dropdown is shown.
  • Rewards that ship anywhere are always shown if enabled.
  • When the selected country matches the local pickup reward's country, or a country in a restricted rewards shipping location list, those rewards + the no reward/digital rewards are shown

@scottkicks scottkicks force-pushed the scott/filter-rewards-by-shipping-location branch from 02bf3a3 to 553126a Compare August 6, 2024 16:41
@@ -549,7 +549,7 @@ public struct Service: ServiceType {
let query = GraphAPI
.FetchProjectRewardsByIdQuery(
projectId: projectId,
includeShippingRules: false,
includeShippingRules: true,
Copy link
Contributor Author

@scottkicks scottkicks Aug 6, 2024

Choose a reason for hiding this comment

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

Tested around the app and made sure tests passed to make sure this didn't impact anything unexpectedly. All this does is include shipping rule/location data in each reward for a project.

In theory, this might slow down project load time. I haven't seen a notable difference, but I will keep an eye on it.

Comment on lines +445 to +476
private func filteredRewardsByLocation(
_ rewards: [Reward],
shippingRule: ShippingRule?
) -> [Reward] {
return rewards.filter { reward in
var shouldDisplayReward = false

let isRewardLocalOrDigital = isRewardDigital(reward) || isRewardLocalPickup(reward)
let isUnrestrictedShippingReward = reward.isUnRestrictedShippingPreference
let isRestrictedShippingReward = reward.isRestrictedShippingPreference

// return all rewards that are digital or ship anywhere in the world.
if isRewardLocalOrDigital || isUnrestrictedShippingReward {
shouldDisplayReward = true

// if add on is local pickup, ensure locations are equal.
if isRewardLocalPickup(reward) {
if let rewardLocation = reward.localPickup?.country,
let shippingRuleLocation = shippingRule?.location.country, rewardLocation == shippingRuleLocation {
shouldDisplayReward = true
} else {
shouldDisplayReward = false
}
}
// If restricted shipping, compare against selected shipping location.
} else if isRestrictedShippingReward {
shouldDisplayReward = rewardShipsTo(selectedLocation: shippingRule?.location.id, reward)
}

return shouldDisplayReward
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is mostly from the existing AddOns screen filtering logic with minor adjustments.

If there are any suggestions for simplifying or making this easier to understand, please suggest them!

@scottkicks scottkicks marked this pull request as ready for review August 7, 2024 16:12
@scottkicks scottkicks merged commit 6a3b3f5 into main Aug 12, 2024
5 checks passed
@scottkicks scottkicks deleted the scott/filter-rewards-by-shipping-location branch August 12, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants