Magento add to cart product with custom options by Ajax


 
 

        
        

Add product to cart from any page of magento by Ajax
get the custom option ids from admin panel by inspecting html elements

// load product by id
load(1);  ?>

jQuery("#buy_now").click(function(){
	
	    var urls = 'getAddUrl($_pro) ?>';
            // radio custom options
            var txt = jQuery('.color_pro:checked').val();
            var cov = jQuery('.cover_pro:checked').val();
            
            if (txt !== '') {
                    jQuery('#pro_pop').html('Loading... Please Wait');

                    jQuery.ajax({
                        type:"POST",
                        data:{qty:1, options:{"2":txt, "1":cov} },
                        url:urls
                    }).done(function (msg) {
                        setLocation('getBaseUrl() ?>checkout/cart/');
                    });

                } else {
                    jQuery('#pro_pop').html('Select Options');

                }

			 
	});


Posted

in

by

Tags: