База знаний

22.09.2017

Проблема

Как сделать возможность в форме поиска по товарам фильтровать товары со скидкой?

Решение

Во вьюхе формы поиска хардкодим например чекбокс - товары со скидкой Например <input type="checkbox" name="discount" />

Дальше в модельке в функции where после:

if (!empty($_REQUEST["pr1"]) || !empty($_REQUEST["pr2"]))
    {
        if (!empty(
$_REQUEST["pr1"]))
        {
            
$pr1 = $this->diafan->filter($_REQUEST, "int", "pr1");
            
$getnav .= '&pr1='.$pr1;
        }
        if (!empty(
$_REQUEST["pr2"]))
        {
            
$pr2 = $this->diafan->filter($_REQUEST, "int", "pr2");
            
$getnav .= '&pr2='.$pr2;
        }
        
$where_param .= " INNER JOIN {shop_price} AS pr ON pr.good_id=s.id AND pr.trash='0'"
            
." AND pr.date_start<=".time()." AND (pr.date_start=0 OR pr.date_finish>=".time().")"
            
." AND pr.currency_id=0"
            
." AND pr.role_id".($this->diafan->_users->role_id ? " IN (0,".$this->diafan->_users->role_id.")" : "=0")
            .
" AND (pr.person='0'".($this->person_discount_ids ? " OR pr.discount_id IN(".implode(",", $this->person_discount_ids).")" : "").")";
        
$group = ", pr.price_id HAVING"
            
.(!empty($_REQUEST["pr1"]) ? " MIN(ROUND(pr.price))>=".$pr1 : '')
            .(!empty(
$_REQUEST["pr2"]) ? (!empty($_REQUEST["pr1"]) ? " AND" : "")." MIN(pr.price)<=".$pr2 : '');
    }
    else
    {
        
$where_param .= " LEFT JOIN {shop_price} AS pr ON pr.good_id=s.id AND pr.trash='0'"
            
." AND pr.date_start<=".time()." AND (pr.date_start=0 OR pr.date_finish>=".time().")"
            
." AND pr.currency_id=0"
            
." AND pr.role_id".($this->diafan->_users->role_id ? " IN (0,".$this->diafan->_users->role_id.")" : "=0")
            .
" AND (pr.person='0'".($this->person_discount_ids ? " OR pr.discount_id IN(".implode(",", $this->person_discount_ids).")" : "").")";
    }

пишем что-то вроде:

if (!empty($_REQUEST['discount'])) {

        
$where_param .= ' AND pr.discount_id !=0';

    }
Автор решения: Андрей (R4W)