Skip to content

Instantly share code, notes, and snippets.

@vitaly-zdanevich
Created May 6, 2016 17:44
Show Gist options
  • Save vitaly-zdanevich/85d890b452426bdace5587ed107ecc4b to your computer and use it in GitHub Desktop.
Save vitaly-zdanevich/85d890b452426bdace5587ed107ecc4b to your computer and use it in GitHub Desktop.
test code: checkout
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