This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PAID_ITEM_COUNT = 2 | |
| DISCOUNTED_ITEM_COUNT = 1 | |
| # Returns the integer amount of items that must be discounted next | |
| # given the amount of items seen | |
| # | |
| def discounted_items_to_find(total_items_seen, discounted_items_seen) | |
| Integer(total_items_seen / (PAID_ITEM_COUNT + DISCOUNTED_ITEM_COUNT) * DISCOUNTED_ITEM_COUNT) - discounted_items_seen | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DISCOUNTS_BY_QUANTITY = { | |
| 10_000 => 20, | |
| 1_000 => 15, | |
| 100 => 10, | |
| 10 => 5, | |
| } | |
| Input.cart.line_items.each do |line_item| | |
| next if line_item.variant.product.gift_card? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DISCOUNTS_BY_QUANTITY = { | |
| 10_000 => 20, | |
| 1_000 => 15, | |
| 100 => 10, | |
| 10 => 5, | |
| } | |
| Input.cart.line_items.each do |line_item| | |
| next if line_item.variant.product.gift_card? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @percent = Decimal.new(25) / 100.0 | |
| Input.cart.line_items.each do |line_item| | |
| product = line_item.variant.product | |
| next if product.gift_card? | |
| next unless product.tags.include?('myTag') | |
| line_discount = line_item.line_price * @percent | |
| line_item.change_line_price(line_item.line_price - line_discount, message: "25% Off") | |
| end | |
| Output.cart = Input.cart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Input.cart.line_items.each do |line_item| | |
| product = line_item.variant.product | |
| next if product.gift_card? | |
| next unless product.tags.include?('MyTag') | |
| line_item.change_line_price(line_item.line_price - Money.new(cents: 500), message: "$5 Off") | |
| end | |
| Output.cart = Input.cart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PAID_ITEM_COUNT = 1 | |
| DISCOUNTED_ITEM_COUNT = 1 | |
| # Returns the integer amount of items that must be discounted next | |
| # given the amount of items seen | |
| # | |
| def discounted_items_to_find(total_items_seen, discounted_items_seen) | |
| Integer(total_items_seen / (PAID_ITEM_COUNT + DISCOUNTED_ITEM_COUNT) * DISCOUNTED_ITEM_COUNT) - discounted_items_seen | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| customer = Input.cart.customer | |
| discount = 0 | |
| message = "" | |
| if customer | |
| if customer.orders_count > 2 #number of orders needed to get discount | |
| discount = 0.2 #percent discount in decimal form | |
| message = "VIP Customer" | |
| end | |
| end | |
| puts discount |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| customer = Input.cart.customer | |
| discount = 0 | |
| message = "" | |
| if customer | |
| if customer.orders_count == 0 | |
| discount = 0.1 #change the discount given here | |
| message = "Thanks for placing your first order" #change the message shown here | |
| end | |
| puts discount |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| customer = Input.cart.customer | |
| discount = 0 | |
| message = "" | |
| if customer | |
| if customer.orders_count > 2 #number of orders placed to get the deal | |
| discount = 1000 #discount amount in cents | |
| message = "VIP Customer - $10 off" | |
| end | |
| end | |
| puts discount |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| min_discount_order_amount = Money.new(cents:100) * 30 #number of dollars needed in cart to get the discount | |
| total = Input.cart.subtotal_price_was | |
| discount = if total > min_discount_order_amount | |
| 0.2 #discount percentage in decimal form | |
| else | |
| 0 | |
| end | |
| message = "My message" | |
| Input.cart.line_items.each do |line_item| |