Jump to content

Фотография для следующего и предыдущего товаров


Recommended Posts

Добрый день!

Необходимо на странице товара отобразить картику для следующего и предыдущего товаров.

Подскажите, пожалуйста, каким образом нужно дополнить запрос к БД в get_next_product и get_prev_product, чтобы в $prev_product и $next_product получить filename соответствующей фотографии.

 

Спасибо!

Link to post
Share on other sites

 

Примерно так:

	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/, и картинка какая-то "левая" отображается.

Где нужно поправить, подскажите, пожалуйста!

Link to post
Share on other sites
  • 1 year later...

Видать давно дело было и по-удаляли что-то из темы.

Код выше прописал, но не понимаю как вызвать собственно картинку товара уже в шаблоне. МОжет кто-нибудь может помочь?

Link to post
Share on other sites
  • 10 months later...

Чтобы в шаблоне заработали смарти-теги с выводом предыдущей и следующей картинки нужно:

 

В файле 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 by Al_Ary
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...