This commit is contained in:
Shohrat 2023-06-20 19:29:53 +00:00
commit a9cf360430
4 changed files with 42 additions and 61 deletions

View File

@ -84,6 +84,8 @@ function onStart(){
{% framework extras %}
{% partial 'scripts/addToCart' token=nurgulToken %}
{% scripts %}
</body>

View File

@ -1,68 +1,47 @@
{% put scripts %}
<script>
$('#loader_form').hide();
function login() {
$('#loader_add').hide();
function addToCart(prodId, qty) {
var phone = document.getElementsByName("phone")[0].value;
var pass = document.getElementsByName("password")[0].value;
var deviceName = 'from Web';
// var fd = new FormData();
// fd.append('phone', phone);
var fd = new FormData();
fd.append('phone', phone);
fd.append('password', pass);
fd.append('device_name', deviceName);
var product = {};
product.product_id = prodId;
product.quantity = qty;
console.log('{{token}}');
console.log(prodId);
console.log(qty);
console.log(JSON.stringify(product));
$.ajax({
url: 'https://nurgul.com.tm/app/api/customer/login',
data: fd,
url: 'https://nurgul.com.tm/app/api/customer/cart/add/' + prodId,
data: JSON.stringify(product),
processData: false,
contentType: false,
type: 'POST',
beforeSend: function () {
$('#loader_form').show();
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer {{token}}');
xhr.setRequestHeader('Content-Type', 'application/json');
$('#loader_add').show();
},
success: function (data) {
$('#loader_form').hide();
console.log(data);
console.log(data.data.name);
console.log(data.token);
// onSetData(data.token, data.data.name, data.data.phone);
$('input[name=token]').val(data.token);
$('input[name=name]').val(data.data.name);
$('input[name=phone]').val(data.data.phone);
var link = document.querySelector('#testq');
if(link) {
link.click();
}
// $(document).on(function () {
// $(this).request('onSetSessionNurgul', { data: { token: 'someVar' } });
// });
// $(this).request('onSetSession', {
// data: { nurgulToken: data.token }
// });
// $(this).request('onSetSession', {
// data: { nurgulToken: data.token, name: data.data.name, phone: data.data.phone }
// });
oc.flashMsg({
message: "{{'added.cart.success'|_}}",
type: 'success',
interval: 3
});
},
error: function (data) {
$('#loader_form').hide();
dataq = JSON.parse(data.responseText);
// console.log(dataq);
for (var error of dataq.errors) {
$('#errors').append(`<a href="#" style="padding-bottom: 15px;"><small style="color: darkred;font-weight: bold;background: #ff8888;padding: 10px;border-radius: 5px;"> * ` + error + `</small></a>`);
}
// console.log(dataq.errors);
console.log(data);
}
});
}
</script>
{% endput %}
{% endput %}

View File

@ -42,7 +42,7 @@
</a>
</li>
<li class="add-to-cart">
<a ` + ('{{nurgulToken}}' == "" ? `href='/login'` : `href='javascript:;' onClick='addToCart(`+product.id+`)'`) + ` title="Add to Cart" >
<a ` + ('{{nurgulToken}}' == "" ? `href='/login'` : `href='javascript:;' onClick='addToCart(`+product.id+`,`+`1`+`)'`) + ` title="Add to Cart" >
<span class="cart-text d-none d-xl-block">{{add}}</span>
<span class="d-block d-xl-none"><i class="icon-handbag"></i></span>
</a>

View File

@ -1,19 +1,19 @@
{% put scripts %}
<script>
function setModal(product){
$('#modal_img').html(`<img src="`+product.images[0].original_image_url+`" alt="Nurgul `+ product.name +`">`);
$('#modal_name').html(product.name);
$('#modal_price').html(product.formatted_price);
$('#modal_desc').html(product.description);
$('#modal_add').html('{{add}}');
if(product.hasOwnProperty('special_price')){
$('#modal_discount').show();
$('#modal_discount').html(product.formatted_regular_price);
}else{
$('#modal_discount').hide();
}
<script>
function setModal(product) {
$('#modal_img').html(`<img src="` + product.images[0].original_image_url + `" alt="Nurgul ` + product.name + `">`);
$('#modal_name').html(product.name);
$('#modal_price').html(product.formatted_price);
$('#modal_desc').html(product.description);
$('#modal_add').html('{{add}}');
if (product.hasOwnProperty('special_price')) {
$('#modal_discount').show();
$('#modal_discount').html(product.formatted_regular_price);
} else {
$('#modal_discount').hide();
}
</script>
}
</script>
{% endput %}