Code Monkey home page Code Monkey logo

scripts-public's Introduction

Shopify Scripts

Shopify Scripts is only available to select Shopify merchants

Shopify's Script Editor allow you to write Ruby scripts that can modify the prices and properties of line items in your store's cart. With scripts, you can create discounts that will be applied automatically based on the items and properties of a cart.

This repository provides public informations about scripts, new functionalities and examples that can be created with Shopify's Script Editor.

Changelog

Look at the changelog for more informations about the latest changes in Shopify Script

Examples

# Use an array to keep track of the discount campaigns desired.
CAMPAIGNS = [
  # $5 off all items with the "sale" tag
  ItemCampaign.new(
    AndSelector.new(
      TagSelector.new("sale"),
      ExcludeGiftCartSelector.new,
    ),
    MoneyDiscount.new(5_00, "5$ off all items on sale",),
  ),

  # 10% off all items with a price lower than $100
  ItemCampaign.new(
    AndSelector.new(
      ExcludeGiftCartSelector.new,
      PriceSelector.new(:lower_than, Money.new(cents: 100_00)),
    ),
    PercentageDiscount.new(10, "10% off all items under 100$"),
  ),

  # Give every 3rd item with the tag "letter" for free
  BogoCampaign.new(
    TagSelector.new("letter"),
    PercentageDiscount.new(100, "Third item is free"),
    LowToHighPartitioner.new(2,1),
  )
]

# Iterate through each of the discount campaigns.
CAMPAIGNS.each do |campaign|
  # Apply the campaign onto the cart.
  campaign.run(Input.cart)
end

# In order to have the changes to the line items be reflected, the output of
# the script needs to be specified.
Output.cart = Input.cart

Exploring

This repository aims to build small, reusable components that can be assembled to write fully-functional discount scripts.

Campaigns

Campaigns are Ruby classes that organize discounting. They are responsible for tracking the eligibility of discounts, selecting items and applying discounts.

  • ItemCampaign: Discount all the products with the selected tag.
  • BogoCampaign: Give x free items when y items have been purchased (for example, "buy one get one free").

Discounts

Discounts modify the prices of line items.

Selectors

Selectors find items that are eligible for discounting.

Partitioners

Partitioners divide line items into non-discounted and discounted items. They are used for BogoCampaign. For example:

BogoCampaign.new(
  TagSelector.new("sale"),
  PercentageDiscount.new(100, "Third item is free"),
  LowToHighPartitioner.new(2,1),
)
  1. The TagSelector finds all items that have the sale tag.
  2. The LowToHighPartitioner sorts all items with prices ascending (low to high), and then returns every 3rd item (skipping 2, taking 1).
  3. The PercentageDiscount then applies 100% discounts on all items returned by the partitioner.

scripts-public's People

Contributors

adamhollett avatar gavinballard avatar gmalette avatar michael-thorpe avatar simon-shopify avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.