I am unable to get summary count with php code when cache is enable.
I used below code.
<?php
$helper = $this->helper('\Magento\Checkout\Helper\Cart');
echo $helper->getSummaryCount();
?>
You can't with cache enabled, all files aren't re-interpreted.
You should get it with javascript. You can try to add the following code in your phtml file (the following example is to show you the way) :
<script type="text/javascript">
require([
'Magento_Customer/js/customer-data'
], function (customerData) {
'use strict';
customerData.get('cart').subscribe(function (cartInfo) {
console.log(cartInfo['summary_count']);
}, this);
});
</script>
This code will print nothing where there isn't product in cart, and cart count when there is products.
It will be triggered every times that the cart is updated.
$this->helper('\Magento\Checkout\Helper\Cart');
you should try it$this->helper(Magento\Checkout\Helper\Cart::class);
make sure clearing cache after making this change.