Skip to main content

Free Swatches Discount

Overviewโ€‹

Provides up to $12 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: $12
  • Swatch Price: $2 each
  • Maximum Free Swatches: 6 swatches

How It Worksโ€‹

Normal Case (โ‰ค6 swatches)โ€‹

  • All swatches are free
  • Total discount โ‰ค $12

Edge Case (>6 swatches)โ€‹

  • Discount is capped at $12
  • Customer pays for additional swatches
  • Example: 15 swatches = $12 discount + $18 charge = $18 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, 12 - 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: $12 (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.