SEJIN Posted August 27, 2013 Report Share Posted August 27, 2013 Добрый день!Необходимо на странице товара отобразить картику для следующего и предыдущего товаров.Подскажите, пожалуйста, каким образом нужно дополнить запрос к БД в get_next_product и get_prev_product, чтобы в $prev_product и $next_product получить filename соответствующей фотографии. Спасибо! Quote Link to post Share on other sites
SEJIN Posted August 28, 2013 Author Report Share Posted August 28, 2013 Примерно так: public function get_prev_product($id) { $this->db->query("SELECT position FROM __products WHERE id=? LIMIT 1", $id); $position = $this->db->result('position'); $this->db->query("SELECT pc.category_id FROM __products_categories pc WHERE product_id=? ORDER BY position LIMIT 1", $id); $category_id = $this->db->result('category_id'); $query = $this->db->placehold("SELECT id FROM __products p, __products_categories pc WHERE pc.product_id=p.id AND p.position<? AND pc.position=(SELECT MIN(pc2.position) FROM __products_categories pc2 WHERE pc.product_id=pc2.product_id) AND pc.category_id=? AND p.visible ORDER BY p.position DESC limit 1", $position, $category_id); $this->db->query($query); $n=$this->get_product((integer)$this->db->result('id')); $n->images = $this->get_images(array('product_id'=>$n->id)); $n->image = &$n->images[0]; return $n; // return $this->get_product((integer)$this->db->result('id')); } Спасибо! Картинки передаются, но не могу выловить маленький баг: если выбран самый первый товар из списка,, т.е. у него нет предыдущих товаров, то вместо предыдущего товара отображается ссылка на список всех товаров, т.е. на .../products/, и картинка какая-то "левая" отображается.Где нужно поправить, подскажите, пожалуйста! Quote Link to post Share on other sites
Eddie Posted January 17, 2015 Report Share Posted January 17, 2015 Видать давно дело было и по-удаляли что-то из темы.Код выше прописал, но не понимаю как вызвать собственно картинку товара уже в шаблоне. МОжет кто-нибудь может помочь? Quote Link to post Share on other sites
Al_Ary Posted November 24, 2015 Report Share Posted November 24, 2015 (edited) Чтобы в шаблоне заработали смарти-теги с выводом предыдущей и следующей картинки нужно: В файле api/Products.php Найти функцию: public function get_next_product($id) { $this->db->query("SELECT position FROM __products WHERE id=? LIMIT 1", $id); $position = $this->db->result('position'); $this->db->query("SELECT pc.category_id FROM __products_categories pc WHERE product_id=? ORDER BY position LIMIT 1", $id); $category_id = $this->db->result('category_id'); $query = $this->db->placehold("SELECT id FROM __products p, __products_categories pc WHERE pc.product_id=p.id AND p.position>? AND pc.position=(SELECT MIN(pc2.position) FROM __products_categories pc2 WHERE pc.product_id=pc2.product_id) AND pc.category_id=? AND p.visible ORDER BY p.position limit 1", $position, $category_id); $this->db->query($query); return $this->get_product((integer)$this->db->result('id')); } Вставить после $this->db->query($query); $n=$this->get_product((integer)$this->db->result('id')); if($n != 0){ $n->images = $this->get_images(array('product_id'=>$n->id)); $n->image = &$n->images[0]; return $n; } И закомментировать двумя слешами или удалить строчку: // return $this->get_product((integer)$this->db->result('id')); Аналогично сделать для функции get_prev_product, после $this->db->query($query); вставить тот же код, что и выше и удалить последнюю строчку. От описанного выше отличается исправлением бага связанного с самым первым и самым последним товаром. В шаблоне можно использовать: {$next_product->image->filename|resize:200:200} {$prev_product->image->filename|resize:200:200} Edited November 24, 2015 by Al_Ary Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.