Skip to content

Instantly share code, notes, and snippets.

View CodeBrotha's full-sized avatar

Tineyi CodeBrotha

  • United States
View GitHub Profile
# Saving a product from database
product = ShopifyAPI::Product.find(179761209) # This does an get http request to shopify api
db_product = DBProduct.new # You have to create a new rails model
db_product.shopify_id = product.id
db_product.save
# Saving a product to shopify
product.title = 'changed'
product.save # updates product in shopify, http put request
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
discount = 1
message = "Free Standard Shipping"
Input.shipping_rates.each do |shipping_rate|
next unless shipping_rate.source == "shopify"
next unless shipping_rate.name == "Standard Shipping"
shipping_rate.apply_discount(shipping_rate.price * discount, message: message)
end
Output.shipping_rates = Input.shipping_rates
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
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?
@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
min_discount_order_amount = Money.new(cents:100) * 30 #minimum amount needed to have in cart to get discount
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount
500 #discount amount you are offering in cents
else
0
end
message = "Here's $5 off" #discount message shown to customer
Input.cart.line_items.each do |line_item|
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|
customer = Input.cart.customer
discount = 0
message = ""
if customer
if customer.orders_count < 1
discount = 1000 #discount amount in cents
message = "New Customer - $10 off"
end
end
puts discount
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