In module's helper Template.php I'm setting session variable using below code

public function getCategoryAddtoLinksIcons($_product, $_compareUrl, $wrapperClasses = '')
    $html = '';

    if (Mage::helper('wishlist')->isAllow())
        $url = Mage::helper('wishlist')->getAddUrl($_product);
        $html .= '
        <li><a class="link-wishlist" onclick=socialLogin()>
                <span class="2 icon ib ic ic-heart"></span>
if (!empty($html))
        return '<ul class="add-to-links clearer ' . $wrapperClasses .'">' . $html . '</ul>';
    return $html;

and doing an ajax request to controller function where retriving session variable and unsetting it using

$wishlist_url = Mage::getSingleton('core/session')->getWishlistUrl();
Mage::log($wishlist_url, null, 'session.log');

But still I see, next time variable is set. Do I need to give timing also while setting/destroying session variable?


If you want to check, if this session variable is set, change

Mage::log($wishlist_url, null, 'session.log');


Mage::log(Mage::getSingleton('core/session')->getWishlistUrl(), null, 'session.log');
  • I see in controller it's being destroyed. I've logged $url = Mage::helper('wishlist')->getAddUrl($_product); in template and the value is again set there. Why so? – amitshree Dec 16 '15 at 18:57
  • 1
    You see this value in template, because template is generated before ajax request. – SeStro Dec 16 '15 at 19:41
  • Do you know of Magento way using which we can unset session variable automatically after some time? – amitshree Dec 17 '15 at 9:11
  • Are you sure, that you need session variable? You could set url as ajax request param. – SeStro Dec 17 '15 at 10:37
  • I was just curious about it. In case, I clicked on add to wishlist and ajax request is done to a controller with product info which needs to be added to wishlist, and in controller I'm setting same info to session. In case if customer doesn't logs in at the same time when clicking on 'add to wishlist' and logs in from different url(let's say login menu), it will redirect to wishlist page with adding product to wishlist. So it will be nice to set a session destroy time (maybe 2 seconds), so that when they click 'add to wishlist' in that case only session will be set. makes sense? – amitshree Dec 17 '15 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.