"Add to cart" button doesn't work because of ReferenceError
I have an "Add to cart" button in my Magento theme, I haven't edited it
but it stopped working. It defenitely worked some time ago and
unfortunately I didn't catch the moment when things went wrong. When I'm
pressing the button nothing happens in frontend and I see the error
"Uncaught ReferenceError: productAddToCartForm is not defined" in console.
Here is the button HTML:
<button class="button btn-cart" title="Äîáàâèòü â êîðçèíó" type="button"
onClick="productAddToCartForm.submit(this)"><i
class="icon-basket"></i>Äîáàâèòü â êîðçèíó</button>
However, when I look at page source, the script is in the page:
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
<?php if(Mage::getStoreConfig('buyshopconfig/options/ajax_add_to_cart')){?>
productAddToCartForm.submit = function(button, url) {
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');
}
url = url.replace("checkout/cart","ajax/index"); // New Code
var data = jQuery('#product_addtocart_form').serialize();
data += '&isAjax=1';
jQuery('#preloader .loader').fadeIn(300);
try {
jQuery.ajax( {
url : url,
dataType : 'json',
type : 'post',
data : data,
success : function(data) {
jQuery('#ajax_loader').hide();
if(data.status == 'ERROR'){
alert(data.message);
}else{
jQuery('#preloader .loader').hide();
if(jQuery('.ul_wrapper.toplinks')){
jQuery('.shoppingcart').replaceWith(data.sidebar);
}
jQuery(".shoppingcart .fadelink").bind({
mouseenter: function(e) {
jQuery(this).find(".shopping_cart_mini").stop(true,
true).fadeIn(300, "linear");
},
mouseleave: function(e) {
jQuery(this).find(".shopping_cart_mini").stop(true,
true).fadeOut(300, "linear");
}
});
if(jQuery('#topline .links')){
jQuery('#topline
.links').replaceWith(data.toplink);
}
jQuery('#preloader .inside').html('Òîâàð
"'data.name+'" áûë äîáàâëåí â âàøó êîðçèíó');
jQuery('#preloader .message').fadeIn(300);
setTimeout(function(){
jQuery('#preloader .message').fadeOut();
},1500)
}
}
});
} catch (e) {
}
// End of our new ajax code
this.form.action = oldUrl;
if (e) {
throw e;
}
}
}.bind(productAddToCartForm);
<?php }else { ?>
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
<?php } ?>
productAddToCartForm.submitLight = function(button, url){
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'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
<?php if(!Mage::helper('lightboxes')->isActive()):?>
jQuery("a.video").click(function() {
jQuery.fancybox({
'padding' : 0,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'title' : this.title,
'width' : 680,
'height' : 495,
'href' : this.href.replace(new RegExp("watch\\?v=", "i"),
'v/'),
'type' : 'swf',
'swf' : {
'wmode' : 'transparent',
'allowfullscreen' : 'true'
}
});
return false;
});
<?php endif;?>
//]]>
Could anyone give the answer what is the problem with this function?
You can reproduce the error on
http://koketka-online.ru/index.php/women/sumka-jimmi-choo-belaya.html
page.
ReplyDeleteIt seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. keep it up!!
ReplyDeleteandroid training in chennai
android online training in chennai
android training in bangalore
android training in hyderabad
android Training in coimbatore
android training
android online training