Skip to main content
Tweeted twitter.com/#!/StackMagento/status/541331384850460672
added 6 characters in body
Source Link
benmarks
  • 16.7k
  • 4
  • 41
  • 108

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'));

    $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{ 
     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?.

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?.

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?.

Source Link
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?.