Jump to content

Сортировка товаров по наличию, новый в начало \ нет в наличии в конец


Go to solution Solved by freeworld,

Recommended Posts

Всех приветствую! Помогите разобраться, как сделать, что бы в итоге по умолчанию получить сортировку в которой первым отображается новый товар который есть в наличии, а товар которого нет нв наличии на складе что бы были в конце списка.
опенкарт 2.1х

 

Link to comment
Share on other sites

  • Solution

Здравствуйте, @Robertnus555!
По пути в catalog/model/catalog/product.php
это замените

if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
		if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
			$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
		} elseif ($data['sort'] == 'p.price') {
			$sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
		} else {
			$sql .= " ORDER BY " . $data['sort'];
		}
	} else {
		$sql .= " ORDER BY p.sort_order";	
	}

 

на это

if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
			if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
				$sql .= " ORDER BY (p.quantity>0) DESC, LCASE(" . $data['sort'] . ")";
			} elseif ($data['sort'] == 'p.price') {
				$sql .= " ORDER BY (p.quantity>0) DESC, (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
			} else {
				$sql .= " ORDER BY (p.quantity>0) DESC," . $data['sort'];
			}
		} else {
			$sql .= " ORDER BY (p.quantity>0) DESC, p.sort_order";	
		}

 

Далее по пути catalog/controller/product/category.php

это

if (isset($this->request->get['sort'])) {
			$sort = $this->request->get['sort'];
		} else {
			$sort = 'p.sort_order';
		}

		if (isset($this->request->get['order'])) {
			$order = $this->request->get['order'];
		} else {
			$order = 'ASC';
		}

 

меняем на такое

if (isset($this->request->get['sort'])) {
			$sort = $this->request->get['sort'];
		} else {
			$sort = 'p.date_added';
		}

		if (isset($this->request->get['order'])) {
			$order = $this->request->get['order'];
		} else {
			$order = 'DESC';
		}

 

Там же ищем эти строки

$data['sorts'][] = array(
	'text'  => $this->language->get('text_default'),
	'value' => 'p.sort_order-ASC',
	'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)
	);

 

и заменяем на эти

$data['sorts'][] = array(
		'text'  => $this->language->get('text_default'),
		'value' => 'p.date_added-DESC',
		'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.date_added&order=DESC' . $url)
	);

 

.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...