Shopify.queue = []; $product = {"id":1473529839715,"title":"犀牛盾SolidSuit手機殼 - OnePlus 6T - 【獨家設計款】 - Not Today","handle":"oneplus-6t-solidsuit-classic-d105","description":"","published_at":"2019-01-16T14:09:09+08:00","created_at":"2019-01-10T15:40:07+08:00","vendor":"Rhinoshield","type":"Android SolidSuit客製化","tags":["20%","25%","30%","35%","40%","45%","50%","android","brand-OnePlus","designer","device-OnePlus 6T","member","OnePlus 6T","reseller","reseller-asus","solidsuit","Top50"],"price":83000,"price_min":83000,"price_max":83000,"available":true,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":12985661882467,"title":"Black","option1":"Black","option2":null,"option3":null,"sku":"SSA0909352-D105","requires_shipping":true,"taxable":true,"featured_image":{"id":4286695735395,"product_id":1473529839715,"position":1,"created_at":"2019-01-10T15:51:45+08:00","updated_at":"2019-10-17T09:15:11+08:00","alt":null,"width":2000,"height":2000,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1082\/7110\/products\/product-SSA0909352-D105.png?v=1571274911","variant_ids":[12985661882467]},"available":true,"name":"犀牛盾SolidSuit手機殼 - OnePlus 6T - 【獨家設計款】 - Not Today - Black","public_title":"Black","options":["Black"],"price":83000,"weight":100,"compare_at_price":null,"inventory_quantity":-1,"inventory_management":null,"inventory_policy":"deny","barcode":null,"featured_media":{"alt":null,"id":1041651695715,"position":1,"preview_image":{"aspect_ratio":1.0,"height":2000,"width":2000,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1082\/7110\/products\/product-SSA0909352-D105.png?v=1569102233"}}}],"images":["\/\/cdn.shopify.com\/s\/files\/1\/1082\/7110\/products\/product-SSA0909352-D105.png?v=1571274911"],"featured_image":"\/\/cdn.shopify.com\/s\/files\/1\/1082\/7110\/products\/product-SSA0909352-D105.png?v=1571274911","options":["color"],"media":[{"alt":null,"id":1041651695715,"position":1,"preview_image":{"aspect_ratio":1.0,"height":2000,"width":2000,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1082\/7110\/products\/product-SSA0909352-D105.png?v=1569102233"},"aspect_ratio":1.0,"height":2000,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1082\/7110\/products\/product-SSA0909352-D105.png?v=1569102233","width":2000}],"content":""}; $bumper = null if ($bumper) { $(document).ready(function() { var productImg = $product.images[0] var bumperVariants = $bumper.variants; var bumperColors = new Object(); var currentVariant = ''; var productType = ''; bumperVariants.forEach(variant => { bumperColors[`${variant.title.split(' (')[0].toLowerCase()}`] = variant.featured_image.src; }); if (productType === 'mod-nx-backplate' || productType === 'mod-backplate') { mergeImages([productImg, bumperColors[currentVariant]],{ crossOrigin: 'anonymous' }) .then(mergedImg => { $('.merged-img').attr('src', mergedImg); }); } else { mergeImages([bumperColors[currentVariant], productImg],{ crossOrigin: 'anonymous' }) .then(mergedImg => { $('.merged-img').attr('src', mergedImg); }); } }); $('#SingleOptionSelector-0').on('change', function() { var productImg = $product.images[0] var bumperVariants = $bumper.variants; var bumperColors = new Object(); var currentVariant = $(this).val().split(' (')[0].toLowerCase(); var productType = ''; bumperVariants.forEach(variant => { bumperColors[`${variant.title.toLowerCase()}`] = variant.featured_image.src; }); if (productType === 'mod-nx-backplate' || productType === 'mod-backplate') { mergeImages([productImg, bumperColors[currentVariant]],{ crossOrigin: 'anonymous' }) .then(mergedImg => { $('.merged-img').attr('src', mergedImg); }); } else { mergeImages([bumperColors[currentVariant], productImg],{ crossOrigin: 'anonymous' }) .then(mergedImg => { $('.merged-img').attr('src', mergedImg); }); } }) } $(function() { // switch device $('#select-device').on('change', function() { window.location.href = $(this).val(); }); // listen quantity changed $('input[name=quantity]').on('change', function() { var quantity = $(this).val(); }); // checkbox action $("input:checkbox").on('click', function() { // in the handler, 'this' refers to the box clicked on var $box = $(this); if ($box.is(":checked")) { // the name of the box is retrieved using the .attr() method // as it is assumed and expected to be immutable var group = "input:checkbox[name='" + $box.attr("name") + "']"; // the checked state of the group/box on the other hand will change // and the current value is retrieved using .prop() method $(group).prop("checked", false); $box.prop("checked", true); } else { $box.prop("checked", false); } }); // add to cart $("#AddToCart-product-template").click(function(e){ var elem; var addition = {}; Shopify.queue = []; e.preventDefault(); // elem = $(this); // $(elem).prop("disabled", true); var original_variant_id = $('.product-form').serialize().split('&')[0].split('=')[1]; var original_variant_quantity = $('.product-form').serialize().split('&')[1].split('=')[1]; addition.id = original_variant_id; addition.quantity = original_variant_quantity; Shopify.queue.push(addition); $.each($("input[name^='recommend[']:checked"), function(i, v) { var addition = {}; var name = $(this).attr('name'); var quantity = $('select[name="' + name + '"]').val(); addition.id = $(this).val(); addition.quantity = quantity; Shopify.queue.push(addition); }); Shopify.moveAlong(); }); Shopify.moveAlong = function() { // If we still have requests in the queue, let's process the next one. // console.log(Shopify.queue); if (Shopify.queue.length) { var request = Shopify.queue.shift(); Shopify.addItem(request.id, request.quantity, Shopify.moveAlong); } // If the queue is empty, take care of the main item else { $.getJSON('/cart.js', function(cart) { $('#CartCount').removeClass('hide'); $('#item-count').text(cart.item_count); toastr.options = { "closeButton": false, "debug": false, "newestOnTop": false, "progressBar": false, "positionClass": "toast-bottom-right", "preventDuplicates": false, "onclick": null, "showDuration": "300", "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": "fadeIn", "hideMethod": "fadeOut" }; toastr["success"]("成功加入購物車"); }); } }; });
// Override default values of shop.strings for each template. // Alternate product templates can change values of // add to cart button, sold out, and unavailable states here. theme.productStrings = { addToCart: "加到購物車", soldOut: "售完", unavailable: "停產" }