Skip to content

Commit fb7a0fa

Browse files
authored
add product name field to combined discounts (#2208)
* add product name field to combined discounts
1 parent 2f8e760 commit fb7a0fa

2 files changed

Lines changed: 51 additions & 23 deletions

File tree

src/ol_dbt/models/marts/combined/_marts__combined__models.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,8 @@ models:
984984
description: string, the product identifier either referring to courserun_readable_id,
985985
programrun_readable_id, or program_readable_id. Examples include course-v1:MITxPRO+TPMx_Mondelez+SPOC_R1
986986
and program-v1:xPRO+SysEngx.
987+
- name: product_name
988+
description: string, the product name either referring to courserun_title or program_title
987989
- name: discount_amount_text
988990
description: string, either dollar amount off, fixed price, or percentage discount.
989991
- name: company_name

src/ol_dbt/models/marts/combined/marts__combined_discounts.sql

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ with mitxonline_discount as (
1818
select * from {{ ref('marts__mitxpro_all_coupons') }}
1919
)
2020

21+
, combined_products as (
22+
select * from {{ ref('marts__combined__products') }}
23+
)
24+
25+
, mitxpro_programs as (
26+
select * from {{ ref('int__mitxpro__programs') }}
27+
)
28+
29+
, mitxpro_courserun as (
30+
select * from {{ ref('stg__mitxpro__app__postgres__courses_courserun') }}
31+
)
32+
2133
, mitxonline_order_sum as (
2234
select
2335
discount_code
@@ -45,7 +57,7 @@ with mitxonline_discount as (
4557
)
4658

4759
select
48-
'MITx Online' as platform
60+
'{{ var("mitxonline") }}' as platform
4961
, mitxonline_discount.discount_code
5062
, null as discount_name
5163
, mitxonline_discount.discount_created_on
@@ -61,6 +73,7 @@ select
6173
, coalesce(case when mitxonline_order_sum.discount_code is not null then true end, false) as redeemed
6274
, mitxonline_order_sum.coupons_used_count as discounts_used_count
6375
, mitxonline_product_joins.product_readable_id
76+
, combined_products.product_name
6477
, case
6578
when discount_type = 'percent-off'
6679
then concat(format('%.2f', mitxonline_discount.discount_amount), '%')
@@ -79,30 +92,43 @@ left join mitxonline_product_joins
7992
on mitxonline_discount.discount_id = mitxonline_product_joins.discount_id
8093
left join mitxonline_order_sum
8194
on mitxonline_discount.discount_code = mitxonline_order_sum.discount_code
95+
left join combined_products
96+
on mitxonline_product_joins.product_readable_id = combined_products.product_readable_id
97+
and combined_products.platform = '{{ var("mitxonline") }}'
8298

8399
union all
84100

85101
select
86-
'xPro' as platform
87-
, coupon_code as discount_code
88-
, coupon_name as discount_name
89-
, coupon_created_on as discount_created_on
90-
, payment_transaction
91-
, case when coupon_id is null then 'b2b' else discount_source end as discount_source
92-
, activated_on as discount_activated_on
93-
, expires_on as discount_expires_on
94-
, couponpaymentversion_num_coupon_codes as num_discount_codes
95-
, couponpaymentversion_max_redemptions as discount_max_redemptions
96-
, couponpayment_name
97-
, b2border_contract_number as b2b_contract_number
98-
, b2breceipt_reference_number
99-
, redeemed
100-
, coupons_used_count as discounts_used_count
101-
, product_readable_id
102-
, discount_amount as discount_amount_text
103-
, company_name
104-
, coupon_type as discount_type
105-
, b2bcoupon_id
106-
, coupon_id as discount_id
107-
, couponpaymentversion_id
102+
'{{ var("mitxpro") }}' as platform
103+
, mitxpro_all_coupons.coupon_code as discount_code
104+
, mitxpro_all_coupons.coupon_name as discount_name
105+
, mitxpro_all_coupons.coupon_created_on as discount_created_on
106+
, mitxpro_all_coupons.payment_transaction
107+
, case when mitxpro_all_coupons.coupon_id is null then 'b2b' else mitxpro_all_coupons.discount_source
108+
end as discount_source
109+
, mitxpro_all_coupons.activated_on as discount_activated_on
110+
, mitxpro_all_coupons.expires_on as discount_expires_on
111+
, mitxpro_all_coupons.couponpaymentversion_num_coupon_codes as num_discount_codes
112+
, mitxpro_all_coupons.couponpaymentversion_max_redemptions as discount_max_redemptions
113+
, mitxpro_all_coupons.couponpayment_name
114+
, mitxpro_all_coupons.b2border_contract_number as b2b_contract_number
115+
, mitxpro_all_coupons.b2breceipt_reference_number
116+
, mitxpro_all_coupons.redeemed
117+
, mitxpro_all_coupons.coupons_used_count as discounts_used_count
118+
, mitxpro_all_coupons.product_readable_id
119+
, coalesce(combined_products.product_name, mitxpro_programs.program_title, mitxpro_courserun.courserun_title)
120+
as product_name
121+
, mitxpro_all_coupons.discount_amount as discount_amount_text
122+
, mitxpro_all_coupons.company_name
123+
, mitxpro_all_coupons.coupon_type as discount_type
124+
, mitxpro_all_coupons.b2bcoupon_id
125+
, mitxpro_all_coupons.coupon_id as discount_id
126+
, mitxpro_all_coupons.couponpaymentversion_id
108127
from mitxpro_all_coupons
128+
left join combined_products
129+
on mitxpro_all_coupons.product_readable_id = combined_products.product_readable_id
130+
and combined_products.platform = '{{ var("mitxpro") }}'
131+
left join mitxpro_programs
132+
on mitxpro_all_coupons.product_readable_id = mitxpro_programs.program_readable_id
133+
left join mitxpro_courserun
134+
on mitxpro_all_coupons.product_readable_id = mitxpro_courserun.courserun_readable_id

0 commit comments

Comments
 (0)