Jump to content

Recommended Posts

А как можно сделать, чтобы по умолчанию в категории список товаров был отсортирован по умолчанию по цене?

Я так понимаю, что капать нужно где то сдесь:

// Выбираем из базы товары
$products = $this->get_products(null, $category->subcats_ids, isset($brand->brand_id)?$brand->brand_id:null, $start_item);

или сдесь

// Функция возвращает товары
function get_products($ids = null, $categories = null, $brand_id = null, $start_item=null)
{

// Если заданы id
$id_filter = '';
if (is_array($ids))
{
foreach ($ids as $k=>$id)
{
$ids[$k]=intval($id);
}
$id_filter = is_null($ids)?"":"AND (products.product_id in(".join($ids, ',')."))";
}

// Если задана категория, добавляем фильт по категории
$category_filter = is_null($categories)?"":"AND (categories.category_id in(".join($categories, ',')."))";

// Если задан бренд, добавляем фильт по бренду
$brand_filter = is_null($brand_id)?"":"AND brands.brand_id = $brand_id";

// Если задан бренд, добавляем фильт по бренду
$limit = is_null($start_item)?"":"LIMIT $start_item, $this->items_per_page";

// Если пользователь залогиен, применим сразу его скидку к ценам на товар
$discount=isset($this->user->discount)?$this->user->discount:0;
$query = "SELECT SQL_CALC_FOUND_ROWS *,
products.*, brands.name as brand, brands.url as brand_url,
categories.single_name as category, categories.url as category_url, categories.image as category_image,
products.price*(100-$discount)/100 as discount_price
FROM products LEFT JOIN categories ON categories.category_id = products.category_id LEFT JOIN brands ON products.brand_id = brands.brand_id
WHERE
categories.enabled=1
and products.enabled=1
$id_filter $category_filter $brand_filter
ORDER BY categories.order_num, products.order_num DESC
$limit";
$this->db->query($query);
$products = $this->db->results();
return $products;
}

но вот где конкретно, что то запутался... помогите плиз, спасибо!

Link to post
Share on other sites

В этой фунции

// Функция возвращает товары
function get_products($ids = null, $categories = null, $brand_id = null, $start_item=null)

В запросе есть строка
ORDER BY categories.order_num, products.order_num DESC

Замените products.order_num на products.price, и товары будут отсортированы по цене

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

$query = "SELECT
products.product_id, products.url, products.category_id, products.brand_id, products.model, products.description, products.body, products.hit, products.order_num, products.small_image, products.large_image, DATE_FORMAT(products.created, '%Y-%m-%d') as created, DATE_FORMAT(products.modified, '%Y-%m-%d') as modified, products.enabled,
brands.name as brand, brands.url as brand_url,
categories.single_name as category, categories.url as category_url, categories.image as category_image
FROM products LEFT JOIN categories ON categories.category_id = products.category_id
LEFT JOIN brands ON products.brand_id = brands.brand_id
LEFT JOIN products_categories ON products.product_id = products_categories.product_id
LEFT JOIN products_variants ON products.product_id = products_variants.product_id
WHERE
categories.enabled=1
and products.enabled=1
$id_filter $category_filter $brand_filter $properties_filter $hit_filter
GROUP BY products.product_id
ORDER BY products_variants.price desc
$limit";


Как то так

Link to post
Share on other sites

Хотя в идеале было бы дописать выбор, пользователем метода сортировки в выводе товара - products.tpl и Storefront.class.php

Если кто сподвижится - будем рады такому.

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

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...