Last active
December 10, 2015 23:28
-
-
Save msmithstubbs/4509078 to your computer and use it in GitHub Desktop.
Back In Stock example for Eric Smith
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Example code only | |
| * This code has not been tested on a live site | |
| * | |
| * | |
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE * WARRANTIES OF MERCHANTABILITY, | |
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| * AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
| * IN THE SOFTWARE. | |
| * | |
| */ | |
| var selectCallback = function(variant, selector) { | |
| if (variant && variant.available) { | |
| // selected a valid variant that is available. | |
| // this line has been changed for Back In Stock | |
| jQuery('#product-add-wrap input[type=submit]').attr('id', 'add').removeClass('disabled').removeAttr('disabled').val('Add to Cart').fadeTo(200,1); // remove unavailable class from add-to-cart button, and re-enable button | |
| // if item is backordered yet can still be ordered, we'll show special message. | |
| if (variant.inventory_management && variant.inventory_quantity <= 0) { | |
| jQuery('#selected-variant').html("Joyetech eGo-T 2 Upgrade Battery" + ' - ' + variant.title); | |
| jQuery('#backorder').removeClass("hidden").fadeTo(200,1); | |
| } else { | |
| jQuery('#backorder').fadeTo(200,0).addClass("hidden"); | |
| } | |
| if ( variant.compare_at_price > variant.price ) { | |
| jQuery('#product-price').html('<span class="product-price on-sale">'+ Shopify.formatMoney(variant.price, "${{amount}}") +'</span>'+' <span class="product-compare-price">'+Shopify.formatMoney(variant.compare_at_price, "${{amount}}")+ '</span>'); // update price field | |
| } else { | |
| jQuery('#product-price').html('<span class="product-price">'+ Shopify.formatMoney(variant.price, "${{amount}}") + '</span>' ); // update price field | |
| } | |
| Currency.convertAll(shopCurrency, jQuery('[name=currencies]').val(), 'form[action="/cart/add"] span.money'); | |
| } else { | |
| // variant doesn't exist or is sold out | |
| jQuery('#backorder').fadeTo(200,0).addClass("hidden"); | |
| // the following two lines changed for Back In Stock | |
| var message = variant ? "Email me when available" : "Unavailable"; | |
| jQuery('#product-add-wrap input[type=submit]').val(message).attr('id', 'BIS_trigger'); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment