//
// BBOX fejlesztés
var is_bbox_active = true;
var bb_token_id = '';
var bb_token_id_tokens = '';
var bbox_references = '';
var BBOX_DESC = '';
var BBOX_host = 'https://konyhaelektro.bookofmycars.com';
var bbox_termek_parameterek = {}; // ezt adatbázisból kérjük ki
if (is_bbox_active) {
if (true) {
if (ShopRenter.product) {
if (true) {
$(document).ready(() => {
// megnézzük, hogy van-e minden paraméter az oldalon
if(
($('.parameter-table').text().toLowerCase().includes('a garanciaidő évben')) &&
($('.parameter-table').text().toLowerCase().includes('termék márkája:')) &&
($('.parameter-table').text().toLowerCase().includes('termék típusa:'))
) {
bbox_termek_parameterek.termek_ara = ShopRenter.product.price;
bbox_termek_parameterek.termek_cikkszam = ShopRenter.product.sku;
bbox_termek_parameterek.termek_neve = ShopRenter.product.name;
var rows_ = $('.parameter-table tr');
for(r = 0; r < rows_.length; r++) {
if(($(rows_[r]).text().toLowerCase().includes('a garanciaidő évben'))) {
bbox_termek_parameterek.termek_garancia = $('td:nth-child(2)', rows_[r]).text();
$(rows_[r]).css('display', 'none');
}
if(($(rows_[r]).text().toLowerCase().includes('termék márkája:'))) {
bbox_termek_parameterek.termek_markaja = $('td:nth-child(2)', rows_[r]).text();
$(rows_[r]).css('display', 'none');
}
if(($(rows_[r]).text().toLowerCase().includes('termék típusa:'))) {
bbox_termek_parameterek.termek_tipusa = $('td:nth-child(2)', rows_[r]).text();
$(rows_[r]).css('display', 'none');
}
}
add_bbox_css();
place_bbox_init_btn();
}
/* // fetch, megnézzük, hogy van-e ilyen termék
const postUrl = BBOX_host + '/bbox/getProductParameters';
// Configuring the fetch request
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json' // specify the content type as JSON
},
body: JSON.stringify({
sku: ShopRenter.product.sku,
shop_hash: shop_hash
}) // convert the JavaScript object to JSON string
};
fetch(postUrl, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(data => {
console.log(data);
if (data.status == 'ok') {
bbox_termek_parameterek.termek_markaja = data.data.termek_markaja;
bbox_termek_parameterek.termek_tipusa = data.data.termek_tipusa;
bbox_termek_parameterek.termek_garancia = data.data.termek_garancia;
bbox_termek_parameterek.termek_ara = data.data.termek_ara;
bbox_termek_parameterek.termek_cikkszam = data.data.termek_cikkszam;
bbox_termek_parameterek.termek_neve = data.data.termek_neve;
add_bbox_css();
place_bbox_init_btn();
} else {
console.log('A termékre BBOX szolg. nincs beállítva.');
}
})
.catch(error => {
// Handle errors
console.error('There was a problem with your fetch operation:', error);
});
*/
});
}
}
setInterval(() => {
if (($('#payment-overlay').length < 1) && $('#payment').length > 0) {
var is_bbox = false;
var is_bbox_portable = false;
var cartItems = $('.cart-items .cart-item .product-name');
var productToGetSku = '';
for (i = 0; i < cartItems.length; i++) {
if (($(cartItems[i]).html()).includes('BusinessBox')) {
is_bbox = true;
productToGetSku = $(cartItems[i]).html();
if (($(cartItems[i]).html()).includes('(hordozható')) {
is_bbox_portable = true;
//productToGetSku = $(cartItems[i]).html();
break;
}
}
}
if (is_bbox) {
get_token_id(productToGetSku);
}
}
}, 1000);
}
}
if (ShopRenter.lastOrder) {
// URL to send the POST request to
const postUrl = BBOX_host + '/bbox/orderSuccessSr';
// Configuring the fetch request
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json' // specify the content type as JSON
},
body: JSON.stringify({ order_id: ShopRenter.lastOrder.id, shop_hash: shop_hash, userAgent: navigator.userAgent }) // convert the JavaScript object to JSON string
};
fetch(postUrl, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(data => { console.log(data) })
.catch(error => {
// Handle errors
console.error('There was a problem with your fetch operation:', error);
});
}
function add_bbox_css() {
$('body').append(``);
}
function place_bbox_init_btn() {
var parent = $('#product .product-cart-box .button-add-to-cart').parent().parent().parent();
$(parent).prepend('
BusinessBox kiterjesztett garancia szolgáltatás
');
}
function acceptTermsDelayed(postData, i) {
setTimeout(() => {
var postUrl = BBOX_host + '/bbox/acceptTerms';
// Configuring the fetch request
var requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json' // specify the content type as JSON
},
body: JSON.stringify(postData) // convert the JavaScript object to JSON string
};
fetch(postUrl, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(data => { console.log(data); })
.catch(error => {
// Handle errors
console.error('There was a problem with your fetch operation:', error);
});
}, i * 170);
}
function get_token_id(productToGetSku) {
//alert(location.href + '/cart.json');
$.ajax({
type: 'GET',
url: location.origin + '/cart.json',
success: function (res) {
var cartContent = res.items;
var tokenId = '';
var sku = '';
for (i = 0; i < cartContent.length; i++) {
if (cartContent[i].name == productToGetSku) {
console.log('cartContent[i].name', cartContent[i].name);
console.log('productToGetSku', productToGetSku);
tokenId = cartContent[i].sku.split('-')[2];
sku = cartContent[i].sku;
}
}
get_infos_bbox(sku);
},
error: function (request, status, error) {
// alert(request.responseText);
}
});
}
function get_infos_bbox(sku) {
var postData = {
sku: sku,
shop_hash: shop_hash
};
// URL to send the POST request to
var postUrl = BBOX_host + '/bbox/getInfos';
// Configuring the fetch request
var requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json' // specify the content type as JSON
},
body: JSON.stringify(postData) // convert the JavaScript object to JSON string
};
fetch(postUrl, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(data => { console.log(data); disablePayment(); showConfirmText(data); })
.catch(error => {
// Handle errors
console.error('There was a problem with your fetch operation:', error);
});
}
function disablePayment() {
$('#payment').append('');
}
function showConfirmText(data) {
var text = JSON.parse(data.confirmtext).confirm;
if ($('#bbox_confirm_checkbox_wrapper').length < 1) {
$('#checkout_confirmation_container').prepend('
A megrendelés véglegesítésével tudomásul veszem és magamra nézve kötelező érvényűnek tekintem, hogy a megrendelésben szereplő tételek tekintetében fizetési kötelezettségem keletkezik.
');
$('.summary-bottom-box-wrapper').prepend('
A termék megrendelésre vonatkozó, a távollévők között kötött szerződés szabályai alapján:
A szolgáltatás megrendelésre vonatkozó, a távollévők között kötött szerződés szabályai alapján:
');
}
}
function checkBBoxConfirm() {
if ($('#bbox_confirm_checkbox').is(':checked') && $('#bbox_more_checkbox').is(':checked')) {
$('#payment button').click();
} else {
alert('Kérem, valamennyi feltételt fogadja el!');
}
}
function init_bbox() {
var postData = {
// INIT
ip: ShopRenter.customer.userClientIP,
userAgent: navigator.userAgent,
shop_hash: shop_hash
};
// URL to send the POST request to
var postUrl = BBOX_host + '/bbox/init';
// Configuring the fetch request
var requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json' // specify the content type as JSON
},
body: JSON.stringify(postData) // convert the JavaScript object to JSON string
};
fetch(postUrl, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(data => { console.log(data); bb_token_id = data.tokenId; tokens_bbox(); })
.catch(error => {
// Handle errors
console.error('There was a problem with your fetch operation:', error);
});
}
function tokens_bbox() {
var postData = {
// TOKENS
tokenId: bb_token_id,
shop_hash: shop_hash
};
// URL to send the POST request to
var postUrl = BBOX_host + '/bbox/tokens';
// Configuring the fetch request
var requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json' // specify the content type as JSON
},
body: JSON.stringify(postData) // convert the JavaScript object to JSON string
};
fetch(postUrl, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(data => { console.log(data); bb_token_id_tokens = data.tokenId; remote_calculation_bbox(); })
.catch(error => {
// Handle errors
console.error('There was a problem with your fetch operation:', error);
});
}
function remote_calculation_bbox() {
var postData = {
productTypeReference: bbox_termek_parameterek.termek_tipusa,
productBrandReference: bbox_termek_parameterek.termek_markaja,
productPrice: Math.round(bbox_termek_parameterek.termek_ara) || Math.round(ShopRenter.product.price),
warrantyPeriod: bbox_termek_parameterek.termek_garancia,
productTypeNumber: bbox_termek_parameterek.termek_cikkszam,
tokenId: bb_token_id_tokens,
product_name: bbox_termek_parameterek.termek_neve,
product_sku: bbox_termek_parameterek.termek_cikkszam,
shop_hash: shop_hash
};
// URL to send the POST request to
var postUrl = BBOX_host + '/bbox/remoteCalculate';
// Configuring the fetch request
var requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json' // specify the content type as JSON
},
body: JSON.stringify(postData) // convert the JavaScript object to JSON string
};
fetch(postUrl, requestOptions)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(data => { console.log(data); show_select_option_bbox(data) })
.catch(error => {
// Handle errors
console.error('There was a problem with your fetch operation:', error);
});
}
function show_select_option_bbox(data) {
var response = JSON.parse(data.data);
if (response.calculationItems) {
var maganszemely = '';
if (response.calculationItems) {
maganszemely += '';
}
var ceg = '';
if (response.calculationItemsCompany) {
ceg += '';
}
if (response.calculationItemsCompany.length == 0) {
ceg = '';
}
var BBOX_PARENT = $('.product-page-right .product_table_addtocartbtn');
var BBOX_SELECT_OPTION_TITLE = '