<?php

namespace KupShop\ElninoBundle\Util;

use KupShop\ElninoBundle\Query\Filter;
use Query\Operator;

class VirtualCategoryProductsFilterSpecs extends \KupShop\CatalogBundle\Util\VirtualCategoryProductsFilterSpecs
{
    protected function spec_sex(array $sex)
    {
        return Filter::bySex($sex);
    }

    protected function spec_discount(array $discounts)
    {
        if ($discounts['min'] || $discounts['max']) {
            $discountRange = new \Range($discounts['min'], $discounts['max']);

            $fieldName = 'IF(p.display_discount > 0, IF(p.discount > 0, ((p.display_discount * (1 - (p.discount / 100))) + p.discount), p.display_discount), p.discount)';

            return Operator::between($fieldName, $discountRange);
        }
    }
}
