In addition, I have added the following in addProductToRecent function:
$inputCookie = JFactory::getApplication()->input->cookie;
$inputCookie->set($name = 'vmlastvisitedproductids_cookie', $value = $products_ids, time() + (86400 * 30));
but when I try to retrieve this cookie it does not exist. Does anyone have an idea of the reason?