Ошибка в файле PHP

#
Ошибка в файле PHP
Добрый день!
На сайте в одной из категорий пропал фильтр и появились предупреждения

Предупреждение: Invalid argument supplied for foreach() в файле /var/www/igor/data/www/plitkamags.ru/modules/pao/shop.php (строка 703)Предупреждение: Invalid argument supplied for foreach() в файле /var/www/igor/data/www/plitkamags.ru/modules/pao/shop.php (строка 662)

Буду благодарен за подсказку, где исправить.

Сам файл выглядит так:

<?php

defined('HOSTCMS' || exit('HostCMS: access denied.';
$file = $_SERVER["DOCUMENT_ROOT"]  . "/hostcmsfiles/license.txt";
$file_get_contents = file_get_contents($file);
if($file_get_contents !== HOSTCMS_CONTRACT_NUMBER){
    exit('HostCMS: access denied.';
}

class Pao_Shop
{  
    public function getGroupPropertyValue($group, $property_id){
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('value'
            ->from('property_value_ints'
            ->open()
            ->where('entity_id', '=', $group)
            ->setAnd()
            ->where('property_id', '=', $property_id)
            ->close();
        $row = $oCore_QueryBuilder_Select->execute()->asAssoc()->current();
        if($row && count($row)>0){
            return $row["value"];
        }
        return false;
    }
    
    public function JsonFilter($shop_group_id, $find_array, $price_from, $price_to, $instock, $type_of_answer){
        if($shop_group_id > 0){
            if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json') {
                $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json', true);
                if($file){
                    //содержимое файла
                    $file_array =  json_decode($file);
                    $found_items_id = array();
                    foreach($file_array as $key => $item){
                        $found_array = array();
                        if($item->current_price >= $price_from && $item->current_price <= $price_to && $item->count >= $instock){
                            //если есть свойства, проверка по свойствам, если нет - все подряд
                            if(count($find_array)>0 && isset($item->propertys) && count($item->propertys)>0){
                                foreach($item->propertys as $key => $property){
                                    $property_id = $key;
                                    if(isset($find_array[$property_id])){
                                        foreach($find_array[$property_id] as $key2 => $val){
                                            $f = array_search($val, $property);  
                                            if($f !== false){
                                                $found_array[] = $property_id;      
                                            }      
                                        }
                                    }
                                }
                                if(count($found_array) == count($find_array)){
                                    if($item->modification_id > 0){
                                        $found_items_id[] = $item->modification_id;  
                                    }    
                                    else{
                                        $found_items_id[] = $item->id;    
                                    }
                                }  
                            }
                            else{
                                if(count($found_array) == count($find_array)){
                                    if($item->modification_id > 0){
                                        $found_items_id[] = $item->modification_id;  
                                    }    
                                    else{
                                        $found_items_id[] = $item->id;    
                                    }
                                }
                            }      
                        }
                    }
                    if(count($found_items_id)>0){
                        $found_items_id = array_unique($found_items_id);
                        if($type_of_answer == 'count'{
                            return count($found_items_id);    
                        }
                        else{
                            return $found_items_id;
                        }
                    }
                }
            }
        }
        return false;  
    }
    
    public function GetPropertysAndValuesForFilter($propertys, $request, $instock){
        if(isset($request['group'])){
            $shop_group_id = $request['group'];  
        }
        else{
            return false;
        }
        $price_from = $request['price_from'];
        $price_to = $request['price_to'];
        $result = false;
        if(count($propertys)>0){
            $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json', true);
            if($file){
                //содержимое файла
                $file_array =  json_decode($file);
                //формируем id свойств для каждого свойства
                $find_array = array();
                foreach($propertys as $key => $value){
                    $find_array[$value] = array();
                    foreach($propertys as $key2 => $value2){
                        if($value2 !== $value){
                            $v = '';
                            if(isset($request["property_$value2"])){
                                $find_array[$value][$value2] = $request["property_$value2"];
                            }
                        }  
                    }
                }
                foreach($find_array as $key0 => $property){
                    $found_items_id = array();
                    if(count($find_array[$key0])>0){
                        //цикл по файлу - товары
                        foreach($file_array as $key1 => $item){
                            if($item->current_price >= $price_from && $item->current_price <= $price_to && $item->count >= $instock){
                                //цикл по товарам - свойства
                                $found_array = array();
                                if(count($find_array)>0 && isset($item->propertys) && count($item->propertys)>0){
                                    foreach($item->propertys as $key2 => $property){
                                        $property_id = $key2;
                                        if(isset($find_array[$key0][$property_id])){
                                            foreach($find_array[$key0][$property_id] as $key3 => $val){
                                                $f = array_search($val, $property);  
                                                if($f !== false){
                                                    $found_array[] = $property_id;      
                                                }      
                                            }
                                        }  
                                    }
                                    if(count($found_array) > 0 && count($find_array[$key0]) == count($found_array)){
                                        $found_items_id[] = $item->id;    
                                    }
                                }
                                else{
                                    $found_items_id[] = $item->id;  
                                }
                            }
                        }  
                    }
                    else{
                        //поиск по всем товарам
                        //нет свойств, запускаем без свойств
                        $found_items_id = array();
                        foreach($file_array as $key => $item){
                           if($item->current_price >= $price_from && $item->current_price <= $price_to && $item->count >= $instock){
                                $found_items_id[] = $item->id;
                           }
                        }
                    }
                    $property = $key0;
                    if(count($found_items_id)>0){
                        //достанем свойства товаров
                        $prop = $this->GetValuesByItems($file_array,$property,$found_items_id);
                        if($prop && count($prop)>0){
                            $result[$property] = $prop;
                        }
                        else{
                            $result[$property] = '';
                        }
                    }
                    else{
                        $result[$property] = '';
                    }
                }  
                //общее количество товаров по всем свойствам
                $find_array = array();
                foreach($request as $key => $prop){
                    $e = explode("_",$key);
                    if(isset($e[1]) && $e[0] =='property'{
                        $find_array[$e[1]] = $prop;    
                    }
                }
                $c = $this->JsonFilter($shop_group_id, $find_array, $price_from, $price_to, $instock, 'count';
                $count = 0;
                if($c){
                    $count = $c;
                }
                $result['count'] = $count;
                
                return $result;    
            }  
            else{
                return array();
            }        
        }
        else{
            return array();
        }
    }
    
    public function GetValuesByItems($file_array, $property, $items_id){
        //достаем свойства
        $prop = array();
        foreach($items_id as $key => $item){
            if(isset($file_array->$item->propertys->$property)){
                foreach($file_array->$item->propertys->$property as $k => $v){
                    $prop[] = $v;
                }
            }
        }
        $prop = array_values(array_unique($prop));
        return $prop;
    }

    public function UpdateJsonOnServer($shop_item_id, $shop_group_id, $new_price = false){
        //если файла нет запускаем первичную прогонку
        if (!file_exists($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json') {
            $this->UpdateJsonItemsOnServer($shop_group_id);
        }
        else if($shop_item_id){
            //получаем файл и удаляем товар и модификации
            $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json', true);
            if($file) {
                $file_array = json_decode($file);
                //удаляем товар и модификацию
                if(count($file_array) == 0){
                    return true;
                }
                foreach ($file_array as $key => $items) {
                    if ($items->id == $shop_item_id || $items->modification_id == $shop_item_id) {
                        unset($file_array->$key);
                    }
                }

                //преобразовываем в обычный массив
                $items = get_object_vars($file_array);

                //создаем товар с модификациями в массиве заново
                $oShop_Item = Core_Entity::factory('Shop_Item', $shop_item_id);

                $oShop_Group = Core_Entity::factory('Shop_Group', $shop_group_id);

                $oShop = Core_Entity::factory('Shop', $oShop_Group->shop_id);
            
                $aShop_Currencies = Core_Entity::factory('Shop_Currency'->findAll();
                foreach ($aShop_Currencies as $oShop_Currency)
                {
                    // Получаем коэффициент пересчета для каждой валюты
                    $currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
                        $oShop_Currency, $oShop->Shop_Currency
                    );
                    $cur[$oShop_Currency->id]["id"] = $oShop_Currency->id;
                    $cur[$oShop_Currency->id]["coefficient"] = $currency_coefficient;
                    if($oShop_Currency->default ==1){
                        $currency_default = $oShop_Currency->id;
                    }
                }

                if($oShop_Item->deleted == 0 && $oShop_Item->active == 1){

                    if($oShop_Item->shop_currency_id !== $currency_default && $oShop_Item->price > 0 && isset($cur[$oShop_Item->shop_currency_id]["coefficient"])){
                        $price = $oShop_Item->price * $cur[$oShop_Item->shop_currency_id]["coefficient"];
                        $new_price = $new_price * $cur[$oShop_Item->shop_currency_id]["coefficient"];
                    }
                    else{
                        $price = $oShop_Item->price;
                    }

                    $items[$oShop_Item->id]["id"] = $oShop_Item->id;
                    $items[$oShop_Item->id]["price"] = $new_price !== false ? $new_price : $oShop_Item->price;
                    $items[$oShop_Item->id]["shop_currency_id"] = $oShop_Item->shop_currency_id;
                    $items[$oShop_Item->id]["current_price"] = $new_price !== false ? $new_price : $price;
                    $items[$oShop_Item->id]["modification_id"] = $oShop_Item->modification_id;
                    //количество на складе
                    $items[$oShop_Item->id]["count"] = $this->getWerehouseItemCount($oShop_Item->id);
                    //получим доп-свойства товара
                    $propertys = $this->getItemsPropertys2($oShop_Item->id);
                    foreach($propertys as $key => $property){
                        $values = $this->getPropertysWithValueForItem($oShop_Item->id,$property["property_id"]);
                        if($values){
                            $items[$oShop_Item->id]["propertys"][$property["property_id"]] = $values;
                        }
                    }
                    //получим модификации
                    $oCore_QueryBuilder_Select = Core_QueryBuilder::select('id'
                        ->from('shop_items'
                        ->where('modification_id', '=', $oShop_Item->id);
                    $aRows = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
                    if($aRows && count($aRows)>0){
                        foreach($aRows as $key => $mod_items){
                            $oShop_Item_Mod = Core_Entity::factory('Shop_Item', $mod_items["id"]);

                            if($oShop_Item_Mod->deleted == 0 && $oShop_Item_Mod->active == 1){

                                if($oShop_Item_Mod->shop_currency_id !== $currency_default && $oShop_Item_Mod->price > 0 && isset($cur[$oShop_Item_Mod->shop_currency_id]["coefficient"])){
                                    $price = $oShop_Item_Mod->price * $cur[$oShop_Item_Mod->shop_currency_id]["coefficient"];
                                }
                                else{
                                    $price = $oShop_Item_Mod->price;
                                }

                                $items[$oShop_Item_Mod->id]["id"] = $oShop_Item_Mod->id;
                                $items[$oShop_Item_Mod->id]["price"] = $oShop_Item_Mod->price;
                                $items[$oShop_Item_Mod->id]["shop_currency_id"] = $oShop_Item_Mod->shop_currency_id;
                                $items[$oShop_Item_Mod->id]["current_price"] = $price;
                                $items[$oShop_Item_Mod->id]["modification_id"] = $oShop_Item_Mod->modification_id;
                                //количество на складе
                                $items[$oShop_Item_Mod->id]["count"] = $this->getWerehouseItemCount($oShop_Item_Mod->id);
                                //получим доп-свойства товара
                                $propertys = $this->getItemsPropertys2($oShop_Item_Mod->id);
                                foreach($propertys as $key => $property){
                                    $values = $this->getPropertysWithValueForItem($oShop_Item_Mod->id,$property["property_id"]);
                                    if($values){
                                        $items[$oShop_Item_Mod->id]["propertys"][$property["property_id"]] = $values;
                                    }
                                }
                            }
                        }
                    }

                }

                $json = json_encode($items);
                $fp = fopen($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'. $shop_group_id .'.json', "w";
                fwrite($fp, $json);
                fclose($fp);

            }
        }
    }
    
    public function UpdateJsonItemsOnServer($shop_group_id){
        $oShopGroup = Core_Entity::factory('Shop_Group', $shop_group_id);
        $oShop = Core_Entity::factory('Shop', $oShopGroup->shop_id);
        //достаем товары и выгружаем в файл
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select("id","price","shop_currency_id","modification_id"
           ->from('shop_items'
           ->open()
                ->where('shop_group_id', '=', $shop_group_id)
                ->setAnd()
                ->where('active', '=', 1)
                ->setAnd()
                ->where('deleted', '=', 0)  
           ->close();
        $aRows = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
        if($aRows && count($aRows)>0){
            foreach($aRows as $k => $i){
                $it[] = $i["id"];
            }
            //достанем модификации
            $oCore_QueryBuilder_Select2 = Core_QueryBuilder::select("id","price","shop_currency_id","modification_id"
               ->from('shop_items'
               ->open()
                    ->where('modification_id', 'IN', $it)
                    ->setAnd()
                    ->where('active', '=', 1)
                    ->setAnd()
                    ->where('deleted', '=', 0)  
               ->close();
            $aRows2 = $oCore_QueryBuilder_Select2->execute()->asAssoc()->result();    
            foreach($aRows as $k => $items_with_mod){
                $it2[] = $items_with_mod;
            }
            foreach($aRows2 as $k2 => $items_with_mod2){
                $it2[] = $items_with_mod2;
            }      
            $aShop_Currencies = Core_Entity::factory('Shop_Currency'->findAll();
            foreach ($aShop_Currencies as $oShop_Currency)
            {
                // Получаем коэффициент пересчета для каждой валюты
                $currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
                    $oShop_Currency, $oShop->Shop_Currency
                );
                $cur[$oShop_Currency->id]["id"] = $oShop_Currency->id;
                $cur[$oShop_Currency->id]["coefficient"] = $currency_coefficient;

                if($oShop_Currency->default ==1){
                    $currency_default = $oShop_Currency->id;
                }
            }
            $items = array();
            foreach($it2 as $key => $item){
                if($item["shop_currency_id"] !== $currency_default && $item["price"] > 0 && isset($cur[$item["shop_currency_id"]]["coefficient"])){
                    $price = $item["price"] * $cur[$item["shop_currency_id"]]["coefficient"];
                }
                else{
                    $price = $item["price"];
                }
                $items[$item["id"]]["id"] = $item["id"];
                $items[$item["id"]]["price"] = $item["price"];
                $items[$item["id"]]["shop_currency_id"] = $item["shop_currency_id"];
                $items[$item["id"]]["current_price"] = $price;
                $items[$item["id"]]["modification_id"] = $item["modification_id"];    
                //количество на складе
                $items[$item["id"]]["count"] = $this->getWerehouseItemCount($item["id"]);
                //получим доп-свойства товара
                $propertys = $this->getItemsPropertys2($item["id"]);
                foreach($propertys as $key => $property){
                    $values = $this->getPropertysWithValueForItem($item["id"],$property["property_id"]);
                    if($values){
                        $items[$item["id"]]["propertys"][$property["property_id"]] = $values;  
                    }
                }
            }
            //запись в файл
            $json = json_encode($items);
            $fp = fopen($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'. $shop_group_id .'.json', "w";
            fwrite($fp, $json);
            fclose($fp);
            //формируем файл с данными для фильтра
            //$this->createPropertysAndValuesForFilter($shop_group_id);
        }  
    }
    
    public function getWerehouseItemCount($item_id){
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('count'
            ->from('shop_warehouse_items'
            ->open()
            ->where('shop_item_id', '=', $item_id)
            ->close();
        $row = $oCore_QueryBuilder_Select->execute()->asAssoc()->current();
        if($row && count($row)>0){
            return $row["count"];
        }
        return false;
    }
    
    public function getPropertysWithValueForItem($item_id, $property_id){
        $r = false;
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select("value"
           ->from('property_value_ints'
           ->open()
           ->where('property_value_ints.entity_id', '=', $item_id)
           ->setAnd()
           ->where('property_value_ints.property_id', '=', $property_id)
           ->setAnd()
           ->where('property_value_ints.value', '!=', 0)  
           ->close();  
        $v = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();  
        foreach($v as $key => $val){
            $r[] = $val["value"];
        }
        return $r;
    }
    
    /*
    *  вывод в виде списка в карточке товара
    */
    public function getValuesForItem($items){

        $res = false;
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('property_value_ints.property_id', 'property_value_ints.value'
            ->from('property_value_ints'
            ->leftJoin('properties', 'property_value_ints.property_id', '=', 'properties.id'
            ->leftJoin('shop_item_properties', 'properties.id', '=', 'shop_item_properties.property_id'
            ->from('property_value_ints'
            ->open()
            ->where('property_value_ints.entity_id', 'IN', $items)
            ->setAnd()
            ->where('property_value_ints.value', '!=', 0)  
            ->setAnd()
            ->where('shop_item_properties.show_in_item', '=', 1)
            ->close();
        $v = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();  
        if($v){
            //получаем список id свойств
            $property_ids = array();
            foreach($v as $key => $p){
                $property_ids[] = $p["property_id"];
            }
            $property_ids = array_values(array_unique($property_ids));
            //получаем список значений для свойств
            $prop = array();
            foreach($property_ids as $id){
                foreach($v as $key => $val){
                    if($val["property_id"] == $id){
                        $prop[$id][] = $val["value"];
                    }
                }
            }
            //отфильтруем
            $pr = array();
            foreach($prop as $key => $v){
                $pr[$key] = array_values(array_unique($v));
            }
            //получаем названия свойств
            foreach($pr as $key => $v){
                $oCore_QueryBuilder_Select = Core_QueryBuilder::select('name','sorting'->from('properties'->where('id', '=', $key);
                $res_prop = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
                if($res_prop){
                    $name = $res_prop[0]["name"];
                    $sorting = $res_prop[0]["sorting"];  
                    $res[$key]["name"] = $name;
                    $res[$key]["sorting"] = $sorting;
                    //свойства
                    foreach($v as $val){
                        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('value'->from('list_items'->where('id', '=', $val);
                        $res_val = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
                        if($res_val){
                            $val_name = $res_val[0]["value"];  
                            $res[$key]["values"][$val] = $val_name;
                        }
                    }
                }
            }
        }
        return $res;

    }
    
    
    /*
    * при формировании фильтра

    public function createPropertysAndValuesForFilter($shop_group_id){  
        $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json', true);
        $result = false;
        if($file){
            $file_array =  json_decode($file);
            $prop = array();
            foreach($file_array as $key => $value){
                if(isset($value->propertys)){
                    foreach($value->propertys as $key => $p){
                        $prop[$key][] = $p[0];
                    }
                }
            }
            //почистим
            $u = array();
            foreach($prop as $key => $p){
                $u[$key] = array_values(array_unique($p));
            }
            //достанем названия свойств
            if(count($u)>0){
                $result = array();
                foreach($u as $key => $array){
                    //название самого свойства
                    $oCore_QueryBuilder_Select = Core_QueryBuilder::select('name','sorting'->from('properties'->where('id', '=', $key);
                    $res_prop = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
                    $name = '';
                    $sorting = 0;
                    if($res_prop){
                        $name = $res_prop[0]["name"];
                        $sorting = $res_prop[0]["sorting"];
                    }
                    $result[$key]['property'] = $name;
                    $result[$key]['sorting'] = $sorting;
                    if(count($array)>0){
                        foreach($array as $k => $val){
                            $oCore_QueryBuilder_Select = Core_QueryBuilder::select('value', 'icon'->from('list_items'->where('id', '=', $val);
                            $res = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
                            if($res){
                                $result[$key]['values'][$val]["value"] = $res[0]["value"];
                                $result[$key]['values'][$val]["icon"] = $res[0]["icon"];
                            }
                        }  
                    }
                }
                if(count($result)>0){
                    //запись в файл
                    $json = json_encode($result);
                    $fp = fopen($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/filter_'. $shop_group_id .'.json', "w";
                    fwrite($fp, $json);
                    fclose($fp);  
                }  
            }
            return $result;
        }
        return false;
    }
    */
    /*
    * используется при формировании файла
    */
    public function getItemsPropertys2($item_id){  
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('property_value_ints.property_id', 'shop_item_properties.filter'
            ->from('property_value_ints'
            ->leftJoin('properties', 'property_value_ints.property_id', '=', 'properties.id'
            ->leftJoin('shop_item_properties', 'properties.id', '=', 'shop_item_properties.property_id'
            ->from('property_value_ints'
            ->open()
            ->where('property_value_ints.entity_id', '=', $item_id)
            ->setAnd()
            ->where('property_value_ints.value', '!=', 0)  
            ->setAnd()
            ->where('shop_item_properties.filter', '=', 4)
            ->close();
        return $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
    }

    /*
     * при формировании фильтра
     * */
    protected function getItemsPropertys($items){
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select(Core_QueryBuilder::expression('DISTINCT(`property_value_ints`.`property_id`), properties.name, shop_item_properties.filter, properties.type')
            ->leftJoin('shop_item_properties', 'property_value_ints.property_id', '=', 'shop_item_properties.property_id'
            ->leftJoin('properties', 'property_value_ints.property_id', '=', 'properties.id'
            ->from('property_value_ints'
            ->open()
            ->where('property_value_ints.entity_id', 'IN', $items)
            ->setAnd()
            ->where('shop_item_properties.filter', '!=', 0)
            ->setAnd()
            ->where('properties.deleted', '=', 0)
            ->setAnd()
            ->where('property_value_ints.value', '!=', 0)
            ->close()
            ->orderBy('properties.sorting','DESC'
        ;
        return $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
    }

    public function getValues($property_id, $shop_group_id){

        if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json') {
            $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json', true);
            if($file){
                $file_array =  json_decode($file);
                //получим товары и модификации
                $items_id = array();
                foreach($file_array as $k => $items) {
                    $items_id[] = $items->id;
                }
                if(count($items_id)>0){

                    $oCore_QueryBuilder_Select = Core_QueryBuilder::select(Core_QueryBuilder::expression('DISTINCT(`property_value_ints`.`value`)')
                        ->select(array('list_items.value', 'list_items_value')
                        ->select('list_items.icon'
                        ->leftJoin('list_items', 'property_value_ints.value', '=', 'list_items.id'
                        ->from('property_value_ints'
                        ->open()
                        ->where('property_value_ints.entity_id', 'IN', $items_id)
                        ->setAnd()
                        ->where('property_value_ints.property_id', '=', $property_id)
                        ->setAnd()
                        ->where('property_value_ints.value', '!=', 0)
                        ->close()
                        ->orderBy('list_items.sorting','ASC'// DESC A-Z  !!!
                    ;
                    return $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
                }

            }
        }
        return false;
    }
    
    /*
    * получаем массив с данными для фильтра
    */
    public function getFilterParams($shop_group_id){
        if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/filter_'.$shop_group_id.'.json') {
            $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/filter_'.$shop_group_id.'.json', true);
            if($file){
                return json_decode($file);
            }
        }
        return false;
    }
    public function getFilterParams2($shop_group_id){
        if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json') {
            $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json', true);
            if($file){
                $file_array =  json_decode($file);
                //получим товары и модификации
                $items_id = array();
                foreach($file_array as $k => $items) {
                    $items_id[] = $items->id;
                }
                if(count($items_id)>0){
                    $propertys = $this->getItemsPropertys($items_id);
                    if($propertys){
                        return $propertys;
                    }
                }

            }
        }
        return false;
    }
    
    public function getModificationsByItem($item_id, $shop_group_id){
        if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json') {
            $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json', true);
            if($file){
                $file_array =  json_decode($file);
                $items = array();
                foreach($file_array as $key => $value){
                    if($value->modification_id == $item_id){
                        $items[] = $value->id;
                    }
                }
                if(count($items)>0){
                    return $items;
                }
                return false;
            }
        }
        return false;
    }
    
    public function GetMinMax($shop_group_id){
        if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json') {
            $file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/hostcmsfiles/json/'.$shop_group_id.'.json', true);
            if($file){
                $file_array =  json_decode($file);
                $res = $p = array();
                foreach($file_array as $key =>$value){
                    if(isset($value->current_price) and $value->current_price !==''{
                        $p[] = $value->current_price;    
                    }
                }
                if(count($p)>0){
                    $res["min"] = min($p);
                    $res["max"] = max($p);  
                    return $res;
                }
                return false;
            }
        }
        return false;
    }

    function GetSubgroup($group, $shop_id, $get_level, $start_level){
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('id', 'sorting'// A-Z
           ->from('shop_groups'
           ->open()
           ->where('parent_id', '=', $group)
           ->setAnd()
           ->where('shop_id', '=', $shop_id)
           ->setAnd()
           ->where('active', '=', 1)
           ->setAnd()
           ->where('deleted', '=', 0)
           ->close()
           ;
        $aRows = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
        if($aRows and count($aRows)>0){
            foreach($aRows as $key => $group){
                $array[$key]["id"] = $group["id"];
                $array[$key]["sorting"] = $group["sorting"];//                
                if($start_level < $get_level){
                    $new_level = $start_level + 1;
                    $array_sub = $this->GetSubgroup($group["id"], $shop_id, $get_level, $new_level);
                    if($array_sub and count($array_sub)>0){
                        $array[$key]["subgroups"] = $array_sub;
                    }
                }
            }
            return $array;  
        }  
    }
    
    function GetValueColorSize($item_id, $property_id_1, $property_id_2, $property_id_1_value){
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('property_value_ints.entity_id'
        ->from('property_value_ints'
        ->leftJoin('shop_items', 'property_value_ints.entity_id', '=', 'shop_items.id'
        ->open()
            ->where('property_value_ints.property_id','=',$property_id_1)
            ->setAnd()
            ->where('property_value_ints.value','=',$property_id_1_value)
            ->setAnd()
            ->where('shop_items.modification_id','=',$item_id)
            ->setAnd()
            ->where('shop_items.deleted','=',0)
            ->setAnd()
            ->where('shop_items.active','=',1)
        ->close();
        $oCore_QueryBuilder_Select2 = Core_QueryBuilder::select("value"
            ->from('property_value_ints'
            ->open()
            ->where('property_id','=',$property_id_2)
            ->setAnd()
            ->where('entity_id','IN',$oCore_QueryBuilder_Select)
            ->close();
        $aRows = $oCore_QueryBuilder_Select2->execute()->asAssoc()->result();
        return $aRows;
    }
    
    function GetValueColorSizeAlloption($item_id, $property_id){
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('property_value_ints.entity_id'
        ->from('property_value_ints'
        ->leftJoin('shop_items', 'property_value_ints.entity_id', '=', 'shop_items.id'
        ->open()
            ->where('property_value_ints.property_id','=',$property_id)
            ->setAnd()
            ->where('shop_items.modification_id','=',$item_id)
            ->setAnd()
            ->where('shop_items.deleted','=',0)
            ->setAnd()
            ->where('shop_items.active','=',1)
        ->close();
        $oCore_QueryBuilder_Select2 = Core_QueryBuilder::select("value"
            ->from('property_value_ints'
            ->open()
            ->where('property_id','=',$property_id)
            ->setAnd()
            ->where('entity_id','IN',$oCore_QueryBuilder_Select)
            ->close();
        $aRows = $oCore_QueryBuilder_Select2->execute()->asAssoc()->result();
        return $aRows;
    }

    function GetElementId($item_id, $property_id_1, $property_id_2, $property_value_1, $property_value_2){
        
        $having = 0;
        
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select("shop_items.id"
            ->from('shop_items'
            ->leftJoin('property_value_ints', 'shop_items.id', '=', 'property_value_ints.entity_id'
            ->open()
            ->where('shop_items.modification_id','=',$item_id)
            ->setAnd()
            ->where('shop_items.deleted','=',0)
            ->setAnd()
            ->where('shop_items.active','=',1)
            ->close();
        
        if($property_value_1 > 0 or $property_value_2 > 0){
            $oCore_QueryBuilder_Select->open();
        }
        
        if($property_value_1 > 0){
            $having++;
            $oCore_QueryBuilder_Select
                ->open()
                    ->where('property_value_ints.property_id','=',$property_id_1)
                    ->setAnd()
                    ->where('property_value_ints.value','=',$property_value_1)
                ->close();
        }
        
        if($property_value_2 > 0){
            $having++;
            
            if($property_value_1 > 0){
                $oCore_QueryBuilder_Select->setOr();
            }
            
            $oCore_QueryBuilder_Select
                ->open()
                    ->where('property_value_ints.property_id','=',$property_id_2)
                    ->setAnd()
                    ->where('property_value_ints.value','=',$property_value_2)
                ->close();
        }
        
        if($property_value_1 > 0 or $property_value_2 > 0){
            $oCore_QueryBuilder_Select->close();
        }
    
        if($having > 0){
            $oCore_QueryBuilder_Select->groupBy('shop_items.id';
            $oCore_QueryBuilder_Select->having(Core_QueryBuilder::expression('COUNT(DISTINCT property_value_ints.property_id)', '>=', $having);
        }
        $aRows = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
        
        return $aRows;
        
    }

    function CheckItemActive($item_id){
        $oItem = Core_Entity::factory('Shop_Item', $item_id);
        if($oItem->active == 1 && $oItem->deleted == 0){
            $oGroup = Core_Entity::factory('Shop_Group', $oItem->shop_group_id);
            if($oGroup->active == 1 && $oGroup->deleted == 0){
                while ($oGroup->parent_id != 0 && $oGroup = $oGroup->getParent()){
                    if($oGroup->active !== '1' or $oGroup->deleted == '1'{
                        //print "active " . $oGroup->active ."<br>";
                        //print "deleted " . $oGroup->deleted ."<br>";
                        //print $oGroup->id ."<br>";
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
        return false;
    }

    function GetAssociatedItem($item_id){
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select("shop_item_associated.shop_item_associated_id", "shop_items.shop_group_id"
            ->from('shop_item_associated'
            ->leftJoin('shop_items', 'shop_item_associated.shop_item_id', '=', 'shop_items.id'
            ->open()
            ->where('shop_item_associated.shop_item_id','=',$item_id)
            ->setAnd()
            ->where('shop_items.deleted','=',0)
            ->setAnd()
            ->where('shop_items.active','=',1)
            ->close()
            ;
        $aRows = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
        $g = false;
        if($aRows and count($aRows)>0){
            foreach($aRows as $key => $value){
                $check_active = $this->CheckItemActive($value["shop_item_associated_id"]);
                if($check_active){
                    $g[] = $value["shop_item_associated_id"];
                }
            }
            return $g;  
        }
        else{
            return false;
        }  
    }
    

    public function getSubGroups($current_group){
        $oGroup = Core_Entity::factory('Shop_Group', $current_group);
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select("id"
           ->from('shop_groups'
           ->open()
           ->where('parent_id', '=', $current_group)
           ->setAnd()
           ->where('active', '=', 1)
           ->setAnd()
           ->where('deleted', '=', 0)
           ->close();
        $groups_row = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
        if(count($groups_row)>0){
            foreach($groups_row as $key => $g){
                $groups[] = $g["id"];
                $array_sub = $this->getSubGroups($g["id"]);
                if($array_sub){
                    $groups[] = $array_sub;
                }
            }
            return $groups;
        }
        else{
            return false;
        }
    }
    
    public function ArrayMerge($array){
        if(count($array)>0){
            $arrOut = array();
            foreach($array as $key => $val){
                if(is_numeric($val)){
                     $arrOut[] = $val;
                }
                else{
                     $res = $this->ArrayMerge($val);
                     foreach($res as $k => $v){
                         $arrOut[] = $v;
                     }
                }
            }
            return $arrOut;  
        }
        else{
            return $array;
        }
    }
    
/*
    public function GetMinMax($subGroups, $oShop){
        $aShop_Currencies = Core_Entity::factory('Shop_Currency'->findAll();

        $query_currency_switch = 'price';
        foreach ($aShop_Currencies as $oShop_Currency)
        {
            $currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
                $oShop_Currency, $oShop->Shop_Currency
            );

            $query_currency_switch = "IF (`shop_items`.`shop_currency_id` = '{$oShop_Currency->id}', IF (shop_discounts.value, IF(shop_discounts.type, price * {$currency_coefficient} - shop_discounts.value, price * (100 - shop_discounts.value) * {$currency_coefficient} / 100), shop_items.price * {$currency_coefficient}), {$query_currency_switch})";
        }

        $current_date = date('Y-m-d H:i:s';

        $oSubMinMaxQueryBuilder = Core_QueryBuilder::select(array(Core_QueryBuilder::expression($query_currency_switch), 'absolute_price')
            ->from('shop_items'
            ->leftJoin('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.shop_item_id'
            ->leftJoin('shop_discounts', 'shop_item_discounts.shop_discount_id', '=', 'shop_discounts.id', array(
                array('AND (' => array('shop_discounts.end_datetime', '>=', $current_date)),
                array('OR' => array('shop_discounts.end_datetime', '=', '0000-00-00 00:00:00'),
                array('AND' => array('shop_discounts.start_datetime', '<=', $current_date)),
                array('' => NULL)
            ))
            ->where('shop_items.shop_group_id', 'IN', $subGroups)
            ->groupBy('shop_items.id';

        $oMinMaxQueryBuilder = Core_QueryBuilder::select(
            array(Core_QueryBuilder::expression('MIN(t.absolute_price)', 'min',
            array(Core_QueryBuilder::expression('MAX(t.absolute_price)', 'max'
        )
        ->from(array($oSubMinMaxQueryBuilder, 't');

        $rows = $oMinMaxQueryBuilder->asAssoc()->execute()->current();
        
        return $rows;
    }
    
    

    function GetMinMaxByItems($getItemsId, $oShop){
        
        $getItemsId = $this->getModificationAndItems($getItemsId);

        $aShop_Currencies = Core_Entity::factory('Shop_Currency'->findAll();

        $query_currency_switch = 'price';
        foreach ($aShop_Currencies as $oShop_Currency)
        {
            $currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
                $oShop_Currency, $oShop->Shop_Currency
            );

            $query_currency_switch = "IF (`shop_items`.`shop_currency_id` = '{$oShop_Currency->id}', IF (shop_discounts.value, IF(shop_discounts.type, price * {$currency_coefficient} - shop_discounts.value, price * (100 - shop_discounts.value) * {$currency_coefficient} / 100), shop_items.price * {$currency_coefficient}), {$query_currency_switch})";
        }

        $current_date = date('Y-m-d H:i:s';

        $oSubMinMaxQueryBuilder = Core_QueryBuilder::select(array(Core_QueryBuilder::expression($query_currency_switch), 'absolute_price')
            ->from('shop_items'
            ->leftJoin('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.shop_item_id'
            ->leftJoin('shop_discounts', 'shop_item_discounts.shop_discount_id', '=', 'shop_discounts.id', array(
                array('AND (' => array('shop_discounts.end_datetime', '>=', $current_date)),
                array('OR' => array('shop_discounts.end_datetime', '=', '0000-00-00 00:00:00'),
                array('AND' => array('shop_discounts.start_datetime', '<=', $current_date)),
                array('' => NULL)
            ))
            ->where('shop_items.id', 'IN', $getItemsId)
            ->groupBy('shop_items.id';

        $oMinMaxQueryBuilder = Core_QueryBuilder::select(
            array(Core_QueryBuilder::expression('MIN(t.absolute_price)', 'min',
            array(Core_QueryBuilder::expression('MAX(t.absolute_price)', 'max'
        )
        ->from(array($oSubMinMaxQueryBuilder, 't');

        $rows = $oMinMaxQueryBuilder->asAssoc()->execute()->current();
        
        return $rows;  
    }
    

    public function getItemsId($groups, $shop_id){
        
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select("id"
           ->from('shop_items';
          
        if($groups and is_numeric($groups)){
            $groups = array($groups);
            $oCore_QueryBuilder_Select
               ->open()
               ->where('shop_group_id', 'IN', $groups)
               ->setAnd();
        }
        else{
            $oCore_QueryBuilder_Select
               ->open()
                    ->where('shop_id', '=', $shop_id)
               ->setAnd();    
        }

          
        $oCore_QueryBuilder_Select
           ->where('active', '=', 1)
           ->setAnd()
           ->where('deleted', '=', 0)
           ->close();  
        $items_row = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
        if(count($items_row)>0){
            foreach($items_row as $key => $i){
                $items[] = $i["id"];                
            }
            return $items;
        }
        else{
            return false;
        }    
    }
    
    

    function getItemsIdWithDiscount($oShop){
        
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select("shop_items.id"
           ->from('shop_items';
        
        
        $aShop_Currencies = Core_Entity::factory('Shop_Currency'->findAll();
        $query_currency_switch = 'price';
        foreach ($aShop_Currencies as $oShop_Currency)
        {
            
            $currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
                $oShop_Currency, $oShop->Shop_Currency
            );

            $query_currency_switch = "IF (`shop_items`.`shop_currency_id` = '{$oShop_Currency->id}', IF (shop_discounts.value, IF(shop_discounts.type, price * {$currency_coefficient} - shop_discounts.value, price * (100 - shop_discounts.value) * {$currency_coefficient} / 100), shop_items.price * {$currency_coefficient}), {$query_currency_switch})";
        }
        
        

        $query_id_switch = "IF (shop_items.modification_id > 0, shop_items.modification_id, shop_items.id)";
        $current_date = date('Y-m-d H:i:s';
        $oCore_QueryBuilder_Select
            ->select(array(Core_QueryBuilder::expression($query_id_switch), 'id')
            ->select(array(Core_QueryBuilder::expression($query_currency_switch), 'absolute_price')
            ->leftJoin('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.shop_item_id'
            ->leftJoin('shop_discounts', 'shop_item_discounts.shop_discount_id', '=', 'shop_discounts.id', array(
                array('AND (' => array('shop_discounts.end_datetime', '>=', $current_date)),
                array('OR' => array('shop_discounts.end_datetime', '=', '0000-00-00 00:00:00'),
                array('AND' => array('shop_discounts.start_datetime', '<=', $current_date)),
                array('' => NULL)
            ))
           ->open()
           ->where('shop_items.shop_id', '=', $oShop->id)
           ->setAnd()
           ->where('shop_items.active', '=', 1)
           ->setAnd()
           ->where('shop_items.deleted', '=', 0)
           ->setAnd()
           ->where('shop_item_discounts.shop_discount_id', '>', 0)
           ->close()
           ->groupBy('shop_items.id';
          
           $items_row = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
           if($items_row && count($items_row)>0){
                foreach($items_row as $key => $i){
                    $items[] = $i["id"];                
                }  
                return $items;
           }

           return false;
    }
    

    public function getModificationAndItems($items){
        $oCore_QueryBuilder_Select2 = Core_QueryBuilder::select("id"
           ->from('shop_items'
           ->open()
           ->where('modification_id', 'IN', $items)
           ->setAnd()
           ->where('active', '=', 1)
           ->setAnd()
           ->where('deleted', '=', 0)
           ->close();

        $items_row = $oCore_QueryBuilder_Select2->execute()->asAssoc()->result();      
        if($items_row && count($items_row)>0){
            foreach($items_row as $key => $i){
                $items[] = $i["id"];                
            }  
            return $items;
        }    
        else{
            return $items;
        }
    }
    
    


    public function getValues($property_id, $type, $items){

        $items = $this->getModificationAndItems($items);
        if($items and count($items)>0){
            $oCore_QueryBuilder_Select = Core_QueryBuilder::select(Core_QueryBuilder::expression('DISTINCT(`property_value_ints`.`value`)')
               ->from('property_value_ints'
               ->open()
                    ->where('entity_id', 'IN', $items)
                    ->setAnd()
                    ->where('property_id', '=', $property_id)
                    ->setAnd()
                    ->where('value', '!=', 0)
               ->close();
               return $oCore_QueryBuilder_Select->execute()->asAssoc()->result();    
        }
        return false;


    }
    

    public function GetFilter($form, $group, $result_type){
        $property_array = array();

        foreach($form as $key => $value){
            //$_GET["$key"] = $value;
            $explode = explode("_", $key);
            if(count($explode)>0 and $explode["0"] =="property"{
                $property_id = $explode["1"];
                $property_array[$property_id] = $value;  
            }
        }
        
        $oShop_Group = Core_Entity::factory('Shop_Group', $group);
        $oShop = $oShop_Group->Shop;


        
        $current_date = date('Y-m-d H:i:s';  
        $price_from =  intval(Core_Array::getGet('price_from');
        $price_to =  intval(Core_Array::getGet('price_to');

        $query_currency_switch = "";
        if ($price_from || $price_to)
        {
            // Ïîëó÷àåì ñïèñîê âàëþò ìàãàçèГГ 
            $aShop_Currencies = Core_Entity::factory('Shop_Currency'->findAll();

            $query_currency_switch = 'price';
            
            foreach ($aShop_Currencies as $oShop_Currency)
            {
                // Ïîëó÷àåì êîýôôèöèåГГІ ïåðåñ÷åòà äëÿ êàæäîé âàëþòû
                $currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
                    $oShop_Currency, $oShop->Shop_Currency
                );

                $query_currency_switch = "IF (`shop_items`.`shop_currency_id` = '{$oShop_Currency->id}', IF (shop_discounts.value, IF(shop_discounts.type, price * {$currency_coefficient} - shop_discounts.value, price * (100 - shop_discounts.value) * {$currency_coefficient} / 100), shop_items.price * {$currency_coefficient}), {$query_currency_switch})";
            }
            
            if($query_currency_switch !==''{
                $query_currency_switch =", $query_currency_switch AS `absolute_price` ";    
            }
            
            
        }

        $sql ="
            SELECT SQL_CALC_FOUND_ROWS
            IF (`shop_items`.`modification_id` > 0, `shop_items`.`modification_id`, `shop_items`.`id`) AS `id`
            $query_currency_switch
            FROM `shop_items`
            LEFT OUTER JOIN `shop_item_discounts` ON `shop_items`.`id` = `shop_item_discounts`.`shop_item_id`
            LEFT OUTER JOIN `shop_discounts` ON `shop_item_discounts`.`shop_discount_id` = `shop_discounts`.`id`
            AND (  `shop_discounts`.`end_datetime` >= '$current_date' OR `shop_discounts`.`end_datetime` = '0000-00-00 00:00:00'
            AND `shop_discounts`.`start_datetime` <= '$current_date' )";
            
        if(count($property_array)>0){
            $sql .="  
                LEFT OUTER JOIN `shop_item_properties` ON `shop_items`.`shop_id` = `shop_item_properties`.`shop_id`
                LEFT OUTER JOIN `property_value_ints` ON `shop_items`.`id` = `property_value_ints`.`entity_id`
                AND  `shop_item_properties`.`property_id` = property_value_ints.property_id";
        }
        
        if(isset($form["rest"]) and $form["rest"] =='1'{
            $sql .=" LEFT OUTER JOIN `shop_warehouse_items` ON `shop_items`.`id` = `shop_warehouse_items`.`shop_item_id` ";  
        }
            
        $sql .="
            WHERE  `shop_items`.`shop_id` = '". $oShop->id ."'
            AND (  `shop_items`.`start_datetime` < '$current_date' OR `shop_items`.`start_datetime` = '0000-00-00 00:00:00'  )
            AND (  `shop_items`.`end_datetime` > '$current_date' OR `shop_items`.`end_datetime` = '0000-00-00 00:00:00'  )
            AND `shop_items`.`siteuser_group_id` IN (0, -1)
            AND `shop_items`.`deleted` = 0
            AND `shop_items`.`active` = 1
            ";
            
        if(isset($form["rest"]) and $form["rest"] =='1'{
            $sql .=" AND  `shop_warehouse_items`.`count` > 0 ";  
        }
        
        if(isset($form["discount"]) and $form["discount"] =='1'{
            $sql .=" AND  `shop_item_discounts`.`shop_discount_id` > 0 ";  
            
            //ïîëó÷èì ГўГ±ГҐ òîâàðû ГЁ ìîäèôèêàöèè ýòîé ãðóïïû
            $items = $this->getItemsId(false, $oShop->id);
        }
        else{
            //ïîëó÷èì ГўГ±ГҐ òîâàðû ГЁ ìîäèôèêàöèè ýòîé ãðóïïû
            $items = $this->getItemsId($group, $oShop->id);  
        }
            
            //ïîëó÷èì ГЁ òîâàðû ГЁ ìîäèôèêàöèè
            if($items and count($items)>0){
                $items_mod = $this->getModificationAndItems($items);
                if($items_mod and count($items_mod)>0){
                    foreach($items_mod as $key => $value){
                        $items[] = $value;    
                    }      
                }
                
                $sql .=" AND `shop_items`.`id` IN (". implode(",", $items) ." ";  
            }
      
            if(count($property_array)>0){
                $sql .=" AND(";
                $i=0;
                $property_array_simply = array();
                //Г¶ГЁГЄГ« ГЇГ® Г¬ГîæåñòâåГГûì ñâîéñòâàì
                foreach($property_array as $key => $value){
                    if(is_array($value) && count($value)>0){
                        $sql .="(";
                        $j=0;
                        foreach($value as $key2 => $val){
                            $sql .="(`shop_item_properties`.`property_id` = '$key' AND `property_value_ints`.`value` = '$val'";
                            if($j !== count($value)-1){
                                $sql .=" OR ";    
                            }  
                            $j++;
                        }
                        $sql .="";
                        
                        if($i !== count($property_array)-1){
                            $sql .=" OR ";    
                        }
                        $i++;    
                    }
                    // ñôîðìèðóåì îäГîìåðГûé ìàññèâ Г± ïðîñòûìè checkbox
                    if(!is_array($value) && $value =='on'{
                        $property_array_simply[] = $key;
                    }
                }
                //Г¶ГЁГЄГ« ГЇГ® îäГîìåðГîìó ìàññèâó Г± ïðîñòûìè checkbox
                if(count($property_array_simply)>0){
                    foreach($property_array_simply as $key => $value){
                        if($key > 0){$sql .=" OR";}
                        $sql .=" (`shop_item_properties`.`property_id` = '$value' AND `property_value_ints`.`value` = '1' ";
                    }
                }
                $sql .="";  
            }
            
            if(count($property_array)>0 and ($price_from || $price_to)){
                $count_property = count($property_array);  
                $sql .=" GROUP BY `shop_items`.`id` HAVING  `absolute_price` >= $price_from AND `absolute_price` <= $price_to AND COUNT(DISTINCT `shop_item_properties`.`property_id`) = $count_property ";  
            }
            else if(count($property_array) == 0 and ($price_from || $price_to)){
                $sql .=" HAVING  `absolute_price` >= $price_from AND `absolute_price` <= $price_to";    
            }
        
            
            
        $select = mysql_query($sql);
        
        $count = mysql_num_rows($select);
        if($count>0){
            while($array = mysql_fetch_array($select)){
                $result_array[] = $array["id"];
            }

            $result = array_values(array_unique($result_array));
            
            if($result_type =="count"{
                return count($result);    
            }
            else{
                return $result;
            }  
        }
        else{
            return false;
        }
    }  
    
      */
    function GetCountItemFromGroup($group_id){
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select(Core_QueryBuilder::expression('COUNT(`shop_items`.`id`) as count')
           ->from('shop_items'
           ->open()
                ->where('shop_group_id', '=', $group_id)
                ->setAnd()
                ->where('active', '=', 1)
                ->setAnd()
                ->where('deleted', '=', 0)
           ->close();  
        return $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
      
    }


    /*
    * для слайдера на главной странице
    */
    function GetShopItemIdByProperties($property_id){
        $a = false;
        $oCore_QueryBuilder_Select = Core_QueryBuilder::select('shop_items.id', 'shop_items.modification_id'
            ->from('shop_items'
            ->leftJoin('shop_item_properties', 'shop_items.shop_id', '=', 'shop_item_properties.shop_id'
            ->leftJoin('property_value_ints', 'shop_items.id', '=', 'property_value_ints.entity_id',
              array(
                 array('AND' => array('shop_item_properties.property_id', '=', Core_QueryBuilder::expression('`property_value_ints`.`property_id`'))
              )
            )
            ->groupBy('shop_items.id'
            ->where('property_value_ints.property_id', '=', $property_id)
            ->open()
                ->where('property_value_ints.value', '=', 1)
                ->setAnd()  
                ->where('shop_items.active', '=', 1)
                ->setAnd()
                ->where('shop_items.deleted', '=', 0)
            ->close()
         ->limit(10); // A-Z;  
        $row = $oCore_QueryBuilder_Select->execute()->asAssoc()->result();
        if($row and count($row)>0){
            //преобразуем в одномерный
            foreach($row as $key => $value){
                //проверим, если модификация,
                if($value["modification_id"] > 0){
                    $oCore_QueryBuilder_Select = Core_QueryBuilder::select('shop_items.id'
                        ->from('shop_items'
                        ->leftJoin('shop_groups', 'shop_items.shop_group_id', '=', 'shop_groups.id'
                        ->open()
                            ->where('shop_groups.active', '=', 1)
                            ->setAnd()
                            ->where('shop_groups.deleted', '=', 0)
                            ->setAnd()    
                            ->where('shop_items.active', '=', 1)
                            ->setAnd()
                            ->where('shop_items.deleted', '=', 0)
                            ->setAnd()
                            ->where('shop_items.id', '=', $value["modification_id"])
                        ->close();  
                
                    $row2 = $oCore_QueryBuilder_Select->execute()->asAssoc()->current();
                    if($row2 and count($row2)>0){
                        $a[] = $value["id"];    
                    }    
                }
                else{
                    $oCore_QueryBuilder_Select = Core_QueryBuilder::select('shop_items.id'
                        ->from('shop_items'
                        ->leftJoin('shop_groups', 'shop_items.shop_group_id', '=', 'shop_groups.id'
                        ->open()
                            ->where('shop_groups.active', '=', 1)
                            ->setAnd()
                            ->where('shop_groups.deleted', '=', 0)
                            ->setAnd()    
                            ->where('shop_items.active', '=', 1)
                            ->setAnd()
                            ->where('shop_items.deleted', '=', 0)
                            ->setAnd()
                            ->where('shop_items.id', '=', $value["id"])
                        ->close();  
                    $row2 = $oCore_QueryBuilder_Select->execute()->asAssoc()->current();
                    if($row2 and count($row2)>0){
                        $a[] = $value["id"];    
                    }  
                }
            }
            return $a;
        }    
        return false;
    }  
}


?>





Модератор
#
Re: Ошибка в файле PHP
Вам нужно обратиться к автору этого модуля, данный файл не входит в поставку HostCMS.
Авторизация