Free Swatch Books Discount
Overviewโ
Provides up to $4 in free swatch books (Suits swatches) for eligible customers during checkout.
Eligibilityโ
Customers WITHOUT the "swatch-book-buyer" tag
This means:
- First-time customers automatically qualify
- Guest customers automatically qualify
- Once a customer purchases swatch books, they receive the
"swatch-book-buyer"tag and no longer qualify
Discount Detailsโ
- Maximum Discount: $4
- Swatch Book Price: $2 each
- Maximum Free Swatch Books: 2 books
How It Worksโ
Normal Case (โค2 books)โ
- All swatch books are free
- Total discount โค $4
Edge Case (>2 books)โ
- Discount is capped at $4
- Customer pays for additional books
- Example: 5 books = $4 discount + $6 charge = $6 total
Product Taggingโ
Products must be tagged with "Swatch Book" to qualify for this discount.
Discount Messageโ
Customers see: "Free Suits Swatches"
Technical Implementationโ
Logic Flowโ
# Tracks cumulative discount across all swatch book line items
cumulative_swatch_book_discount = 0
Input.cart.line_items.each do |line_item|
if line_item.variant.product.tags.include?("Swatch Book")
quantity = line_item.quantity
discount = [quantity * 2, 4 - cumulative_swatch_book_discount].min
if discount > 0
apply_swatch_discount(line_item, quantity, discount, "Free Suits Swatches")
cumulative_swatch_book_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 Book Limit
Current limit: $4 (appears in script lines 41, 45, 49, 52)
To change, update all instances throughout the free swatch book section.
Guest Handlingโ
โ
Guests qualify for free swatch books since they don't have the "swatch-book-buyer" tag.