Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. <button action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?> type="button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span>Comprar</span></span></button>
  2.  
  3. var productAddToCartForm = new VarienForm('product_addtocart_form');
  4. productAddToCartForm.submit = function(button, url) {
  5. alert("Entrou na função");
  6. if (this.validator.validate()) {
  7. var form = this.form;
  8. var oldUrl = form.action;
  9.  
  10. if (url) {
  11. form.action = url;
  12. }
  13. var e = null;
  14. //Start of our new ajax code
  15. if(!url){
  16. url = jQuery('#product_addtocart_form').attr('action');
  17. }
  18. alert("Redirecionamento");
  19. //url = url.replace("onestepcheckout/index","ajax/index/");
  20. var data = jQuery('#product_addtocart_form').serialize();
  21. data += '&isAjax=1';
  22. try {
  23. alert("Try");
  24. jQuery.ajax({
  25. url: url,
  26. dataType: 'json',
  27. type : 'post',
  28. data: data,
  29. success: function(data){
  30. alert(data.status + ": " + data.message);
  31. if(jQuery('.block-cart')){
  32. jQuery('.block-cart').replaceWith(data.sidebar);
  33. }
  34. if(jQuery('.header .links')){
  35. jQuery('.header .links').replaceWith(data.toplink);
  36. window.location.href = '<?php echo Mage::getUrl("onestepcheckout/index");?>';
  37. }
  38. }
  39. });
  40. } catch (e) {
  41. }
  42.  
  43. this.form.action = oldUrl;
  44. if (e) {
  45. throw e;
  46. }
  47.  
  48. if (button && button != 'undefined') {
  49. button.disabled = true;
  50. }
  51. }
  52. alert("Saindo...");
  53. }.bind(productAddToCartForm);
  54.  
  55. productAddToCartForm.submitLight = function(button, url){
  56. alert("Entrou no submitLight");
  57. if(this.validator) {
  58. var nv = Validation.methods;
  59. delete Validation.methods['required-entry'];
  60. delete Validation.methods['validate-one-required'];
  61. delete Validation.methods['validate-one-required-by-name'];
  62. if (this.validator.validate()) {
  63. if (url) {
  64. this.form.action = url;
  65. }
  66. this.form.submit();
  67. }
  68. Object.extend(Validation.methods, nv);
  69. }
  70. }.bind(productAddToCartForm);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement