0

I am making a Free Shipping top bar, i have added code in header.phtml which is located in app/design/frontend/mytheme/mytheme05/template/page/html/header.phtml

My Code is :

<div id= "um" class="container" style="text-align: center; font-weight: bold; ">
<?php

$grand= $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); 

$count = (int) filter_var($grand, FILTER_SANITIZE_NUMBER_INT);

$umer= 1500;
$total= $umer-$count;
if ($count < $umer)
{
    echo "Free Shipping on $total";
}

else 
    echo "Free Shipping Enjoy"; 
//var_dump($count)

?>

I want to refresh this div when Add to cart Button is press.

The code is located in :

app/design/frontend/mytheme/mytheme05/template/magiccart/magicproduct/product/grid.phtml

Code is here`

<div class="actions-cart">
<?php if(in_array("cart", $actions)):?>
    <?php if($_product->isSaleable()): ?>
        <button type="button" title="<?php echo $this->__('Add to cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Umer') ?></span></span></button>
    <?php else: ?>
        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
    <?php endif; ?>
<?php endif; ?>

I want to refresh that div on onclick Button.

How I can do this ?

This is the Header which I want to update. It is working fine if I refresh the page

2
  • The better is to do it with Ajax, now you want to do it with Ajax or even if you reload the page does not bother you ?
    – PЯINCƎ
    Jul 5, 2017 at 22:34
  • Can you please tell me how I can do with this Ajax
    – Umer
    Jul 5, 2017 at 23:05

1 Answer 1

0

If you want to do this on reload the page, you have to add location.reload(); on onclick add to cart button, But i confirm that the best way is to do it with AJAX

For the product page for exemple:

app/design/frontend/{package}/{theme}/template/catalog/product/view/addtocart.phtml

<button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="btn-cart btn btn-primary btn-sm" onclick="productAddToCartForm.submit(this); location.reload();"><?php echo $buttonTitle ?></button>

With Ajax :

function reload(url){
       $.get(url, function(data){      // $.get will get the content of the page defined in url and will return it in **data** variable 
            $('#row').append(data);
       }
    }

$('.button.btn-cart').click(function(e){ 
        e.preventDefault();
        var url = 'http://example.com/somepage.html';
        reload(url);  // this calls the reload function
});

Reference

Or you can do some load() function something like :

$("#myDiv").load(location.href+" #myDiv>*","");

Reference

3
  • I want to only refresh that free shipping part which is in header instead of whole page
    – Umer
    Jul 5, 2017 at 23:20
  • Look my update please
    – PЯINCƎ
    Jul 6, 2017 at 0:35
  • you're welcome ;)
    – PЯINCƎ
    Jul 7, 2017 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.