Jump to content
Sign in to follow this  
lubov17

сортировка в производителе, категориях, подкатегориях опенкарт 2

Recommended Posts

все,сдаюсь

весь форум перерыла, опенкарт версия 2031

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

 

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';
		}

НО, это не то что мне хотелось. 
Ребята, как сделать так, чтобы в категориях,подкатегориях, производителе  в конце выводились товары с нулевым остатком, а не в перемешку.

 

Share this post


Link to post
Share on other sites

Сортируйте по количеству по умолчанию

p.quantity

вместо

p.date_added

и будет вам щастье :)

  • +1 1

Share this post


Link to post
Share on other sites

А зачем дублировать тему?

Одно и тоже ж....

Share this post


Link to post
Share on other sites

ответа там не увидела, который нужно мне

Share this post


Link to post
Share on other sites

Fedka, модули хорошо, но я хочу в коде подправить

Share this post


Link to post
Share on other sites

пробовала много кодов, спасибо этой теме нашла еще один вариант и сработало!!!!ура)))

 

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";	
		}

Share this post


Link to post
Share on other sites

Расшифровую это:

Скрытый текст
<file path="catalog/model/catalog/product.php">
		<operation>
        <search><![CDATA[$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";]]></search>
        <add position="replace"><![CDATA[$sql .= " ORDER BY (p.quantity>0) DESC, LCASE(" . $data['sort'] . ")";]]></add>
        </operation>
	    <operation>
        <search><![CDATA[} elseif ($data['sort'] == 'p.price') {]]></search>
        <add position="replace"><![CDATA[} elseif ($data['sort'] == 'p.price') {]]></add>
        </operation>
		<operation>
        <search><![CDATA[$sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";]]></search>
        <add position="replace"><![CDATA[$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)";]]></add>
        </operation>
        <operation>
        <search><![CDATA[$sql .= " ORDER BY " . $data['sort'];]]></search>
        <add position="replace"><![CDATA[$sql .= " ORDER BY (p.quantity>0) DESC," . $data['sort'];]]></add>
        </operation>
        <operation>
        <search><![CDATA[$sql .= " ORDER BY p.sort_order";]]></search>
        <add position="replace"><![CDATA[$sql .= " ORDER BY (p.quantity>0) DESC, p.sort_order";]]></add>
        </operation>
  </file>

 

Открываем файл: catalog/model/catalog/product.php

Ищем: 

$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";

Заменяем на:

$sql .= " ORDER BY (p.quantity>0) DESC, LCASE(" . $data['sort'] . ")";

Ищем:

} elseif ($data['sort'] == 'p.price') {

Заменяем на:

} 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)";

Заменяем на:

$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)";

Ищем:

$sql .= " ORDER BY " . $data['sort'];

Заменяем на:

$sql .= " ORDER BY (p.quantity>0) DESC," . $data['sort'];

Ищем:

$sql .= " ORDER BY p.sort_order";

Заменяем на:

$sql .= " ORDER BY (p.quantity>0) DESC, p.sort_order";

 

 

Если так проще, чем залить файл в папку system. Затем перейти в админку, Дополнения->Менеджер дополнений и нажать кнопку обновить...

 

То да, наверное...

Share this post


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
You are posting as a guest. If you have an account, please sign in.
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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.