Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Ajax add to cart is not updating the product to the shopping cart upon onclick action checkout/continue in the popup and then it redirects to the URL
 
sureshkantharaj
Jr. Member
 
Total Posts:  4
Joined:  2013-09-04
 

<b>Ajax add to cart is not updating the product to the shopping cart upon onclick action checkout/continue in the popup and then it redirects to the URL http://hostip.com/checkout/cart/ </b>

My javascript code

<script type="text/javascript">
    function 
setAjaxData(data,iframe){
            
if(data.status == 'ERROR'){
                alert(data
.message);
            
}else{
                
if(jQuery('.block-cart')){
                    jQuery
('.block-cart').replaceWith(data.sidebar);
                
}
    
//            if(jQuery('.header .links')){
    //                jQuery('.header .links').replaceWith(data.toplink);
    //            }
                
if(jQuery('.cart-top-container')){
                    
//jQuery('.cart-top-container').empty();
                    
jQuery('.cart-top-container').replaceWith(data.toplink);
                
}
                
var targetUrl='<?php echo Mage::getUrl('onestepcheckout') ?>';
                
jQuery"#dialog-confirm" ).dialog({
                    resizable
false,
                    
//height:140,
                    
modaltrue,
                    
buttons{
                        
"Checkout": function() {
                            [removed]
.href targetUrl;
                            
//jQuery(this).dialog( "close" );
                        
},
                        
"Continue Shopping": function() {
                            jQuery
(this).dialog"close" );
                        
}
                    }
                }
);
            
}
        }
        
function setLocationAjax(url,id){
            url 
+= 'isAjax/1';
            
url url.replace("checkout/cart","ajax/index");
            
jQuery('#ajax_loader'+id).show();
            try 
{
                jQuery
.ajax{
                    url 
url,
                    
dataType 'json',
                    
success : function(data{
                        jQuery
('#ajax_loader'+id).hide();
                        
setAjaxData(data,false);          
                    
}
                }
);
            
catch (e{
            }
        }
    </script>

<b>My form to submit</b>

<form action="<?php echo $this->getSubmitUrl($p) ?>" method="post" id="product_addtocart_form"<?php if ($p->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
                        <
div class="home-prouduct-details">
                            
<?php $pid $p->getId(); ?>
                            <?php $prod 
Mage::getModel('catalog/product')->load($pid);  ?>
                            <?php $html
$prod->getShortDescription(); ?>
                            <?php                          
                               $str 
$html;
                               
$matches = array();
                               
preg_match_all('#<div[^>]*>(.*?)</div>#'$str$matches);
//                               print_r($matches[1][0]);
                            
?>
                            
<class="prod-name" href="<?php echo $prod->getProductUrl(); ?>"><?php echo $prod->getName(); ?></a>
                            <
div class="prod-img">
                                <
a href="<?php echo $prod->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($prod, 'small_image'), null, true) ?>" class="product-image">
                                    <
img src="<?php echo $this->helper('catalog/image')->init($prod, 'small_image')->resize(285,172); ?>" width="285" height="175" alt="<?php echo $this->stripTags($this->getImageLabel($prod, 'small_image'), null, true) ?>" />
                                </
a>
                            </
div>
                            <
div class="home-price-button">
                                
<?php $almost_gone_qty=$this->htmlEscape($prod->getData('almost_gone_qty')); ?>
                                <?php $qtyStock 
Mage::getModel('cataloginventory/stock_item')->loadByProduct($prod)->getQty(); ?>
                                <?php 
if (!$this->hasOptions() && strtotime($prod->getDealEndDate())>= Mage::getModel('core/date')->timestamp(time())):?>
                                    
<div style="clear:both;"></div>
                                    <
div class="add-to-box">
                                        
<?php if($prod->isSaleable() && $qtyStock $almost_gone_qty){ ?>
                                            
<class="availability out-of-stock">
                                                <
a onclick="setLocationAjax('<?php echo Mage::helper('checkout/cart')->getAddUrl($prod); ?>',<?php echo $prod->getId();?>)" title="Add To Cart">
                                                    <
img src="<?php echo $this->getSkinUrl('images/steamy.png'); ?>" title="Add To Cart" alt="Add To Cart" width="285" />
                                                </
a>
                                            </
p>
                                            
<?php } else if($qtyStock <= $almost_gone_qty && $qtyStock!=0){?>
                                                
<class="availability out-of-stock">
                                                    <
a onclick="setLocationAjax('<?php echo Mage::helper('checkout/cart')->getAddUrl($prod); ?>',<?php echo $prod->getId();?>)" title="Almost Gone">
                                                        <
img src="<?php echo $this->getSkinUrl('images/almostgone.png'); ?>" title="Almost Gone" alt="Almost Gone" width="285" />
                                                    </
a>
                                                </
p>
                                            
<?php } else{ ?>
                                                
<class="availability out-of-stock">
                                                    <
a href="<?php echo Mage::getBaseUrl(); ?>sold-out" title="Sold Out">
                                                        <
img src="<?php echo $this->getSkinUrl('images/soldout.png'); ?>" width="285" /><?php //echo $this->__('Out of stock') ?>
                                                    
</a>
                                                </
p>
                                            
<?php } ?>
                                            
<span id='ajax_loader<?php echo $prod->getId()?>' style='text-align: center; display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>
                                    </
div>                                    
                                
<?php else : ?>
                                    
<class="deal-has-ended">
                                        <
a href="<?php echo Mage::getBaseUrl(); ?>sold-out" title="Sold Out">
                                            <
img src="<?php echo $this->getSkinUrl('images/deal_ended.png'); ?>" width="285" />
                                        </
a>
                                    </
p>                                
                                
<?php endif; ?>
                                    <?php 
echo $this->getChildHtml('addto'?>
                                    <?php 
//echo $this->getChildHtml('extra_buttons') ?>
                            
</div>
                            <
div class="home-price">
                                <
div class="home-prices">
                                    
<?php 
                                        
echo Mage::helper('core')->currency($prod->getPrice());
                                    
?>    
                                
</div>
                                
<?php if($matches[1][1] !=""){ ?>
                                    
<div class="home-save">
                                        
<?php
                                            $savings 
$matches[1][1];
                                            
$savings str_ireplace('Rs.''&#8377;'$savings);
                                            
$savings str_ireplace('Rs''&#8377;'$savings);
                                            echo 
$savings;
                                        
?>
                                        <?php 
//print_r($matches[1][1]); ?>
                                        
<div class="home-saver">
                                            
savings
                                        
</div>
                                    </
div>
                                
<?php } ?>
                                
<div class="deal-endtime"
                                    
<?php 
                                                    
echo "<div id='cdcontainer_".$prod->getId()."' class='cdcontainer'></div>";
                                                    
$dealEndDate $prod->getDealEndDate();
                                                    
$dealEndDateParts explode(" "$dealEndDate);
                                                    
$targetDateParts explode("-"$dealEndDateParts[0]);
                                                    
$year $targetDateParts[0];
                                                    
$month $targetDateParts[1];
                                                    
$date $targetDateParts[2];

                                                    
$month_array = array(
                                                            
"January""February""March""April""May""June""July""August""September""October""November""December"
                                                    
);
                                                    
$month $month_array[$month-1];

                                                    
$targetDate "$month $date$year ".$dealEndDateParts[1];
                                                    
$timer_text Mage::getStoreConfig('homedeals/basic_settings/cd_display_text');
                                                    
$timer_end_text Mage::getStoreConfig('homedeals/basic_settings/cd_end_text');     
                                                    
//echo $timer_end_text;
                                                    //echo date("Y-m-d H:i:s"); echo "<br/>";
                                                    //echo $dealEndDate;
                                                    
if($dealEndDate <= date("Y-m-d H:i:s")){
                                                    ?>
                                                    
<script type="text/javascript">
                                                            var 
launchdate_<?php echo $prod->getId(); ?>=new cdLocalTime("cdcontainer_<?php echo $_product->getId(); ?>""server-php"0"""""<?php echo '<span><h1 style=color:red;>Deal has ended - 00:00:00</h1></span>' ?><?php //echo $timer_text; ?>""<?php echo $timer_end_text; ?>""<?php echo $prod->getId(); ?>");
                                                            
launchdate_<?php echo $prod->getId(); ?>.displaycountdown("hours"formatresults2);
                                                    
</script>
                                                    <?php   }else { ?>
                                                    
<script type="text/javascript">
                                                            var 
launchdate_<?php echo $prod->getId(); ?>=new cdLocalTime("cdcontainer_<?php echo $prod->getId(); ?>""server-php"0"<?php echo $targetDate?>""<?php print date("F dY H:i:s", Mage::getModel('core/date')->timestamp(time()))?>""<?php echo $timer_text; ?>""<?php echo $timer_end_text; ?>""<?php echo $prod->getId(); ?>");

                                                            
launchdate_<?php echo $prod->getId(); ?>.displaycountdown("hours"formatresults2);
                                                    
</script>
                                                    <?php } ?>
                                
</div>
                            </
div>
                        </
div>
                        <
div id="dialog-confirm" style="display:none;">
                            
<?php echo $prod->getName();?> added to your cart Successfully.
                        </
div>
                        </
form>
 
Magento Community Magento Community
Magento Community
Magento Community
 
GoMageTeam
Guru
 
Avatar
Total Posts:  356
Joined:  2013-01-13
Warsaw, Poland
 

Hello,

The reason that there is no Ajax updating of the product while adding to cart can be a compatibility conflict with a custom theme or with any third party extension.

You can contact support@gomage.com and the developers will help you to investigate the issue.
Also, we can suggest you two wonderful extensions for the shopping cart and the checkout page:

https://www.gomage.com/extensions/procart.html and

https://www.gomage.com/extensions/gomage-lightcheckout.html

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top