Раздел sale в simpla
Требуется создать категорию, куда будут попадать товары с скидкой.
- создаем категорию с адресом страницы «sale»
- в файле /view/ProductsView.php правим код:
// Выберем текущую категорию if (!empty($category_url)) { $category = $this->categories->get_category((string)$category_url); if (empty($category) || (!$category->visible && empty($_SESSION['admin']))) return false; $this->design->assign('category', $category); if($category->url == 'sale') { $filter['discounted'] = 1; } else { $filter['category_id'] = $category->children; } }
- В файде /api/Products.php обновляем методы get_products и count_products:
public function get_products($filter = array()) { ... $is_featured_filter = ''; $discounted_filter = ''; $in_stock_filter = ''; ... if(isset($filter['discounted'])) $discounted_filter = $this->db->placehold('AND (SELECT 1 FROM __variants pv WHERE pv.product_id=p.id AND pv.compare_price>0 LIMIT 1) = ?', intval($filter['discounted'])); ... $query = "SELECT ... WHERE ... $discounted_filter ... "; ... } public function count_products($filter = array()) { ... $is_featured_filter = ''; $discounted_filter = ''; $in_stock_filter = ''; ... if(isset($filter['discounted'])) $discounted_filter = $this->db->placehold('AND (SELECT 1 FROM __variants pv WHERE pv.product_id=p.id AND pv.compare_price>0 LIMIT 1) = ?', intval($filter['discounted'])); ... $query = "SELECT ... WHERE ... $discounted_filter ... "; ... }