Build a finder class for querying the Zuora Product Catalog
Proposal
Once #3486 is complete and the necessary custom fields have been added to the Zuora Product Catalog, a finder class can be built in CustomersDot to facilitate querying the Product Catalog. You can find details about the proposed idea for this finder class in &6579 (closed).
For this issue, let's focus on building an MVC. We'd like to have a proof-of-concept in order to run some performance tests. If it turns out this approach is not feasible because of performance concerns, it would be best to know this earlier rather than later.
Example
In the Plan
model, Plan::PREMIUM_SM_1_YEAR_PLAN
is defined as a constant and pulls the Product Rate Plan id for this "plan" from the associated key defined in application.yml
. Instead, we could use the finder class (something like ProductPlanFinder
, name TBD) to filter ProductRatePlans
(and other Zuora product objects) and find this object.
ProductPlanFinder
.where(product: { plan_tier: 'premium' })
.where(product: { platform_type: 'self_managed' })
.where(product_rate_plan_charge: { billing_period_months: 12 })
.first
In this example, the keys from the where
method params would map to the fields available (notably custom fields) on the Zuora Product object. Given this is a bit wordy, we could build on this by creating some convenient scope-like methods for these common where
methods.
def premium
where(product: { plan_tier: 'premium' })
end
That would enable us to distill the earlier statement to something like: ProductPlanFinder.premium.sm.annual
.
Naming of the Finder class
A PlansFinder
class already exists in CustomersDot, which will impact the name of this new class being proposed. The existing finder class relies heavily on finding plans from the eager loaded set of plans. This class will be altered as part of #2680 (closed) which will remove eager loading.