1

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);
        if(isset($url)){
            Mage::getSingleton('core/session')->setWishlistUrl($url);
        }
        $html .= '
        <li><a class="link-wishlist" onclick=socialLogin()>
                <span class="2 icon ib ic ic-heart"></span>
        </a></li>';
}
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::getSingleton('core/session')->unsWishlistUrl(); 
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?

0

1 Answer 1

1

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

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

to

Mage::log(Mage::getSingleton('core/session')->getWishlistUrl(), null, 'session.log');
5
  • 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, 2015 at 18:57
  • 1
    You see this value in template, because template is generated before ajax request.
    – SeStro
    Dec 16, 2015 at 19:41
  • Do you know of Magento way using which we can unset session variable automatically after some time?
    – amitshree
    Dec 17, 2015 at 9:11
  • Are you sure, that you need session variable? You could set url as ajax request param.
    – SeStro
    Dec 17, 2015 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, 2015 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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