Skip to content

Instantly share code, notes, and snippets.

View ihorduchenko's full-sized avatar
💭
Working

Ihor Duchenko ihorduchenko

💭
Working
View GitHub Profile
@ihorduchenko
ihorduchenko / shopify-focal-points.liquid
Created February 28, 2023 22:46
Shopify images focal points usage example
{%- if section.settings.main_image != blank -%}
{%- assign focal_point = section.settings.main_image.presentation.focal_point -%}
{%- capture focal_point_css -%}
{%- if focal_point != blank -%}
style="object-position:{{ focal_point.x }}% {{ focal_point.y }}%;"
{%- endif -%}
{%- endcapture -%}
<div class="collection-banner--img img-cover">
<img class="lazyload" data-src="{{ section.settings.main_image | img_url: 'master' }}" alt="Banner" {{ focal_point_css }}>
</div>
@ihorduchenko
ihorduchenko / get-cart.liquid
Created February 16, 2023 12:48
Programmatically get cart object in Shopify
<script>
const cartRoute = '{{ routes.cart_url | append: '.js' }}';
function forceCartUpdate() {
var getCartForce = function() {
var url = ''.concat(cartRoute, '?t=').concat(Date.now());
return fetch(url, {
credentials: 'same-origin',
method: 'GET'
}).then(response => response.json());
@ihorduchenko
ihorduchenko / cart-total-based-free-gifts.rb
Created January 25, 2023 16:17
Shopify Scripts: Offer free products as gifts when specific cart total reached (with multiple thresholds)
# ================================ Customizable Settings ================================
# ================================================================
# Spend $X, get Product Y for Z Discount
#
# If the cart total is greater than (or equal to) the entered
# threshold (less the discounted amount), the entered number of
# matching items is discounted by the entered amount.
#
# - 'product_selector_match_type' determines whether we look for
# products that do or don't match the entered selectors. Can
@ihorduchenko
ihorduchenko / grid-auto-placement.html
Last active January 17, 2023 12:26
Force certain column to change it's position on desktop outside of the flow
<!-- https://prnt.sc/f05LCS_YIdZq -->
<div class="product-hero">
<div class="product-media__wrapper">
Product media
</div>
<div class="product__info">
Product info
</div>
@ihorduchenko
ihorduchenko / input-radio-change-trigger.js
Created November 16, 2022 23:22
Trigger radio-button change event
if ('createEvent' in document) {
var evt = document.createEvent('HTMLEvents');
evt.initEvent('change', false, true);
inputRadioDOMelement.dispatchEvent(evt);
}
@ihorduchenko
ihorduchenko / shopifyCartAjaxify.js
Created November 10, 2022 15:10
Ajax methods to manage cart items in Shopify
// Add item to the cart
function cartItemAdd(id, qty) {
fetch('/cart/add.js', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify({'items': [{'id':id,'quantity':qty}]})
@ihorduchenko
ihorduchenko / newline_to_br_split.liquid
Last active May 6, 2023 12:54
Split text field to multiple lines using 'newline_to_br' and 'split' filters
{%- assign text_rows = text | newline_to_br | split: '<br />' -%}
{%- for row in text_rows -%}
{{ row }}
{%- endfor -%}
@ihorduchenko
ihorduchenko / reviews.io-star-rating-snippet.liquid
Created September 8, 2022 10:30
Reviews.io star rating snippet for Shopify
<div class="ruk_rating_snippet" data-sku="{{ product.handle }};{{ product.variants | map: 'sku' | join: ';' }};{{ product.variants | map: 'id' | join: ';' }}"></div>
@ihorduchenko
ihorduchenko / disable-discount-codes-for-sale-items.rb
Created August 8, 2022 23:16
Disable discount codes for the specified list of variant IDs of items
# ================================ Customizable Settings ================================
# ================================================================
# Disable Discount Code(s) For Products
#
# If any matching discount codes are used, and any matching items
# are in the cart, the discount code is rejected with the entered
# message.
#
# - 'discount_code_match_type' determines whether the below
# strings should be an exact or partial match. Can be:
@ihorduchenko
ihorduchenko / autoplay-lazy-videos-intersection-observer.liquid
Created July 26, 2022 01:02
Toggle video play on screen intersection + on click
<div class="absolute-cover video-cover controlled-video autoplayLazyVideo">
<video
{% if img != blank %}
poster="{{ img.src }}"
{% endif %}
playsinline
loop
muted>
<source
src="{{ video.src }}"