derm_oct/themes/dagdan/partials/scripts/newProd.htm

39 lines
1.4 KiB
HTML

{% put scripts %}
<script>
getNewProducts('{{query}}', '{{limit}}');
// console.log("qqq");
function getNewProducts(query, limit) {
console.log(query);
$(document).ready(function () {
$.ajax({
url: `http://216.250.11.229/derman/app/api/products?`+query+`{{activeLocale}}&limit=`+limit,
type: 'GET',
dataType: 'json',
beforeSend: function () {
$('#products_{{id}}').hide();
$('#loader_{{id}}').show();
},
success: function (data, textStatus, xhr) {
$('#loader_{{id}}').hide();
$('#products_{{id}}').show();
// console.log(data.data);
var products = data.data;
for (var product of products) {
// console.log(product.hasOwnProperty('special_price'));
$('#products_{{id}}').append(`{% partial 'product/card' url="/product/`+product.id+`" name="` + product.name+`" price="`+ product.formatted_price +`" category="`+ product.shop_title +`" img="`+product.images[0].original_image_url+`" product_id="`+ product.id +`" %}`);
}
},
error: function (xhr, textStatus, errorThrown) {
console.log('Error in Operation');
}
});
});
}
</script>
{% endput %}