0

my module etc/modules/Minicart_Quick.xml

 <?xml version="1.0"?>
<config>
    <modules>
        <Minicart_Quick>
            <active>true</active>
            <codePool>local</codePool>
        </Minicart_Quick>
    </modules>
</config>

app/code/local/Minicart/Quick/etc/config.xml

   <?xml version="1.0"?>
  <config>
     <modules>
        <Minicart_Quick>
          <version>0.1.0</version>
        </Minicart_Quick>
     </modules>
     <frontend>
       <routers>
          <routeurfrontend>
              <use>standard</use>
              <args>
                 <module>Minicart_Quick</module>
                 <frontName>Quick</frontName>
              </args>
           </routeurfrontend>
       </routers>
    </frontend>
</config>

app/code/local/Minicart/Quick/controllers/minicartcontroller.php

    <?php
class Minicart_Custom_minicartcontroller extends Mage_Core_Controller_Front_Action{

    public function add_to_minicart()
{
    Mage::log("control get",null,"mini.log");
    $this->loadLayout();
    $layout = Mage::getSingleton('core/layout');
    $block = $layout->getBlock('cart_sidebar');
    $html = $block->toHtml();
    $this->getResponse()->setHeader('Content-type',
        'application/json')->setBody($this->_success($html));
    return $this;
}
}

Ajax function

function minicartAjax(){
var url = "<?php echo Mage::getUrl('quick/controllers/add_to_minicart');?>";
alert(url);
jQuery.ajax({
    url: url,
    dataType: 'json',
    success: function(data){
        //Your minicart html
        alert("hii");
    }
});

}

this is my updated code it's not working fine

1 Answer 1

0

Use below code in your controller

public function <Your-Action>()
{
    $this->loadLayout();
    $layout = Mage::getSingleton('core/layout');
    $block = $layout->getBlock('cart_sidebar');
    $html = $block->toHtml();
    $this->getResponse()->setHeader('Content-type',
        'application/json')->setBody($this->_success($html));
    return $this;
}

in your ajax success part

if(data.status=="SUCCESS"){
    jQuery("#success_message").html(data.message);
    minicartAjax();
    var qty = jQuery("#qty").val();
    var curqty = jQuery(".header-minicart .count").html();
    var newqty=parseInt(qty)+parseInt(curqty);
    jQuery(".header-minicart .count").html(newqty);
    //jQuery(".header-minicart .label").html('Cart ('+newqty+')');
}

new function

function minicartAjax(){
    $.ajax({
        url: <CustomController-Action-Url>,
        dataType: 'json',
        success: function(data){
            //Your minicart html
        }
    });
}

Reference

Find tutorial to create custom module-controller

9
  • can you explain it for me that can i add my action as "addtocart" as same in script function name and also in core file where this controller located
    – amith lal
    Mar 16, 2017 at 5:50
  • just create new controller and after success in ajax just call that action and get this data because alter the core code is not good practice @Amith Mar 16, 2017 at 5:58
  • so i can create a controller like this /app/code/local/name/name/controllers/CartController.php ?? is this work out for minicart product updation without reload page
    – amith lal
    Mar 16, 2017 at 6:02
  • @Amith find my updated answer Mar 16, 2017 at 6:07
  • how to get the custom controller url controller is located in "app/code/local/Minicart/Quick/controllers/minicartcontroller.php" and my action name is "add_to_minicart" i have tried to access the code like this "<?php echo $this->getUrl('Quick/controllers/add_to_minicart');?>" is this correct
    – amith lal
    Mar 16, 2017 at 7:13

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.