I’ve actually struggled with this a bit in the past so if anybody has a better solution than these, please chime in!
Presumably, you want the # of items in your cart to update on ajax requests, which will use one of the CartBox handlers and return the template’d partials in fetchPartials
https://github.com/tastyigniter/ti-ext-cart/blob/master/components/CartBox.php#L127. If all you want to display is one of those partials already, then you’re golden. If not, then -
hacky solution #1 -
If your theme isn’t using one of template partials in that function, you can replace the partial in your theme with the data you need as a cart count (and just call it #tip_box or what have you). This is only possible if you aren’t already using all the other fields though, so
hacky solution #2 -
Listen for ajax responses in javascript with something like
$(document).ajaxComplete(function(event, xhr, settings) { // read data and update your cart counter here });
The only non-hacky way to do this that I’ve found (so this is solution #3) is to create your own extension along side the theme, create and register a component called newCartBox
or whatever, have the new component class extend \Igniter\Cart\Components\CartBox
, override the fetchPartials()
method so that it returns a new data field for cart count, and then in your theme, instead of instantiating cartBox
you instantiate newCartBox
.
Sorry for the long response there! As you can probably guess, I have run into this problem as well and am eagerly hoping that somebody else chimes in with a much simpler and more obvious solution that I’m missing.