Skip to main content
1 of 2
Rat
  • 834
  • 13
  • 28

Magento set Cookie?

We need to show recently viewed product by customer based on browser and i try to below code.

$cookie = Mage::getSingleton('core/cookie'); if($cookie->get('recent_product')){ $recent_product=$cookie->get('recent_product'); $Current_prd= explode(",",$cookie->get('recent_product'));

        if(!in_array($productId, $Current_prd)){
            $recent_product=$recent_product.",".$productId;   
        }
        # $cookie->get('recent_product');
        $cookie->set('recent_product', $recent_product ,time()+86400,'/');
    }else{ 
       
        $recent_product =array();
        $recent_product=$productId;
        $cookie = Mage::getSingleton('core/cookie');
        $cookie->set('recent_product',$recent_product ,time()+86400,'/');
    }

It is set the cookie. But when i close the browser, not able to get the previous cookie value.

What i missing the above code?.

Rat
  • 834
  • 13
  • 28