Skip to content

Instantly share code, notes, and snippets.

Avatar

Shopify Partners shopifypartners

View GitHub Profile
View shopify-scripts-multiple-components-one-scripts-example.rb
# 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",),
),
View developing-accessible-shopify-themes-form-error-form-success.liquid
{% form ‘new_comment’, article %}
{{ form.errors | default_errors }}
<label for=”CommentAuthor” class=”hidden-label”>Name</label>
<input {% if form.errors contains 'author' %}class=”error”{% endif %} type=”text” name=”comment[author]” placeholder=”Name” id=”CommentAuthor” value=”{{ form.author }}”>
<label for=”CommentEmail” class=”hidden-label”>Email</label>
<input {% if form.errors contains 'email' %}class=”error”{% endif %} type=”email” name=”comment[email]” placeholder=”email” id=”CommentEmail” value=”{{ form.email }}” autocorrect=”off” autocapitalize=”off”>
{% endform %}
View ambient-light-simple-demo.js
if ( 'AmbientLightSensor' in window ) {
const sensor = new AmbientLightSensor();
sensor.onreading = () => {
if ( sensor.illuminance < 20) {
element.style.setProperty('--bg', 'black’);
} else {
element.style.setProperty('--bg', 'blue’);
}
};
sensor.start();
View using-javascript-on-client-stores-information-request-from-server.js
(function(Resources, $, undefined) {
// Private
var requestLimit = 50;
var collections = [];
var collectionsHandleMap = [];
var products = [];
var productsHandleMap = [];
var getResources = function() {
View shopify-api-update-variant-inventory.rb
# Takes a product id, and a map of variant ids and quantities
def update_inventory(id, vid_quantities)
variants = vid_quantities.map do |vid, qty|
{ "id" => vid, "inventory_quantity" => qty }
end
data = {
"product" => {
"variants" => variants
}
}
View relative-pagination.rb
products = ShopifyAPI::Product.find(:all, params: { order: 'inventory_total desc', limit: 250 })
process_products(products)
3.times do
break unless products.next_page?
products = products.fetch_next_page
process_products(products)
end
View a-beginners-guide-to-sass-part-3-interpolation.liquid.scss
// Escaping Liquid in SCSS.
//
// Expected output:
// a{
// color: {{ settings.link-color }};
// }
a{
color: #{'{{ settings.link-color }}'};
}
View sticky-add-to-cart.html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="jquery.sticky.js"></script>
<script>
$(document).ready(function(){
$(".add-to-cart").sticky({topSpacing:50});
});
</script>
View shopify-api-call-limit-with-mutex.rb
# use a shared lock and credits_remaining
@lock = Mutex.new
@credits_remaining = 40
@shopify_url = ENV["SHOPIFY_URL"]
# Sends a request to Shopify, blocking until credits are available
def self.request(method, path, params={})
params[:headers] = {"Content-Type" => "application/json"}
# wait for a credit
View ambient-light-simple-demo.js
if ( 'AmbientLightSensor' in window ) {
const sensor = new AmbientLightSensor();
sensor.onreading = () => {
if ( sensor.illuminance < 20) {
element.style.setProperty('--bg', 'black’);
} else {
element.style.setProperty('--bg', 'blue’);
}
};
sensor.start();
You can’t perform that action at this time.