Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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>
- var productAddToCartForm = new VarienForm('product_addtocart_form');
- productAddToCartForm.submit = function(button, url) {
- alert("Entrou na função");
- if (this.validator.validate()) {
- var form = this.form;
- var oldUrl = form.action;
- if (url) {
- form.action = url;
- }
- var e = null;
- //Start of our new ajax code
- if(!url){
- url = jQuery('#product_addtocart_form').attr('action');
- }
- alert("Redirecionamento");
- //url = url.replace("onestepcheckout/index","ajax/index/");
- var data = jQuery('#product_addtocart_form').serialize();
- data += '&isAjax=1';
- try {
- alert("Try");
- jQuery.ajax({
- url: url,
- dataType: 'json',
- type : 'post',
- data: data,
- success: function(data){
- alert(data.status + ": " + data.message);
- if(jQuery('.block-cart')){
- jQuery('.block-cart').replaceWith(data.sidebar);
- }
- if(jQuery('.header .links')){
- jQuery('.header .links').replaceWith(data.toplink);
- window.location.href = '<?php echo Mage::getUrl("onestepcheckout/index");?>';
- }
- }
- });
- } catch (e) {
- }
- this.form.action = oldUrl;
- if (e) {
- throw e;
- }
- if (button && button != 'undefined') {
- button.disabled = true;
- }
- }
- alert("Saindo...");
- }.bind(productAddToCartForm);
- productAddToCartForm.submitLight = function(button, url){
- alert("Entrou no submitLight");
- if(this.validator) {
- var nv = Validation.methods;
- delete Validation.methods['required-entry'];
- delete Validation.methods['validate-one-required'];
- delete Validation.methods['validate-one-required-by-name'];
- if (this.validator.validate()) {
- if (url) {
- this.form.action = url;
- }
- this.form.submit();
- }
- Object.extend(Validation.methods, nv);
- }
- }.bind(productAddToCartForm);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement