-
Notifications
You must be signed in to change notification settings - Fork 0
/
GWP tag equal to zero plus staff member plus excluding discount codes.arb
65 lines (51 loc) · 1.96 KB
/
GWP tag equal to zero plus staff member plus excluding discount codes.arb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
STAFF_TAG = "PICKUP STAFF"
STAFF_MESSAGE = "Staff discount"
REJECT_MESSAGE = "Discount codes cannot be redeemed with Staff Discount"
DISCOUNT_APPLIED_FOR = ["Adult","Baby","Books","Bundle","Fragrances","Haircare","Health & Wellness","Home","Makeup","Mattress","Nails","Party","Personal Care","Pod Starter Kit","Skincare","Sports Nutrition","Stationery"]
DISCOUNT_AMOUNT = 0.75 #means 25%
Dicount_applied = false
DISCOUNT_APPLIED_FOR_1 = ["Alcohol","Electronics","Grocery","Toys"]
DISCOUNT_AMOUNT_1 = 0.85 #means 15%
Dicount_applied_1 = false
GWP_TAG = "GWP"
GWP_MESSAGE = "free gift added"
customer = Input.cart.customer
if customer && customer.tags.include?(STAFF_TAG)
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
unless product.tags.include?("rrp sale"||"Sale_Clearance")
DISCOUNT_APPLIED_FOR.each do |target|
Dicount_applied = product.product_type.include?(target)
if Dicount_applied == true
break
end
end
DISCOUNT_APPLIED_FOR_1.each do |target|
Dicount_applied_1 = product.product_type.include?(target)
if Dicount_applied_1 == true
break
end
end
if Dicount_applied
next if product.gift_card?
line_item.change_line_price(line_item.line_price * DISCOUNT_AMOUNT, message: STAFF_MESSAGE)
end
if Dicount_applied_1
next if product.gift_card?
line_item.change_line_price(line_item.line_price * DISCOUNT_AMOUNT_1, message: STAFF_MESSAGE)
end
end
next if product.gift_card?
if Input.cart.discount_code
Input.cart.discount_code.reject(message: REJECT_MESSAGE)
end
end
end
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
if product.tags.include?(GWP_TAG)
next if product.gift_card?
line_item.change_line_price(line_item.line_price * 0, message: GWP_MESSAGE)
end
end
Output.cart = Input.cart