Caneca Térmica SouJava Ícone
Código: termica-soujava-icone
* Este prazo de entrega está considerando a disponibilidade do produto + prazo de entrega.
Caneca Térmica, de aço inox, na cor branca, de alto brilho e qualidade.
Capacidade: 440ml
';
}
return '
';
}();
const $container = $product.find('.' + selector);
if($container.length)
$container.append(element);
else
$product.find('.compre-junto__variacoes').append('
' + element + '
');
} else {
let element = '
';
const $container = $product.find('.' + selector);
if($container.length)
$container.find('select').append(element);
else
$product.find('.compre-junto__variacoes').append('
');
}
});
});
if(product.type === 'individual') {
$product.find('.compre-junto__sku').val(product.skus[0].id);
$product.find('.compre-junto__preco--regular').text(formatPrice(product.skus[0].price.full)).attr('data-price', product.skus[0].price.full);
$product.find('.compre-junto__preco--regular').attr('data-full-price', product.skus[0].price.full);
if(product.skus[0].price.promotional > 0 && product.skus[0].price.promotional !== product.skus[0].price.full ){
$product.find('.compre-junto__preco--promocional').text(formatPrice(product.skus[0].price.promotional)).attr('data-price', product.skus[0].price.promotional);
$product.find('.compre-junto__preco--promocional').attr('data-promotional-price', product.skus[0].price.promotional);
}
if(product.skus[0].price.buy_together_price > 0 && product.skus[0].price.buy_together_price !== product.skus[0].price.full){
$product.find('.compre-junto__preco--promocional').text(formatPrice(product.skus[0].price.buy_together_price)).attr('data-buy-together-price', product.skus[0].price.buy_together_price);
$product.find('.compre-junto__preco--promocional').attr('data-price', product.skus[0].price.buy_together_price);
}
} else {
variations[product.id] = skus;
}
return $product.prop('outerHTML');
}
function setVariation(type, $attribute) {
const $product = $attribute.closest('.compre-junto__produto'),
$parent = $attribute.closest('.compre-junto__atributos'),
product_id = $product.attr('data-id'),
$error = $product.find('.compre-junto__erro--variacoes'),
$buy_button = $('.compre-junto__comprar'),
parent_selector = $parent.get(0).classList[1];
$error.text('');
$buy_button.removeClass('compre-junto__comprar--desabilitado');
let value;
if(type === 'grid') {
value = $attribute.attr('data-value');
$parent.find('.compre-junto__atributo--selecionado').removeClass('compre-junto__atributo--selecionado');
$attribute.addClass('compre-junto__atributo--selecionado');
} else {
value = $attribute.val();
}
$parent.attr('data-value', value);
if(variations.hasOwnProperty(product_id) && $product.find('.compre-junto__atributos:not([data-value])').length === 0) {
const selected_attributes = JSON.stringify($product.find('.compre-junto__atributos').map(function() {
return $(this).attr('data-value');
}).get().sort());
const variation_found = {};
$.each(variations[product_id], function(index, variation) {
const attributes = JSON.stringify(variation.attributes.sort());
if(selected_attributes === attributes) {
variation_found.sku = variation.sku;
variation_found.promotional_price = variation.promotional_price;
variation_found.regular_price = variation.regular_price;
variation_found.buy_together_price = variation.buy_together_price;
return false;
}
});
const sku = $product.find('.compre-junto__sku');
const regular_price = $product.find('.compre-junto__preco--regular');
const promotional_price = $product.find('.compre-junto__preco--promocional');
if($.isEmptyObject(variation_found)) {
sku.val('');
regular_price.text('').attr('data-price', '');
promotional_price.text('').attr('data-price', '');
$error.text('Variação indisponível');
$buy_button.addClass('compre-junto__comprar--desabilitado');
return;
}
sku.val(variation_found.sku);
regular_price.text(formatPrice(variation_found.regular_price))
.attr('data-price', variation_found.regular_price)
.attr('data-full-price', variation_found.regular_price);
promotional_price
.attr('data-promotional-price', variation_found.promotional_price || '')
.attr('data-buy-together-price', variation_found.buy_together_price || '')
if (variation_found.buy_together_price > 0 && variation_found.buy_together_price !== variation_found.regular_price) {
promotional_price.text(formatPrice(variation_found.buy_together_price))
.attr('data-price', variation_found.buy_together_price);
return;
}
if (variation_found.promotional_price > 0 && variation_found.promotional_price !== variation_found.regular_price) {
promotional_price.text(formatPrice(variation_found.promotional_price))
.attr('data-price', variation_found.promotional_price);
return;
}
promotional_price.text('').attr('data-price', '');
}
}
function updateTotalPrice() {
let regular_price = 0,
promotional_price = 0;
discount_value = Number($('.compre-junto__conteudo').attr('data-discount-value'));
discount_label = $('.compre-junto__desconto');
$('.compre-junto__produto--principal, .compre-junto__produto--selecionado').each(function() {
const price = $(this).find('.compre-junto__preco--regular').attr('data-price');
if(!price) {
regular_price = 0;
return false;
}
const _regular_price = parseFloat(price),
_promotional_price = $(this).find('.compre-junto__preco--promocional').attr('data-price');
regular_price += _regular_price;
promotional_price += _promotional_price ? parseFloat(_promotional_price) : _regular_price;
});
if(regular_price) {
$('.compre-junto__preco-total--regular').text(formatPrice(regular_price));
$('.compre-junto__preco-total--promocional').text(promotional_price < regular_price ? formatPrice(promotional_price) : '');
} else {
$('.compre-junto__preco-total--regular').text('');
$('.compre-junto__preco-total--promocional').text('');
}
const totalWithPercentage = regular_price - ((discount_value / 100) * regular_price);
if (promotional_price < totalWithPercentage) {
discount_label.hide();
}
}
function updatePriceAttributes() {
var selected_products = $('.compre-junto__produto--selecionado').length;
var total_products = $('.compre-junto__conteudo').attr('data-total');
var buy_together_discount = $('.compre-junto__conteudo').attr('data-discount-value');
var discount_label = $('.compre-junto__desconto');
var all_products_selected = selected_products === total_products - 1;
if (all_products_selected) {
if (buy_together_discount !== 'null'){
$(discount_label).css( 'display', 'block' );
}
$('.compre-junto__conteudo').find('.compre-junto__produto').each(function() {
var productElement = $(this);
var buy_together = Number(productElement.find('.compre-junto__preco--promocional').attr('data-buy-together-price')|| undefined);
var full_price = Number(productElement.find('.compre-junto__preco--regular').attr('data-price')|| undefined);
if(!isNaN(buy_together) && buy_together !== full_price){
productElement.find('.compre-junto__preco--promocional').text(formatPrice(buy_together)).attr('data-price', buy_together)
}
});
return;
}
$(discount_label).css( 'display', 'none' );
$('.compre-junto__conteudo').find('.compre-junto__produto').each(function() {
var productElement = $(this);
var promotional = Number(productElement.find('.compre-junto__preco--promocional').attr('data-promotional-price')|| undefined);
if(!isNaN(promotional)){
productElement.find('.compre-junto__preco--promocional').text(formatPrice(promotional)).attr('data-price', promotional);
}
if(isNaN(promotional)){
productElement.find('.compre-junto__preco--promocional').text('').attr('data-price', '')
}
})
}
function addToCart(buyTogether) {
const url = new URL(cart_url);
$('.compre-junto__produto--principal, .compre-junto__produto--selecionado').each(function() {
const sku = $(this).find('.compre-junto__sku').val();
if(!sku) return;
url.searchParams.set(sku, 1);
});
if(!url.searchParams.size) return;
if(window.eventTracking && typeof window.eventTracking.handleBuyTogetherAddToCart === 'function') {
window.eventTracking.handleBuyTogetherAddToCart();
}
$.cookie('buytogether', buyTogether.id);
$.cookie('buytogetherProducts', Array.from(url.searchParams.keys()));
const fromSmartSuggestions = buyTogether.id === '1';
url.searchParams.set('origin', 'buy-together' + (fromSmartSuggestions ? '-smart' : ''));
window.location.href = url;
}
function setFirstVariation() {
$('.compre-junto__produto').each(function() {
const $variations = $(this).find('.compre-junto__variacoes');
if(!$variations.is(':empty')) {
const $attribute = $variations.find('.compre-junto__atributo').first();
if($variations.find('.compre-junto__atributos').length === 1) {
if($attribute.hasClass('compre-junto__atributo--grade'))
$attribute.click();
else
$attribute.val($attribute.find('option').eq(1).val()).change();
} else {
const productVariations = variations[$(this).attr('data-id')];
const attributeValue = $attribute.hasClass('compre-junto__atributo--grade')
? $attribute.attr('data-value')
: $attribute.find('option').eq(1).val();
const indexVariation = productVariations.findIndex(function(variation) {
return variation.attributes.indexOf(attributeValue) > -1;
});
const attributes = productVariations[indexVariation].attributes;
$.each(attributes, function(index, value) {
const $attribute_grid = $variations.find('.compre-junto__atributo--grade').filter(function() {
return $(this).attr('data-value') === value;
});
if($attribute_grid.length) {
$attribute_grid.click();
} else {
const $attribute_list = $variations.find('.compre-junto__atributo--lista option').filter(function() {
return this.value === value;
});
$attribute_list.parent().val(value).change();
}
});
}
}
});
}
$.get(buy_together_url + PRODUTO_ID, function(response) {
if(response && response.data) {
const buyTogether = response.data,
format = buyTogether.structure === 'list' ? 'lista' : 'grade',
total_products = buyTogether.products.length,
total_columns = $('.produto.span9').length ? 9 : 12;
discount_type = buyTogether.discountType
discount_value = buyTogether.discountValue
products_total_selected = buyTogether.products.length - 1
let html = ' \
\
' + buyTogether.title + '
\
\
`;
if(buyTogether.positionInProduct === 'afterProduct')
$('#buy-together-position2').html(html).show();
else
$('#buy-together-position1').html(html).show();
if(format === 'grade') {
$('.compre-junto__produtos').slick({
infinite: false,
slidesToShow: 2.5,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 1
}
}
]
});
}
updateTotalPrice();
$('.compre-junto__atributo--grade').click(function() {
setVariation('grid', $(this));
updatePriceAttributes();
updateTotalPrice();
});
$('.compre-junto__atributo--lista').change(function() {
setVariation('list', $(this));
updatePriceAttributes();
updateTotalPrice();
});
setFirstVariation();
$('.compre-junto__selecionar input').change(function() {
$(this).closest('.compre-junto__produto').toggleClass('compre-junto__produto--selecionado');
updatePriceAttributes();
const total = $('.compre-junto__produto--selecionado').length + 1;
const total_title = total === 1
? ['somente', 'item']
: ['os', 'itens'];
$('.compre-junto__titulo-total').text('Compre ' + total_title[0] + ' ' + total + ' ' + total_title[1]);
updateTotalPrice();
});
$('.compre-junto__comprar button').click(function() {
addToCart(buyTogether);
});
$(document).trigger('buy_together_ready');
}
});
}
$(function() {
initBuyTogether();
});