n_oct/themes/nurgul/partials/scripts/productDetail.htm

71 lines
2.6 KiB
HTML
Executable File

{% put scripts %}
<script>
getProductDetail('{{query}}');
// console.log("qqq");
function getProductDetail(query) {
console.log(query);
$(document).ready(function () {
$.ajax({
url: `https://nurgul.com.tm/app/api/products/{{prodId}}/` + query,
type: 'GET',
dataType: 'json',
beforeSend: function () {
$('#deatil_screen').hide();
$('#loader').show();
},
success: function (data, textStatus, xhr) {
$('#loader').hide();
$('#deatil_screen').show();
console.log(data.data);
var product = data.data;
setDetail(product);
},
error: function (xhr, textStatus, errorThrown) {
console.log('Error in Operation');
}
});
});
}
function setDetail(product) {
var images = product.images;
for (var image of images) {
// console.log(product.hasOwnProperty('special_price'));
$('#product_images').append(`<div class="single-small-img">
<img src="`+image.small_image_url+`" alt="Nurgul `+ product.name +`">
</div>`);
}
for (var image of images) {
// console.log(product.hasOwnProperty('special_price'));
$('#product_large_images').append(`<div class="single-large-img">
<a href="`+image.original_image_url+`" data-rel="lightcase:myCollection">
<img src="`+image.original_image_url+`" alt="Nurgul `+ product.name +`">
</a>
</div>`);
}
// $('#product_images').html(`<img src="`+product.images[0].original_image_url+`" alt="Nurgul `+ product.name +`">`);
$('#product_name').html(product.name);
$('#product_main').html(product.name);
$('#product_price').html(product.formatted_price);
$('#product_desc_short').html(product.short_description);
$('#product_desc').html(product.description);
$('#product_add').html(`{{ 'add.cart'|_ }}`);
if (product.hasOwnProperty('special_price')) {
$('#product_discount').show();
$('#product_discount').html(product.formatted_regular_price);
} else {
$('#product_discount').hide();
}
}
</script>
{% endput %}