Well, finally it was really easy... But in fact I have lost almost one week searching the issue of this problem.
It seems that even if you will precise the tax %, in the tax rules, and you will chose tax class "Normal", the same for the product, it will not add tax to your product. It will without tax.
You have to choose tax class Shipping, for tax rule and product. And after that all works like a charm.
$( '#cartqty' ).html('<?php echo $this->helper('checkout/cart')->getSummaryCount(); ?>'); not ajax call .
Call an ajax
on button click
to new url.
Get data from that New Url.so you need to new Action on exit any controller
or create new controller and get data
.
<script>
$( '.product-add-btn' ).click(function() {
new Ajax.Request(url, {
method:'get',
onLoading:function(){ },
onSuccess: function(transport) {
if (200 == transport.status){
var response = transport.responseText.evalJSON( );
$( '#cartqty' ).html(response.count );
}else{
alert('Something went wrong...');
}
},
onFailure: function() { alert('Something went wrong...'); }
});
});
</script>
Need to create a controller by create new module:
<?php
class Amit_Custommodule_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$this->helper('checkout/cart')->getSummaryCount();
$result=array();
$result['count']=this->helper('checkout/cart')->getSummaryCount();
$this->getResponse()->setHeader('Content-type','application/json',true);
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
Full module:
- First of all create module control file Module name as
Amit_Custommodule.xml at app/etc/modules/
.
Code:
<?xml version="1.0"?>
<config>
<modules>
<Amit_Custommodule>
<codePool>community</codePool>
<active>true</active>
</Amit_Custommodule>
</modules>
</config>
- Path Of
config.xml
is app/code/community/Amit/Custommodule/etc
Code:
<?xml version="1.0" ?>
<config>
<modules>
<Amit_Custommodule>
<version>1.0.0</version>
</Amit_Custommodule>
</modules>
<frontend>
<routers>
<custommodule>
<use>standard</use>
<args>
<module>Amit_Custommodule</module>
<frontName>custommodule</frontName>
</args>
</custommodule>
</routers>
</frontend>
</config>
- IndexController.php path is
app/code/community/Amit/Custommodule/controllers/
Code:
<?php
class Amit_Custommodule_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$result=array();
$result['count']=Mage::helper('checkout/cart')->getSummaryCount();
$this->getResponse()->setHeader('Content-type','application/json',true);
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
And script:
<script>
$( '.product-add-btn' ).click(function() {
new Ajax.Request('<?php echo $this->getUrl("custommodule/index/index")?>', {
method:'get',
onLoading:function(){ },
onSuccess: function(transport) {
if (200 == transport.status){
var response = transport.responseText.evalJSON( );
$( '#cartqty' ).html(response.count );
}else{
alert('Something went wrong...');
}
},
onFailure: function() { alert('Something went wrong...'); }
});
});
</script>
Best Answer
This is how i solve this problem:
in my block:
after this in my phtml i used this funcitons like this $block->function();