# /assets/ambronite.js # # 2017-06-30 | Jaakko Toivanen <jaakko.toivanen@live.fi> # # File details - On Ambronite's homepage, this script handles the changes and submit on the product form - Number of dropdowns, variants in the dropdowns, price per portion, total price, subscription discount price - isChecked = Subscription checkbox isChecked - salePrice = Sale price / discounted subscription price of the variant - originalPrice = Orignal price of the variant - salePerValue = Sale price / discounted subscription price of one serving size for one product - originalPerValue = Original price of one serving size for one product - selectedKcal = ## Changed 2017-06-30 ## ## Cause: Serving size price was shown without subscription discount on top of the product dropdown on the homepage. ## ## Fix: Added new variable portionPrice to fetch the correct price per one serving and show it on top of the product dropdown. ## ## Below removed code lines start with '-' and added lines start with '+' ## Lines: @@ -191,7 +191,7 @@ambronite.Product = function (pID, hasSubscription) { } if (this.state.selectedKcal) { - this.props.perValueElement.html(Shopify.formatMoney(this.state.originalPerValue, ambronite.strings.moneyFormat) + ' per ' + this.state.selectedKcal + ' kcal') + var portionPrice = this.state.salePerValue + if (!this.state.isChecked) { + var portionPrice = this.state.originalPerValue + } + this.props.perValueElement.html(Shopify.formatMoney(portionPrice, ambronite.strings.moneyFormat) + ' per ' + this.state.selectedKcal + ' kcal') } else { this.props.perValueElement.html('') } ## Added 2017-06-29 ## Lines 374..434 ## ## Cause: Subscription products that were added from the homepage to the cart, did not go to ReCharge Recurring Billing & Subscriptions checkout. ## Variants added to the cart where missing required property-fields needed for 'ReCharge'-checkout to trigger. ## Previously, like in the US-store the properties are submitted via hidden input-elements, but due to change on homepage to include multiple products, ## the variants where added to cart via ajax /cart/update.js function which did not include the needed elements. ## ## Fix: /cart/update.js was used to add all products to the cart. 'ReCharge'-checkout however needs additional properties when variant is added to cart. ## Added new addItemToCart function that adds each variant individually and sets the correct 'ReCharge'-ruleset subscription id for the variant. ## ## Todo: Remove subscription_id, shipping_interval_unit_type and shipping_interval_frequency from being hardcoded in the function. ## ## Below removed code lines start with '-' and added lines start with '+' ## ## Lines: @@ -365,6 +369,74 @@ambronite.productContainer = (function () { + + // Add variants to cart - Jaakko 2017-06-29 + function addItemToCart (variant_id, quantity, countId) { + + // alert("Subscription checkbox " + state.isChecked); + // alert("Shaker checkbox " + state.shakerIsChecked); + var shakerCheckbox = state.shakerIsChecked; + var subscriptionCheckbox = state.isChecked; + var selectedOriginalVariant = document.getElementById('selectedVariant').innerHTML; + // Recharge-app's subscription ruleset 2, subscription_id=3991 + var subscriptionId = "3991"; + // If product selected on hp_product_1 dropdown and first add to cart, use Recharge-app's ruleset 1, subscription_id=707 + // alert("selectedOriginalVariant " + selectedOriginalVariant + " , Count: " + countId); + if (countId == 1 && selectedOriginalVariant != "None") { + var subscriptionId = "707"; + } + + if (subscriptionCheckbox && variant_id!=props.shaker.variants[0].id) { + var data = { + "quantity": quantity, + "id": variant_id, + "properties[shipping_interval_frequency]": 1, + "properties[shipping_interval_unit_type]": "Month", + "properties[subscription_id]": subscriptionId + } + } else { + var data = { + "quantity": quantity, + "id": variant_id + } + } + + $.ajax({ + type: 'POST', + url: '/cart/add.js', + dataType: 'json', + data: data, + async: false, + error: function(){ + alert('Error: Failed to add product ' + id + 'to cart!'); + } + }) + } + + + function addToCart(updates) { + $.ajax({ + type: 'POST', + url: '/cart/clear.js', + dataType: 'json', + async: false, + error: function(){ + alert('Error: Failed to clear the cart!'); + } + }); + var variant = ""; + var iCount = 1; + for (variant in updates) { + addItemToCart(variant, 1, iCount++); + } + } ## Changed 2017-06-29 ## ## Cause: Same as above ## ## Fix: In function handleCartSubmit(e), that triggers when submit button is pressed, the function updateCart() was changed to addToCart(), ## so subscription properties for variant are included in the cart. ## ## Below removed code lines start with '-' and added lines start with '+' ## Lines: @@ -442,9 +515,8 @@ ambronite.productContainer = (function () { - updateCart(updates).then(function () { - document.location.href = '/cart' - }) + addToCart(updates); + document.location.href = '/cart'; # /layout/theme.liquid # # 2017-06-28 | Jaakko Toivanen <jaakko.toivanen@live.fi> # ## Added 2017-06-28 ## ## Cause: 'ReCharge' integration guide http://support.rechargepayments.com/article/91-recharge-integration-guide ## ## Lines: @@ -675,6 +675,8 @@ var google_remarketing_only = true; </script> {% include 'judgeme_html_miracle' %} -{% comment %}ly_static_code_begin{% endcomment %}{% include 'ly-languages' %}{% comment %}ly_static_code_end{% endcomment %}{% include 'smartmarketer' %}{% include 'upsellapp-theme' %}</body> +{% comment %}ly_static_code_begin{% endcomment %}{% include 'ly-languages' %}{% comment %}ly_static_code_end{% endcomment %}{% include 'smartmarketer' %}{% include 'upsellapp-theme' %} +{% include 'subscription-theme-footer' %}<br> +</body> </html> {% comment %}ly_static_code_begin{% endcomment %}{% endcapture %}{% include 'ly-static' with ly_content %}{% comment %}ly_static_code_end{% endcomment %} # /config/settings_data.json # # 2017-06-28 | Jaakko Toivanen <<a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="99f3f8f8f2f2f6b7edf6f0eff8f7fcf7d9f5f0effcb7fff0">[email&#160;protected]</a><script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script>> # # File details: Shop settings. ## Added 2017-06-29 ## ## Added new setting for subscription discount value settings.hp_subscription_discount, which is 15%, so it can be changed from the settings file . ## ## Lines: 699 "hp_subscription_discount": "15%", # /snippets/hp-product-form.liquid # # 2017-06-28 | Jaakko Toivanen <<a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="6208030309090d4c160d0b14030c070c220e0b14074c040b">[email&#160;protected]</a><script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script>> # # File details: Sets the product order form on the home page. ## Added 2017-06-29 ## ## Added new setting for subscription discount value settings.hp_subscription_discount, which is 15%, so it can be changed from the settings file . ## Added id="selectedVariant to product variant dropdown selector, for future use. ## ## Lines: @@ -1,12 +1,20 @@ {% comment %}ly_global_begin{% endcomment %}{% include 'ly-global' %}{% comment %}ly_global_end{% endcomment %} {% assign product = collections.frontpage.products.first %} {% assign shaker_product = all_products[settings.hp_shaker] %} +{% assign hp_product_discount = settings.hp_product_discount %} +{% assign hp_subscription_discount = settings.hp_subscription_discount %} @@ -70,7 +70,7 @@ <ul class="v-selector__list"> <li class="v-selector__active js-trigger"> - <span class="v-selector__active-text js-selected-variant">None</span> + <span class="v-selector__active-text js-selected-variant" id="selectedVariant">None</span> </li> <ul class="v-dropdown js-dropdown" data-productid="{{ product.id }}" style="display:none;"> @@ -101,10 +109,12 @@ {% endif %} {% endfor %} + <div class="p-subscribe"> <div class="p-subscribe__control"> + <input type="hidden" name="subscriptionDiscount" id="subscriptionDiscount" value="{{hp_subscription_discount}}"/> <input type="checkbox" name="attributes[Subscribe]" value="Yes" id="ambroniteSubscribe" class="js-check-subscribe" checked> - <label for="ambroniteSubscribe">Subscribe, <span class="hp-product__red-text">save 15%</span></label> + <label for="ambroniteSubscribe">Subscribe, <span class="hp-product__red-text">save {{hp_subscription_discount}}</span></label> </div> <div class="p-subscribe__control"> # /snippets/product.product-hp.liquid # # 2017-06-29 | Jaakko Toivanen <<a class="__cf_email__" href="/cdn-cgi/l/email-protection" data-cfemail="2c464d4d474743025843455a4d4249426c40455a49024a45">[email&#160;protected]</a><script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script>> # # File details - Ambronite's homepage/frontpage ## Added 2017-06-29 ## ## Cause: Homepage's product form would not response, if user comes to the page via browser's history or using the browser back button ## ## Fix: Added function to refresh product homepage if user comes back to the page using browser history/back button ## ## Lines: @@ -585,6 +585,17 @@ </script> <script type="text/javascript"> + // Reload page if back button was used to get to the page - Jaakko 2017-06-29 + window.addEventListener( "pageshow", function ( event ) { + var historyTraversal = event.persisted || ( typeof window.performance != "undefined" && window.performance.navigation.type === 2 ); + if ( historyTraversal ) { + // Handle page restore. + window.location.reload(); + } +}); +</script> + +<script type="text/javascript"> 'use strict'; $( ".avi-col" ).on( "click", function() { # /snippets/subscription-product-old.liquid # # 2017-06-29 | Jaakko Toivanen <jaakko.toivanen@live.fi> # # File details: - Old product form for homepage that is still used in order for the homepage order form to work ## Changed 2017-06-28 ## ## Cause: Tried to fix 'ReCharge'-checkout issue. No effect. Rollback needed. ## ## Lines: @@ -27,8 +27,7 @@ {% assign subscription_only = 'false' %} {% assign subscription_id = product.metafields.subscriptions.subscription_id %} -<input id="subscription_id_{{product.id}}" name="" value="{{subscription_id}}" class="hide-info"/> - + <script> /*make sure we have jquery available */ var source = '//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' @@ -61,14 +60,14 @@ if (!window.jQuery || arr[0] > 1 || (arr[0] == 1 && arr[1] < 7)) { <label> <span style="color:black;margin-left:0px;"> - <input type="hidden" name="shipping_interval_unit_type" id="shipping_interval_unit_type_{{product.id}}" value="{{shipping_interval_unit_type}}" > + <input type="hidden" name="properties[shipping_interval_unit_type]" id="shipping_interval_unit_type_{{product.id}}" value="{{shipping_interval_unit_type}}" > Deliver every {% if shipping_interval_frequency.size == 1 %} <span >{{shipping_interval_frequency[0]}} {{shipping_interval_unit_type}}</span> - <input type="hidden" name="" id="shipping_interval_frequency_{{product.id}}" value="{{shipping_interval_frequency}}"> + <input type="hidden" name="properties[shipping_interval_frequency]" id="shipping_interval_frequency_{{product.id}}" value="{{shipping_interval_frequency}}"> {%elsif shipping_interval_frequency.size > 1%} - <select name="" id="shipping_interval_frequency_{{product.id}}"> + <select name="properties[shipping_interval_frequency]" id="shipping_interval_frequency_{{product.id}}"> {% for frequency in shipping_interval_frequency %} <option value="{{frequency}}">{{frequency}} {{shipping_interval_unit_type}}</option> {% endfor %} # /templates/cart.liquid # # 2017-06-27 | Jaakko Toivanen <jaakko.toivanen@live.fi> # # File details - Ambronite's cart page ## Changed and Added 2017-06-29 ## ## Cause: Changing variant quantity on the cart page did not update to the checkout. ## Also it was possible to mypass 'MinMaxify'-app limit that prevented to checkout more than one free sample, by changing quantity and clicking checkout before ## MinMaxify-app was fully loaded and order multiple free samples. ## ## Fix: On variant quantity input field. Added function to trigger page reload when field value was change, ## and added css style that prevented pointer events to the field. ## On submit button, disabled it and added css style that prevented pointer and clicks to the button. ## Added script that enabled pointer-events and activated the submit button when cart-page and MinMaxify-app was fully loaded. ## ## Lines: @@ -73,7 +73,7 @@ <p id="quantity_{{ forloop.index }}"> <label for="updates_{{ item.id }}" class="quantity_label">Quantity:</label> - <input type="number" min="0" size="2" maxlength="2" class="quantity" name="updates[]" id="updates_{{ item.id }}" value="{{ item.quantity }}" /> + <input style="pointer-events:none;" onChange="window.location.reload()" type="number" min="0" size="2" maxlength="2" class="quantity" name="updates[]" id="updates_{{ item.id }}" value="{{ item.quantity }}" /> </p> <p class="remove_item"> @@ -117,7 +117,7 @@ <p> <!--<input type="submit" value="Update" /> --> - <input style="background:#72a84d; color:white" type="submit" class="action_button add_to_cart" id="checkout" name="checkout" value="Checkout" /> + <input disabled="disabled" style="background:#72a84d; color:white; pointer-events:none;" type="submit" class="action_button add_to_cart" id="checkout" name="checkout" value="Checkout" /> </p> <p> @@ -158,15 +158,18 @@ {% include 'subscription-cart-footer' %} - <script> + $(document).ready(function(){ + $('input').css('pointer-events','all'); //activate all pointer-events on body + $("#submit").prop("disabled", false); $( ".quantity" ).change(function() { $.ajax({ url:'/cart', type:'POST', data:$("#cart_form").serialize(), success:function(result){ + $.ajax({ type: 'POST', url: '/cart/cart.js',

Ambronite.com
Ambronite

Shopping from US or Canada? Looking for US.Ambronite.com?