Free Swatches Discount
Overviewโ
Provides up to $20 in free swatches for eligible customers during checkout.
Eligibilityโ
Customers WITHOUT the "swatch-buyer" tag
This means:
- First-time customers automatically qualify
- Guest customers automatically qualify
- Once a customer purchases swatches, they receive the
"swatch-buyer"tag and no longer qualify
Discount Detailsโ
- Maximum Discount: $20
- Swatch Price: $2 each
- Maximum Free Swatches: 10 swatches
How It Worksโ
Normal Case (โค10 swatches)โ
- All swatches are free
- Total discount โค $20
Edge Case (>10 swatches)โ
- Discount is capped at $20
- Customer pays for additional swatches
- Example: 15 swatches = $20 discount + $10 charge = $10 total
Product Taggingโ
Products must be tagged with "Swatch" to qualify for this discount.
Discount Messageโ
Customers see: "Free Swatches"
Technical Implementationโ
Logic Flowโ
# Tracks cumulative discount across all swatch line items
cumulative_swatch_discount = 0
Input.cart.line_items.each do |line_item|
if line_item.variant.product.tags.include?("Swatch")
quantity = line_item.quantity
discount = [quantity * 2, 20 - cumulative_swatch_discount].min
if discount > 0
apply_swatch_discount(line_item, quantity, discount, "Free Swatches")
cumulative_swatch_discount += discount
end
end
end
Helper Methodโ
def apply_swatch_discount(line_item, quantity, discount, message)
original_line_price = line_item.line_price
new_line_price = original_line_price - (Money.new(cents: discount * 100))
line_item.change_line_price(new_line_price, message: message)
end
Configurationโ
Adjusting the Free Swatch Limit
Current limit: $20 (appears in script lines 23, 27, 31, 34)
To change, update all instances throughout the free swatch section.
Guest Handlingโ
โ
Guests qualify for free swatches since they don't have the "swatch-buyer" tag.