Skip to content

Instantly share code, notes, and snippets.

@dturton
dturton / gift-modal.md
Created May 12, 2018 13:55 — forked from jgodson/gift-modal.md
Free Gift Modal for Shopify Themes

How to install

  1. Copy the following code and paste it at the end of config/settings_schema.json, just after the last }. Then save the file.
,
  {
    "name": "Free Gift Offer",
    "settings": [
      {
        "type": "header",
        "content": "Offer a free gift with discount code on cart page"
window.datastore.isMobile= function() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|
case Input.cart.discount_code
<%-# I use the discount code percentage, but you could change it to any other -%>
when CartDiscount::Percentage
<%-# get the discount code -%>
discount_code_string = Input.cart.discount_code.code
<%-# I use a prefix in the cupon codes to know if I should check it out -%>
if discount_code_string.include? "regalopanales"
<%-# use a flag to know if there are more then two different products from the same vendor -%>
discount_flag = true
for item in Input.cart.line_items
# Stop customers from using a discount code
# This script will reject all discount codes. Useful if you have a sale
# and don't want additional discounts to be applied
# Set the rejection message for discount codes
REJECTION_MESSAGE = "Discount codes cannot be used during this sale"
class RejectAllDiscountCodes
# Initializes the campaign.
#
@dturton
dturton / README.md
Created November 7, 2018 19:26 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
import Axios from 'axios'
state = {
todos : null
},
getters = {
TODOS : state => {
return state.todos;
}
},
@dturton
dturton / gist:818511b603acff9a8d8caf3e3fc37ff8
Created May 28, 2019 13:27
OpenCV install on MacOS Mojave from source
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_TBB=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D WITH_V4L=ON \
-D WITH_OPENGL=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
@dturton
dturton / vue-breakpoints.js
Created October 4, 2019 12:05
vue reactive breakpoints
import Vue from 'vue'
const screens = {
sm: 640,
md: 768,
lg: 1024,
xl: 1280
}
const sm = val => val >= screens.sm && val <= screens.md
@dturton
dturton / group.js
Created October 23, 2019 14:38
group duplicate items in array
function groupItems(data) {
const group1 = data.reduce((sums, item) => {
const existingIndex = sums.findIndex(sum => sum.sku === item.sku);
const existing = sums[existingIndex];
if (!existing) return sums.concat(item);
return [
...sums.slice(0, existingIndex),
{
sku: item.sku,
quantity: existing.quantity + item.quantity
@dturton
dturton / CreateOrderFulfillment.js
Created February 17, 2020 14:03
CreateOrderFulfillment.js
const ORDER_SATUS_ARRAY = ["SHIPPED", "IN_TRANSIT"];
export const handle = function*(sosOrder) {
this.sosOrder = sosOrder;
try {
this.w2gOrder = yield this.run.task("GetOrderStatus", this.sosOrder);
if (ORDER_SATUS_ARRAY.includes(this.w2gOrder.status)) {
yield this.run.task("ShipOrder", this.sosOrder, this.w2gOrder);
}
} catch (error) {