Robertnus555 Posted July 17, 2022 at 09:08 AM Share Posted July 17, 2022 at 09:08 AM Всех приветствую! Помогите разобраться, как сделать, что бы в итоге по умолчанию получить сортировку в которой первым отображается новый товар который есть в наличии, а товар которого нет нв наличии на складе что бы были в конце списка. опенкарт 2.1х 0 Quote Link to comment Share on other sites More sharing options...
Solution freeworld Posted July 17, 2022 at 09:24 AM Solution Share Posted July 17, 2022 at 09:24 AM Здравствуйте, @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) ); . 1 Quote Link to comment Share on other sites More sharing options...
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.
Note: Your post will require moderator approval before it will be visible.