Coder Social home page Coder Social logo

carolineschnapp-gift-wrap's People

Contributors

carolineschnapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

carolineschnapp-gift-wrap's Issues

When Gift Wrap is Removed from Cart, Added Again

A customer noticed this and I was able to replicate it.

Steps to Replicate

  1. Add Products to Cart
  2. Check Gift Wrap Box
  3. Remove Gift Wrap from Cart (Not by Unchecking Box but by Cart/Themes Natural Remove)

At this point, Line 79 Fires and Re-Adds to Gift Wrap to Cart since Box is Checked Still.

Only 1 option was able to add in the cart

issue = https://watch.screencastify.com/v/zbKFUaiUTvRsIqNsomZ9

My code below: Please help! :)

{% if linklists.gift-wrapping.links.size > 0 and linklists.gift-wrapping.links.first.type == 'product_link' %}

{% for link in linklists.gift-wrapping.links %}

{% assign product_title = link.object.title %}

Add a {{link.object.title}} (Additional {{ link.object.price | money }}) {{link.object.description}}

{% endfor %}

{% assign id = linklists.gift-wrapping.links.first.object.variants.first.id%}

{% assign gift_wraps_in_cart = 0 %}
{% for item in cart.items %}
{% if item.id == id %}
{% assign gift_wraps_in_cart = item.quantity %}
{% endif %}
{% endfor %}
{% assign items_in_cart = cart.item_count | minus:gift_wraps_in_cart %}

<style> #updates_{{ id }} { display: none; } </style> <script> Shopify.Cart = Shopify.Cart || {}; Shopify.Cart.GiftWrap = {}; Shopify.Cart.GiftWrap.set = function() { var headers = new Headers({ 'Content-Type': 'application/json' }); var request = { method: 'POST', headers: headers, body: JSON.stringify({ updates: { {{ id }}: {{ items_in_cart }} }, attributes: { 'gift-wrapping': true } }) }; fetch('/cart/update.js', request) .then(function() { location.href = '/cart'; }); } Shopify.Cart.GiftWrap.remove = function() { var headers = new Headers({ 'Content-Type': 'application/json' }); var request = { method: 'POST', headers: headers, body: JSON.stringify({ updates: { {{ id }}: 0 }, attributes: { 'gift-wrapping': '', 'gift-note': '' } }) }; fetch('/cart/update.js', request) .then(function() { location.href = '/cart'; }); } // If we have nothing but gift-wrap items in the cart. {% if cart.items.size == 1 and gift_wraps_in_cart > 0 %} document.addEventListener("DOMContentLoaded", function(){ Shopify.Cart.GiftWrap.remove(); }); // If we don't have the right amount of gift-wrap items in the cart. {% elsif gift_wraps_in_cart > 0 and gift_wraps_in_cart != items_in_cart %} document.addEventListener("DOMContentLoaded", function(){ Shopify.Cart.GiftWrap.set(); }); // If we have a gift-wrap item in the cart but our gift-wrapping cart attribute has not been set. {% elsif gift_wraps_in_cart > 0 and cart.attributes.gift-wrapping == blank %} document.addEventListener("DOMContentLoaded", function(){ Shopify.Cart.GiftWrap.set(); }); // If we have no gift-wrap item in the cart but our gift-wrapping cart attribute has been set. {% elsif gift_wraps_in_cart == 0 and cart.attributes.gift-wrapping != blank %} document.addEventListener("DOMContentLoaded", function(){ Shopify.Cart.GiftWrap.set(); }); {% endif %} // When the gift-wrapping checkbox is checked or unchecked. document.addEventListener("DOMContentLoaded", function(){ document.querySelector('[name="attributes[gift-wrapping]"]').addEventListener("change", function(event) { if (event.target.checked) { Shopify.Cart.GiftWrap.set(); } else { Shopify.Cart.GiftWrap.remove(); } }); document.querySelector('#gift-note').addEventListener("change", function(evt) { var note = evt.target.value; var headers = new Headers({ 'Content-Type': 'application/json' }); var request = { method: 'POST', headers: headers, body: JSON.stringify({ attributes: { 'gift-note': note } }) }; fetch('/cart/update.js', request); }); }); </script>

{% else %}

You attempted to add a gift-wrapping script to your shopping cart, but it won't work because you don't have a link list with handle gift-wrapping which, in turn, contains a link to your gift-wrapping product. Please review the steps outlined here.

{% endif %}

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.