Reputation: 346
I have enabled secure cart in our magento. After that, add to cart buttons were not working. My theme has custom ajax add-to-cart buttons. Then I added following code in my template js code and add to cart button of product list page started working. But, i could not figure out how i should change the add-to-cart button code of product view(detail) page as it's not working too. I need them with my secure cart. My product detail page is under http protocol. If I manually enter product detail page with https, the add to cart button works. But, I need it working under http product detail page and works functional with secure cart page. How should I change the javascript code or any other code?
My code
if (window.location.protocol == "https:") {
url=url;
}else{
url=url.replace("https://","http://");
}
My theme: http://demo.galathemes.com/#gala-gearbox
Here is theme javascript code that's doing this job:
var test;
Event.observe(window, 'load', function () {
var containerDiv = $('containerDiv');
if(containerDiv)
test = new LightboxAJC(containerDiv);
});
function cart_form(url)
{
data = $('product_addtocart_form').serialize();
ajax_add(url,data);
}
function ajax_add(url,param)
{
tam = url.search("checkout/");
tam2 = url.search("product/");
str1 = url.substr(0,tam)+'ajaxcart/index/add/';
str2 = url.substr(tam2,url.length);
link = str1+str2;
var check = url.search("options");
if(check > 0){
window.location.href = url;
}
else{
var tmp = url.search("in_cart");
test.open();
new Ajax.Request(link, {
parameters:param,
onSuccess: function(data) {
if(tmp > 0 ) {
var host = find_host(url);
window.location.href = host+'index.php/checkout/cart/';
}
else{
//result = data.responseText;alert(result);
$('ajax_content').innerHTML = data.responseText;
if($('ajax_content').down('.top-link-cart')){
var count_cart = $('ajax_content').down('.top-link-cart').innerHTML;
$$('.top-link-cart').each(function (el){
el.innerHTML = count_cart;
});
}
if($('ajax_content').down('.block-cart')){
var ajax_product = $('ajax_content').down('.block-cart').innerHTML;
$$('.block-cart').each(function (el){
el.innerHTML = ajax_product;
});
}
if($('ajax_content').down('.col-main')){
var ajax_result = $('ajax_content').down('.col-main').innerHTML;
$$('.ajaxcart_row1').each(function (el){
el.innerHTML = ajax_result;
});
}
$('ajax_loading').hide();
$('ajaxcart_conent').show();
Event.observe('closeLink', 'click', function () {
test.close();
$$('.ajaxcart_row1').each(function (el){
el.innerHTML = '';
});
$('ajax_loading').show();
});
}
}
});
}
}
function setLocation(url){
if (window.location.protocol == "https:") {
url=url;
}else{
url=url.replace("https://","http://");
}
var tam = url.search("checkout/cart/");
if(tam > 0) ajax_add(url);
else window.location.href = url;
}
document.observe("dom:loaded", function() {
var cartInt = setInterval(function(){
if (typeof productAddToCartForm != 'undefined'){
if(test){
var tam = $('product_addtocart_form').serialize();
var check = tam.search("ajaxcart");
if(check < 0){
productAddToCartForm.submit = function(url){
if(this.validator && this.validator.validate()){
cart_form($('product_addtocart_form').readAttribute('action'));
clearInterval(cartInt);
}
return false;
}
}
}
} else {
clearInterval(cartInt);
}
},500);
});
function find_host(url)
{
var tmp = url.search("index.php");
var str = url.substr(0,tmp)
return str;
}
Upvotes: 0
Views: 7710
Reputation: 346
This is the solution that works for all pages! It's very simple..
if (window.location.protocol == "http:") {
url=url.replace("https://","http://");
}
Upvotes: 1