Skip to content

Instantly share code, notes, and snippets.

View CodeBrotha's full-sized avatar

Tineyi CodeBrotha

  • United States
View GitHub Profile
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
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 = 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
# 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