Created
May 6, 2016 17:44
-
-
Save vitaly-zdanevich/85d890b452426bdace5587ed107ecc4b to your computer and use it in GitHub Desktop.
test code: checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkout(e) { | |
var subject = ''; | |
if($('.pav-shop-cart').length > 0){ //if on checkout page | |
var city = $('#checkout-cart #city').val(); | |
var name = $('#checkout-cart [name=name]').val(); | |
var phone = $('#checkout-cart [type=tel]').val(); | |
var email = $('#checkout-cart [type=email]').val(); | |
var address = $('#checkout-cart #address').val(); | |
var comment = $('#checkout-cart textarea').val(); | |
subject = 'Заказ со страницы корзины'; | |
} else { //fastcart | |
var name = $('#nameFastcart').val(); | |
var phone = $('#phoneFastcart').val(); | |
subject = 'Заказ из быстрой корзины'; | |
} | |
if(validatePhone(phone)){ | |
var products = []; | |
$('#cart table tr').each(function(){ | |
var product = new Object(); | |
product.product_id = $(this).attr('id'); | |
product.quantity = $(this).find('[type=text]').val(); | |
product.warranty = new Boolean($(this).find('[type=checkbox]').attr('checked')); | |
products.push(product); | |
}) | |
$.post('index.php?route=module/checkout/checkout', { | |
products:JSON.stringify(products), | |
city:city, | |
name:name, | |
phone:phone, | |
email:email, | |
address:address, | |
comment:comment, | |
subject:subject, | |
useragent:navigator.userAgent | |
}, function() { | |
toastr.success('Спасибо, ваш заказ отправлен, скоро мы свяжемся с вами'); | |
Cookies.remove('PHPSESSID'); | |
if($('.pav-shop-cart').length > 0) | |
setTimeout(function(){ //if checkout page | |
window.location.replace('/'); | |
}, 3000); | |
else clearCart(); | |
}).fail(function(){ | |
toastr.error('Ошибка при отправке заказа,<br>пожалуйста позвоните нам'); | |
}); | |
if(e) e.preventDefault(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment