Şahin YILDIZ Posted April 1, 2013 Share Posted April 1, 2013 (edited) PrestaShop Superstar : excerpt This is not an easy thing to do, but I've tried to come up with a solution anyway. Download the attached file, then put viewed.php in Prestashop's root directory and viewed.tpl in your chosen theme's directory. You will also need to change the getProducts function in classes/Category.php to below code. Once you've done this, you can go to viewed.php in your root directory to see the viewed products on a separate page. public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $viewed = false) { global $cookie;[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] if ($p < 1) $p = 1; if (empty($orderBy)) $orderBy = 'position'; if (empty($orderWay)) $orderWay = 'ASC'; if ($orderBy == 'id_product' OR $orderBy == 'date_add') $orderByPrefix = 'p'; elseif ($orderBy == 'name') $orderByPrefix = 'pl'; elseif ($orderBy == 'manufacturer') { $orderByPrefix = 'm'; $orderBy = 'name'; } elseif ($orderBy == 'position') $orderByPrefix = 'cp'; if ($orderBy == 'price') $orderBy = 'orderprice'; if (!Validate::isBool($active) OR !Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)) die (Tools::displayError());[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] $id_supplier = intval(Tools::getValue('id_supplier'));[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] /* Return only the number of products */ if ($getTotal) { $result = Db::getInstance()->getRow(' SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').' '.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : '').''); return isset($result) ? $result['total'] : 0; }[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] $sql = ' SELECT ' . ($viewed ? 'DISTINCT ' : '') . 'p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, (p.price - IF((DATEDIFF(reduction_from, CURDATE()) <= 0 AND DATEDIFF(reduction_to, CURDATE()) >=0) OR reduction_from = reduction_to, IFNULL(reduction_price, (p.price * reduction_percent / 100)),0)) AS orderprice FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax` LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`';[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] if ($viewed) { $productsViewed = (isset($cookie->viewed) AND !empty($cookie->viewed)) ? explode(',', $cookie->viewed) : array(); if (sizeof($productsViewed) == 0) return false; $sql .= ' WHERE '; for ($i = 0; $i < sizeof($productsViewed); $i++) $sql .= 'p.`id_product` = ' . $productsViewed[$i] . ($i < sizeof($productsViewed) - 1 ? ' OR ' : ' '); } else { $sql .= ' WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').' '.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : ''); } if ($random === true) { $sql .= 'ORDER BY RAND()'; $sql .= 'LIMIT 0, '.intval($randomNumberProducts); } else { $sql .= 'ORDER BY '.(isset($orderByPrefix) ? $orderByPrefix.'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n); } $result = Db::getInstance()->ExecuteS($sql); if ($orderBy == 'orderprice') { Tools::orderbyPrice($result, $orderWay); } if (!$result) return false;[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); How do I do this PrestaShop 1.5.4.0 Edited April 1, 2013 by Şahin YILDIZ (see edit history) Link to comment Share on other sites More sharing options...
nitin900 Posted February 7, 2014 Share Posted February 7, 2014 PrestaShop Superstar : excerpt This is not an easy thing to do, but I've tried to come up with a solution anyway. Download the attached file, then put viewed.php in Prestashop's root directory and viewed.tpl in your chosen theme's directory. You will also need to change the getProducts function in classes/Category.php to below code. Once you've done this, you can go to viewed.php in your root directory to see the viewed products on a separate page. public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $viewed = false) { global $cookie;[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] if ($p < 1) $p = 1; if (empty($orderBy)) $orderBy = 'position'; if (empty($orderWay)) $orderWay = 'ASC'; if ($orderBy == 'id_product' OR $orderBy == 'date_add') $orderByPrefix = 'p'; elseif ($orderBy == 'name') $orderByPrefix = 'pl'; elseif ($orderBy == 'manufacturer') { $orderByPrefix = 'm'; $orderBy = 'name'; } elseif ($orderBy == 'position') $orderByPrefix = 'cp'; if ($orderBy == 'price') $orderBy = 'orderprice'; if (!Validate::isBool($active) OR !Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)) die (Tools::displayError());[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] $id_supplier = intval(Tools::getValue('id_supplier'));[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] /* Return only the number of products */ if ($getTotal) { $result = Db::getInstance()->getRow(' SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').' '.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : '').''); return isset($result) ? $result['total'] : 0; }[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] $sql = ' SELECT ' . ($viewed ? 'DISTINCT ' : '') . 'p.*, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, (p.price - IF((DATEDIFF(reduction_from, CURDATE()) <= 0 AND DATEDIFF(reduction_to, CURDATE()) >=0) OR reduction_from = reduction_to, IFNULL(reduction_price, (p.price * reduction_percent / 100)),0)) AS orderprice FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax` LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`';[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] if ($viewed) { $productsViewed = (isset($cookie->viewed) AND !empty($cookie->viewed)) ? explode(',', $cookie->viewed) : array(); if (sizeof($productsViewed) == 0) return false; $sql .= ' WHERE '; for ($i = 0; $i < sizeof($productsViewed); $i++) $sql .= 'p.`id_product` = ' . $productsViewed[$i] . ($i < sizeof($productsViewed) - 1 ? ' OR ' : ' '); } else { $sql .= ' WHERE cp.`id_category` = '.intval($this->id).($active ? ' AND p.`active` = 1' : '').' '.($id_supplier ? 'AND p.id_supplier = '.$id_supplier : ''); } if ($random === true) { $sql .= 'ORDER BY RAND()'; $sql .= 'LIMIT 0, '.intval($randomNumberProducts); } else { $sql .= 'ORDER BY '.(isset($orderByPrefix) ? $orderByPrefix.'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n); } $result = Db::getInstance()->ExecuteS($sql); if ($orderBy == 'orderprice') { Tools::orderbyPrice($result, $orderWay); } if (!$result) return false;[/size][/font][/color] [color=#343943][font=Arial, Helvetica, sans-serif][size=3] /* Modify SQL result */ return Product::getProductsProperties($id_lang, $result); How do I do this PrestaShop 1.5.4.0 Nothing happend when follow your instruction.. pls help me thank in advance Link to comment Share on other sites More sharing options...
vekia Posted February 7, 2014 Share Posted February 7, 2014 unfortunately this post doesnt contain any kind of file to download, so i suppose that author removed it can you please shed some more light on this ? Link to comment Share on other sites More sharing options...
nitin900 Posted February 7, 2014 Share Posted February 7, 2014 I already download viewed.php and viewed.tpl from your articleBut result is none Link to comment Share on other sites More sharing options...
vekia Posted February 7, 2014 Share Posted February 7, 2014 in fact, it's not my article, in addition: http://www.prestashop.com/forums/topic/236624-viewed-products/?p=1166324 this post doesnt contain any downloadable file Link to comment Share on other sites More sharing options...
nitin900 Posted February 7, 2014 Share Posted February 7, 2014 Ok , Plese give me solution for Recently viewed product in different page Link to comment Share on other sites More sharing options...
vekia Posted February 7, 2014 Share Posted February 7, 2014 but i haven't got these files, because there is no downloadable files, this is what im trying to say so i don't know why this feature doesn't work Link to comment Share on other sites More sharing options...
Recommended Posts