##################################
### VARIABLES
##################################
CUSTOMER_IS_EMPLOYEE = false
DISCOUNT_MESSAGE = "Employee 30% Discount"
DISCOUNT_PERCENTAGE = 30
TAG_EXCLUDE_PRODUCT = "ed-exclude"
TARGET_DOMAIN = 'companydomain.com'
customer = Input.cart.customer
##################################
### EMPLOYEE DISCOUNT
### If the current customer email contains target domain
### as an employee, apply a discount
### to items that aren't tagged
### to be excluded from discounts.
##################################
# customer is not empty and email contains target domain
if customer and customer.email.include?(TARGET_DOMAIN)
CUSTOMER_IS_EMPLOYEE = true
end
if CUSTOMER_IS_EMPLOYEE
Input.cart.line_items.each do |line_item| # Loop over each cart item
product = line_item.variant.product # Access the actual product object
next if product.tags.include? TAG_EXCLUDE_PRODUCT # If the product contains our excluded tag, skip the current line item.
DISCOUNT = ((100 - DISCOUNT_PERCENTAGE) / 100)
line_item.change_line_price(line_item.line_price * DISCOUNT, message: DISCOUNT_MESSAGE) #Apply the overall discount to the line-item.
end
end
##################################
### OUTPUT
##################################
Output.cart = Input.cart
##################################
### VARIABLES
##################################
CUSTOMER_IS_EMPLOYEE = false
DISCOUNT_MESSAGE = "Employee 30% Discount"
DISCOUNT_PERCENTAGE = 30
TAG_EXCLUDE_PRODUCT = "ed-exclude"
TARGET_DOMAIN = 'companydomain.com'
customer = Input.cart.customer
##################################
### EMPLOYEE DISCOUNT
### If the current customer email contains target domain
### as an employee, apply a discount
### to items that aren't tagged
### to be excluded from discounts.
##################################
# customer is not empty and email contains target domain
if customer and customer.email.include?(TARGET_DOMAIN)
CUSTOMER_IS_EMPLOYEE = true
end
# is employee and has not use discount code
if CUSTOMER_IS_EMPLOYEE and Input.cart.discount_code == nil
Input.cart.line_items.each do |line_item| # Loop over each cart item
product = line_item.variant.product # Access the actual product object
next if product.tags.include? TAG_EXCLUDE_PRODUCT # If the product contains our excluded tag, skip the current line item.
DISCOUNT = ((100 - DISCOUNT_PERCENTAGE) / 100)
line_item.change_line_price(line_item.line_price * DISCOUNT, message: DISCOUNT_MESSAGE) #Apply the overall discount to the line-item.
end
end
##################################
### OUTPUT
##################################
Output.cart = Input.cart