Skip to content

Instantly share code, notes, and snippets.

@shopifypartners
shopifypartners / curl_result_example.txt
Created October 25, 2022 17:14 — forked from krzysztofbialek/curl_result_example.txt
Latency curl result example for Shipping Applications development good practices
time_namelookup: 0.326604s
time_connect: 0.467748s
time_appconnect: 0.000000s
time_pretransfer: 0.467986s
time_redirect: 0.000000s
time_starttransfer: 0.584812s
----------
time_total: 0.584852s
@shopifypartners
shopifypartners / curl_example.txt
Created October 25, 2022 17:13 — forked from krzysztofbialek/curl_example.txt
Latency curl example for Shipping Applications development good practices
time_namelookup: %{time_namelookup}s\n
time_connect: %{time_connect}s\n
time_appconnect: %{time_appconnect}s\n
time_pretransfer: %{time_pretransfer}s\n
time_redirect: %{time_redirect}s\n
time_starttransfer: %{time_starttransfer}s\n
----------\n
time_total: %{time_total}s\n
@shopifypartners
shopifypartners / cache_example.rb
Created October 25, 2022 17:13 — forked from krzysztofbialek/cache_example.rb
Cache example for Shipping Applications development good practices
{
destination_address: {
country_code: "CA",
province_code: "QC",
city: "Montreal",
address1: "address 1",
address2: "address 2",
address3: "address 3",
postal_code: "K2K2K2"
},
# 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"),
ExcludeGiftCardSelector.new,
),
MoneyDiscount.new(5_00, "5$ off all items on sale",),
),
def Shopify.set_product_metafield_map(id, namespace, key, map)
# convert the map to JSON so it fits in one metafield
data = {
"metafield" => {
"namespace" => namespace,
"key" => key,
"value" => map.to_json,
"value_type" => "string"
}
}
################################################################################
# Buy set, get X% off discount script.
#
# This script allows the running of a campaign to give customers X% off a "set"
# of items, if and only if they purchase at least one of each item in the set.
#
# The discount is applied only to all items in the set in the cart.
#
# Written by Gavin Ballard (gavin@discolabs.com)
################################################################################
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.id == 6323295239
line_item.change_line_price(line_item.line_price * 0.90, message: "My Sale")
end
Output.cart = Input.cart
#set($inputRoot = $input.path('$'))
{
"X-Shopify-Shop-Domain": "$input.params().header.get('X-Shopify-Shop-Domain')",
"X-Shopify-Topic": "$input.params().header.get('X-Shopify-Topic')",
"X-Shopify-Hmac-SHA256": "$input.params().header.get('X-Shopify-Hmac-SHA256')",
"body": "$util.base64Encode($input.body)",
"queue": "$stageVariables.sqs_queue",
"client_secret": "$stageVariables.client_secret"
}
'use strict';
var AWS = require('aws-sdk');
var sqs = new AWS.SQS();
var crypto = require('crypto');
exports.handler = (event, context, callback) => {
var client_secret = event.client_secret;
delete event.client_secret;
//calculate the hash
<?php
// Set variables for our request
$shop = "demo-shop";
$token = "SWplI7gKAckAlF9QfAvv9yrI3grYsSkw";
$query = array(
"Content-type" => "application/json" // Tell Shopify that we're expecting a response in JSON format
);
// Webhook content, including the URL to POST to