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
| 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 |
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
| # 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 |
NewerOlder