phpcoder Posted December 3, 2009 Report Share Posted December 3, 2009 А как можно сделать, чтобы по умолчанию в категории список товаров был отсортирован по умолчанию по цене?Я так понимаю, что капать нужно где то сдесь:// Выбираем из базы товары$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; }но вот где конкретно, что то запутался... помогите плиз, спасибо! Quote Link to post Share on other sites
Guest Posted December 3, 2009 Report Share Posted December 3, 2009 В этой фунции// Функция возвращает товары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, и товары будут отсортированы по цене Quote Link to post Share on other sites
igor-tv Posted April 15, 2010 Report Share Posted April 15, 2010 А как быть в Симпле 1.4, где цена указана в таблице products_variants а не products ? Подскажите, как правильно сформировать запрос. Quote Link to post Share on other sites
my.thaw Posted April 19, 2010 Report Share Posted April 19, 2010 $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";Как то так Quote Link to post Share on other sites
my.thaw Posted April 19, 2010 Report Share Posted April 19, 2010 Хотя в идеале было бы дописать выбор, пользователем метода сортировки в выводе товара - products.tpl и Storefront.class.phpЕсли кто сподвижится - будем рады такому. Quote Link to post Share on other sites
igor-tv Posted April 20, 2010 Report Share Posted April 20, 2010 my.thaw, спасибо Quote Link to post Share on other sites
mart Posted February 26, 2011 Report Share Posted February 26, 2011 http://blog.rlstudio.com/2011/02/dorabotki-magazina-simpla-sortirovka-tovarov/ Quote Link to post Share on other sites
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.