husseycoding / ajaxcartpopup

3 stars 10 forks source link

Cart items count not being updated #25

Closed djordje-petrovic closed 8 years ago

djordje-petrovic commented 8 years ago

Hi. Thanks for this great extension. I've managed to integrate it successfully with my custom theme. However there is a small issue of items count for minicart in header. It's not being update at all. Relevant excerpt from my header.phtml looks like this:

<?php
    $_cartQty = $this->getSummaryCount();
    if(empty($_cartQty)) {
        $_cartQty = 0;
    }
?>

<div id="korpa">
<a href="<?php echo $this->helper('checkout/cart')->getCartUrl(); ?>" data-target-element="#header-cart" class="skip-link skip-cart" <?php if($_cartQty <= 0): ?> no-count<?php endif; ?>">
    <span class="icon"></span>
    <span class="label"><i class="fa fa-cart-arrow-down fa-2x"></i></span>
    <span class="count"><?php echo $_cartQty; ?></span>
</a>
</div> 

I've read all in Issue #21 where user had the similar issue but there is not a hint how to solve this?

husseycoding commented 8 years ago

The extension doesn't generate a product count for the header link, it renders the links html, and then strips out the contents of the link element and updates this on the page. If you are not seeing this updating it might be that the contents of the skip-cart anchor element is not rendering correctly.

djordje-petrovic commented 8 years ago

Ok. I can see json key linktext is always null. This means there is no output from this regex line:

preg_match('/<a.+skip-cart.+>(.+)<\/a>/Us', $cartlink, $linktext);

Right?

husseycoding commented 8 years ago

You want to be looking at the _getLinkText() method here.

djordje-petrovic commented 8 years ago

Yes, I'm aware, the line above is from that function exactly. Could you please just confirm what I've asked in the previous post? Please bear with me for this. If my cart link html is like this:

<a href="http://localhost/magento/index.php/checkout/cart/" data-target-element="#header-cart" class="skip-link skip-cart"> <span class="label"><i class="fa fa-cart-arrow-down fa-2x"></i></span> <span class="count">1</span> </a>

Preg_matchs should output something like:

<span class="label"><i class="fa fa-cart-arrow-down fa-2x"></i></span> <span class="count">0</span>

which should be in $linktext. Correct?

husseycoding commented 8 years ago

You can very easily determine what is output for your store by adding a breakpoint into that method to allow you to inspect the contents of $linktext in your IDE, or just put the values into something like this. Remember that array key 1 is returned. not 0.

djordje-petrovic commented 8 years ago

Actually the code snippet I've posted is from one those generators :) Anyway I've solved my problem. It was just a block name I had to change in _getLinkText(). Thank you for your help. You may close the issue.

husseycoding commented 8 years ago

Ok great, thanks for the update.