Перейти к содержанию

DenKuzmin

Пользователь
  • Постов

    8
  • Зарегистрирован

  • Посещение

Сообщения, опубликованные DenKuzmin

  1. Как разместить на странице API-карту Яндекс через "HTML-содержимое"?
    Вставляю просто

    <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU&apikey=КЛЮЧ***"></script>
                <div id="map" style="width: 100%; height: 480px"></div>
                <script src="/catalog/view/javascript/map.js"></script>

    В консоли ymaps is not defined

     

    Если вместо <script src="/catalog/view/javascript/map.js"></script> вставляю

    <script>
    ymaps.ready(function () {
        var myMap = new ymaps.Map('map', {
                center: [59.961430, 30.457771],
                zoom: 10
            }, {
                searchControlProvider: 'yandex#search'
            }),
    
            // создаём метку (Просвещения)
            placemark1 = new ymaps.Placemark([60.054949, 30.328786], {
                hintContent: 'Салон Мебель Массив на Просвещения'
            },
    
        myMap.geoObjects
            .add(placemark1);
    });
    </script>

    При сохранении это вырезает.

  2. Вывожу в слайдер картинки через модуль banner. Путь до картинок подставляю через banner[link]
    Как создать дополнительную переменную banner[link_mob], чтобы в пути до картинки заменить часть пути /desktop/ на /mobile/?

     

    Код контроллера banner:

    <?php
    class ControllerExtensionModuleBanner extends Controller {
    	public function index($setting) {
    		static $module = 0;
    		$this->load->model('design/banner');
    		$this->load->model('tool/image');
    		$this->document->addStyle('catalog/view/javascript/jquery/owl-carousel/owl.carousel.css');
    		$this->document->addStyle('catalog/view/javascript/jquery/owl-carousel/owl.transitions.css');
    		$this->document->addScript('catalog/view/javascript/jquery/owl-carousel/owl.carousel.min.js');
    		$data['banners'] = array();
    		$results = $this->model_design_banner->getBanner($setting['banner_id']);
    		foreach ($results as $result) {
    			if (is_file(DIR_IMAGE . $result['image'])) {
    				$data['banners'][] = array(
    					'title' => $result['title'],
    					'link'  => $result['link'],
    					'class' => $result['class'],
    					'image' => $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height'])
    				);
    			}
    		}
    		$data['module'] = $module++;
    		return $this->load->view('extension/module/banner', $data);
    	}
    }

     

    Хочу получить что-то вроде

    				$data['banners'][] = array(
    					'title' => $result['title'],
    					'link'  => $result['link'],
    					'link_mob' => $result['link_mob'],
    					'class' => $result['class'],
    					'image' => $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height'])
    				);

     

  3. В статье есть простая форма с 1 полем.

    <form action="" method="post" enctype="multipart/form-data" id="test_form">
      <input type="text" value="">
      <input type="submit" value="Отправить" for="test_form">
    </form>


    Как записать значение поля "text", в таблицу os_test в БД?

  4. Это файл контроллера ocfilter (4.7). Пытаюсь немного его изменить, чтобы если нет результатов, то выводил на пустую страницу.

    Подскажите, пожалуйста, где тут строка, которая отвечает за формирование url, если товары не найдены?

    Спойлер
    <?php
    
    class ControllerExtensionModuleOCFilter extends Controller {
      protected $registry;
      protected $data = array();
    
      public function __construct($registry) {
        parent::__construct($registry);
    
        if ($this->registry->has('ocfilter')) {
          $this->data = $this->registry->get('ocfilter')->data;
    
          return;
        }
    
        $this->load->language('extension/module/ocfilter');
    
        $this->load->config('ocfilter');
        $this->load->helper('ocfilter');
    
      	$this->load->model('catalog/ocfilter');
    		$this->load->model('catalog/product');
        $this->load->model('tool/image');
    
        // Decode URL
        $this->decode();
    
        if (!$this->path) {
        	return;
        }
    
        $parts = explode('_', $this->path);
    
        $this->category_id = (int)end($parts);
    
        if (isset($this->request->get['filter_ocfilter'])) {
          $this->params = cleanParamsString($this->request->get['filter_ocfilter'], $this->config);
    
          if ($this->params) {
            $options_get = decodeParamsFromString($this->params, $this->config);
    
      			$this->options_get = $options_get;
    
            if ($this->config->get('ocfilter_show_price') && !empty($options_get['p'])) {
              $range = getRangeParts(end($options_get['p']));
    
              if (isset($range['from']) && isset($range['to'])) {
              	$this->min_price_get = $range['from'];
              	$this->max_price_get = $range['to'];
              }
            }
    
            if (!$this->page_info) {
             	$this->document->setNoindex(true);
            }
          }
        }
    
        // Get values counter
        $filter_data = array(
    			'filter_category_id' => $this->category_id,
          'filter_ocfilter' => $this->params
    		);
    
    		$this->counters = $this->model_catalog_ocfilter->getCounters($filter_data);
    
        if ($this->config->get('ocfilter_show_price')) {
          $filter_data['filter_ocfilter'] = $this->cancelOptionParams('p');
    
          $this->product_prices = $this->model_catalog_ocfilter->getProductPrices($filter_data);
    
          if ($this->product_prices) {
            $this->min_price = $this->currency->format(floor($this->product_prices['min']), $this->session->data['currency'], '', false);
            $this->max_price = $this->currency->format(ceil($this->product_prices['max']), $this->session->data['currency'], '', false);
          }
        }
    
        $this->registry->set('ocfilter', $this);
      }
    
      // Array access
      public function __get($key) {
        if (isset($this->data[$key])) {
          return $this->data[$key];
        } else if ($this->registry->has($key)) {
          return $this->registry->get($key);
        } else {
          return null;
        }
      }
    
      public function __set($key, $value) {
        $this->data[$key] = $value;
      }
    
      // Empty method to prevent execution of index()
      public function initialise() {
    
      }
    
    	public function index($settings = array()) {
        if (!$this->category_id) {
        	return;
        }
    
        $this->load->language('extension/module/ocfilter');
    
        if ($this->config->get('ocfilter_show_price') && $this->min_price < $this->max_price - 1) {
          $data['show_price'] = 1;
        } else {
          $data['show_price'] = 0;
        }
    
        $data['heading_title'] = $this->language->get('heading_title');
    
    		if ($this->min_price_get && $this->min_price_get < $this->min_price) {
    			$this->min_price = $this->min_price_get;
        }
    
    		if ($this->max_price_get && $this->max_price_get > $this->max_price) {
    			$this->max_price = $this->max_price_get;
        }
    
        $data['options']              = $this->getOCFilterOptions();
        $data['min_price']            = $this->min_price;
    		$data['max_price']            = $this->max_price;
        $data['min_price_get']        = $this->min_price_get ? $this->min_price_get : $this->min_price;
        $data['max_price_get']        = $this->max_price_get ? $this->max_price_get : $this->max_price;
        $data['path']                 = $this->path;
    
        $data['link']                 = str_replace('&amp;', '&', $this->link());
    
        $data['params']               = $this->params;
    
        $data['index']   							= $this->config->get('ocfilter_url_index');
        $data['show_counter']         = $this->config->get('ocfilter_show_counter');
        $data['search_button']        = $this->config->get('ocfilter_search_button');
        $data['show_values_limit']   	= $this->config->get('ocfilter_show_values_limit');
        $data['manual_price']         = $this->config->get('ocfilter_manual_price');
    
        $data['text_show_all']        = $this->language->get('text_show_all');
        $data['text_hide']          	= $this->language->get('text_hide');
        $data['button_select']        = $this->language->get('button_select');
        $data['text_load']            = $this->language->get('text_load');
        $data['text_price']           = $this->language->get('text_price');
        $data['text_any']           	= $this->language->get('text_any');
        $data['text_cancel_all']      = $this->language->get('text_cancel_all');
    
        $data['symbol_left']      		= $this->currency->getSymbolLeft($this->session->data['currency']);
        $data['symbol_right']      		= $this->currency->getSymbolRight($this->session->data['currency']);
    
        $data['show_options'] = !empty($this->params);
    
        if ($this->config->get('ocfilter_show_selected') && $this->options_get) {
          $data['selecteds'] = $this->getSelectedOptions();
        } else {
          $data['selecteds'] = array();
        }
    
    		if ($this->config->get('ocfilter_show_options_limit') && $this->config->get('ocfilter_show_options_limit') < count($data['options'])) {
        	$data['show_options_limit'] = $this->config->get('ocfilter_show_options_limit');
    		} else {
          $data['show_options_limit'] = false;
    		}
    
        $this->document->addStyle('catalog/view/javascript/ocfilter/nouislider.min.css');
        $this->document->addStyle('catalog/view/theme/default/stylesheet/ocfilter/ocfilter.css');
    
        $this->document->addScript('catalog/view/javascript/ocfilter/nouislider.min.js');
        $this->document->addScript('catalog/view/javascript/ocfilter/ocfilter.js');
    
    		return $this->load->view('extension/module/ocfilter/module', $data);
    	}
    
    	protected function getOCFilterOptions() {
        if (!is_null($this->options)) {
        	return $this->options;
        }
    
        $options = array();
    
        // Manufacturers filtering
        if ($this->config->get('ocfilter_manufacturer')) {
      		$results = $this->model_catalog_ocfilter->getManufacturersByCategoryId($this->category_id);
    
          if ($results) {
            $options[] = array(
              'option_id'   => 'm',
              'name'        => $this->language->get('text_manufacturer'),
              'description' => $this->language->get('text_manufacturer_description'),
              'type'        => $this->config->get('ocfilter_manufacturer_type'),
              'values'      => $results
            );
          }
        }
    
        // Stock status filtering
        if ($this->config->get('ocfilter_stock_status')) {
    			if ($this->config->get('ocfilter_stock_status_method') == 'stock_status_id') {
    				$results = $this->model_catalog_ocfilter->getStockStatuses();
    
    	      $options['stock'] = array(
    	        'option_id'   => 's',
    	        'name'        => $this->language->get('text_stock'),
              'description' => $this->language->get('text_stock_description'),
    	        'type'        => $this->config->get('ocfilter_stock_status_type'),
    	        'values'      => $results
    	      );
    			} else if ($this->config->get('ocfilter_stock_status_method') == 'quantity') {
    	      $options['stock'] = array(
    	        'option_id'   => 's',
    	        'name'        => $this->language->get('text_stock'),
              'description' => $this->language->get('text_stock_description'),
    	        'type'        => ($this->config->get('ocfilter_stock_out_value') ? 'radio' : 'checkbox'),
    	        'values'      => array(
    						array(
    							'value_id'    => 'in',
    							'name'        => 'В наличии'
    						)
    					)
    	      );
    
    				if ($this->config->get('ocfilter_stock_out_value')) {
              $options['stock']['values'][] = array(
    						'value_id'    => 'out',
    						'name'        => $this->language->get('text_out_of_stock')
    					);
    				}
    			}
        }
    
        // Get category options
    	  $results = $this->model_catalog_ocfilter->getOCFilterOptionsByCategoryId($this->category_id);
    
        if ($results) {
    	 		$options = array_merge($options, $results);
    		}
    
        $options_data = array();
    
        $index = 0;
    
    	  foreach ($options as $key => $option) {
          if ($option['type'] == 'select') {
            $option['type'] = 'radio';
            $option['selectbox'] = true;
          }
    
          $this_option = isset($this->options_get[$option['option_id']]);
    
    			$values = array();
    
          if ($option['type'] != 'slide' && $option['type'] != 'slide_dual') {
    				foreach ($option['values'] as $value) {
    					$this_value = isset($this->options_get[$option['option_id']]) && in_array($value['value_id'], $this->options_get[$option['option_id']]);
    
              $count = 0;
    
    					if (isset($this->counters[$option['option_id'] . $value['value_id']])) {
    						if ($this_option && $option['type'] == 'checkbox') {
    							$count = '+' . $this->counters[$option['option_id'] . $value['value_id']];
    						} else {
    							$count = $this->counters[$option['option_id'] . $value['value_id']];
    						}
    					}
    
              if ($count || !$this->config->get('ocfilter_hide_empty_values')) {
    						if (isset($option['image']) && $option['image'] && isset($value['image']) && $value['image'] && file_exists(DIR_IMAGE . $value['image'])) {
                  $image = $this->model_tool_image->resize($value['image'], 19, 19);
    						} else {
    							$image = false;
    						}
    
                $params = $this->getValueParams($option['option_id'], $value['value_id'], $option['type']);
    
    	          $values[] = array(
    	            'value_id' => $value['value_id'],
    							'id'       => $option['option_id'] . $value['value_id'],
    	            'name'     => html_entity_decode($value['name'] . (isset($option['postfix']) ? $option['postfix'] : ''), ENT_QUOTES, 'UTF-8'),
                  'keyword'  => html_entity_decode((isset($value['keyword']) ? $value['keyword'] : $value['value_id']), ENT_QUOTES, 'UTF-8'),
    							'color'    => ((isset($value['color']) && $value['color']) ? $value['color'] : '#FFFFFF'),
                  'image'    => $image,
    	            'params'   => $params,
    							'count'    => $count,
    	            'selected' => $this_value
    	          );
    					}
            }
    
            if (!$values) {
            	continue;
            }
          } else {
            $range = $this->model_catalog_ocfilter->getSliderRange($option['option_id'], array(
        			'filter_category_id' => $this->category_id,
              'filter_ocfilter' => $this->cancelOptionParams($option['option_id']),
            ));
    
            if ($range['min'] == $range['max']) {
            	continue;
            }
    
            $option['slide_value_min'] = $range['min'];
            $option['slide_value_max'] = $range['max'];
          }
    
          if ($option['type'] == 'radio') {
            $params = $this->cancelOptionParams($option['option_id']);
    
    				if (isset($this->counters[$option['option_id'] . 'all'])) {
    					$count = $this->counters[$option['option_id'] . 'all'];
    				} else {
    					$count = 1;
    				}
    
            array_unshift($values, array(
              'value_id' => $option['option_id'],
    					'id'       => 'cancel-' . $option['option_id'],
              'name'     => $this->language->get('text_any'),
              'params'   => $params,
    					'count'    => $count,
              'selected' => !$this_option
            ));
    			}
    
          $option_data = array(
            'option_id'           => $option['option_id'],
            'index'               => ++$index,
           	'name'                => html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8'),
            'selectbox'           => (isset($option['selectbox']) ? $option['selectbox'] : false),
            'color'			          => (isset($option['color']) ? $option['color'] : false),
            'image'		            => (isset($option['image']) ? $option['image'] : false),
            'keyword'		          => (isset($option['keyword']) ? $option['keyword'] : $option['option_id']),
    				'postfix' 		        => (isset($option['postfix']) ? html_entity_decode($option['postfix'], ENT_QUOTES, 'UTF-8') : ''),
            'description'         => (isset($option['description']) ? $option['description'] : ''),
            'slide_value_min'     => (isset($option['slide_value_min']) ? $option['slide_value_min'] : 0),
            'slide_value_max'     => (isset($option['slide_value_max']) ? $option['slide_value_max'] : 0),
            'slide_value_min_get' => (isset($option['slide_value_min']) ? $option['slide_value_min'] : 0),
            'slide_value_max_get' => (isset($option['slide_value_max']) ? $option['slide_value_max'] : 0),
            'type'                => $option['type'],
            'selected'            => $this_option,
            'values'              => $values
          );
    
          if (($option['type'] == 'slide' || $option['type'] == 'slide_dual') && isset($this->options_get[$option['option_id']][0])) {
            $range = getRangeParts($this->options_get[$option['option_id']][0]);
    
            if (isset($range['from']) && isset($range['to'])) {
              $option_data['slide_value_min_get'] = $range['from'];
              $option_data['slide_value_max_get'] = $range['to'];
    
              // For getSelectedOptions
              array_unshift($option_data['values'], array(
                'value_id' => $range['from'] . '-' . $range['to'],
                'name'     => 'от ' . $range['from'] . ' до ' . $range['to'] . $option['postfix']
              ));
            }
          }
    
          $options_data[] = $option_data;
        } // End options each
    
        $this->options = $options_data;
    
        return $options_data;
      }
    
    	protected function getValueParams($option_id, $value_id, $type = 'checkbox') {
    		$decoded_params = decodeParamsFromString($this->params, $this->config);
    
    		if ($type == 'checkbox') {
    			if (isset($decoded_params[$option_id])) {
    				if (false !== $key = array_search($value_id, $decoded_params[$option_id])) {
    					unset($decoded_params[$option_id][$key]);
    				} else {
    					$decoded_params[$option_id][] = $value_id;
    				}
    			} else {
    				$decoded_params[$option_id] = array($value_id);
    			}
     		} else if ($type == 'select' || $type == 'radio') {
    			if (isset($decoded_params[$option_id])) {
    				unset($decoded_params[$option_id]);
    			}
    
    			$decoded_params[$option_id] = array($value_id);
    		}
    
    		return encodeParamsToString($decoded_params, $this->config);
    	}
    
      protected function cancelOptionParams($option_id) {
        if ($this->params) {
    			$params = decodeParamsFromString($this->params, $this->config);
    
    			if (isset($params[$option_id])) {
    				unset($params[$option_id]);
    			}
    
    			return encodeParamsToString($params, $this->config);
        }
      }
    
      protected function getSelectedOptions() {
        $selected_options = array();
    
        $category_options = $this->getOCFilterOptions();
    
        if ($this->min_price_get && $this->max_price_get) {
          $category_options[] = array(
            'option_id' => 'p',
            'name'      => $this->language->get('text_price'),
    				'type'      => 'select',
            'selected'  => isset($this->options_get['p']),
            'values'    => array(array(
    					'value_id' 	=> $this->min_price_get . '-' . $this->max_price_get,
              'name' 			=> 'от ' . $this->currency->getSymbolLeft($this->session->data['currency']) . $this->min_price_get . ' до ' . $this->max_price_get . $this->currency->getSymbolRight($this->session->data['currency'])
    				))
          );
        }
    
    		foreach ($category_options as $option) {
    			if (!$option['selected']) {
    				continue;
    			}
    
          $option_id = $option['option_id'];
    
    			$values = array();
    
    			foreach ($option['values'] as $value) {
            if (!in_array($value['value_id'], $this->options_get[$option_id])) {
              continue;
    				}
    
    			  $params = '';
    
            if (count($this->options_get) > 1 || count($this->options_get[$option_id]) > 1) {
              if ($option['type'] == 'radio' || $option['type'] == 'select' || $option['type'] == 'slide' || $option['type'] == 'slide_dual') {
                $params .= $this->cancelOptionParams($option_id);
              } else {
                $params .= $value['params'];
              }
            }
    
            $name = html_entity_decode($value['name'], ENT_QUOTES, 'UTF-8');
    
    			  $values[] = array(
              'name' => $name,
              'id'   => $option_id . $value['value_id'],
              'href' => $this->link($params),
            );
    			}
    
    			$selected_options[$option_id] = array(
            'name'   		=> $option['name'],
            'values' 		=> $values
          );
    		}
    
        return $selected_options;
      }
    
      public function decode() {
        if (isset($this->request->get['path'])) {
          $this->path = $this->request->get['path'];
        }
    
        if (!isset($this->request->get['_route_'])) {
          return;
        }
    
        $_route_ = $this->request->get['_route_'];
    
    		$keywords = explode('/', $_route_);
    
    		// remove any empty arrays from trailing
    		if (utf8_strlen(end($keywords)) == 0) {
    			array_pop($keywords);
    		}
    
        $ignored = array();
    
        $page_keywords = array();
    
        // Get category path
        if (!$this->path) {
          $path_info = $this->model_catalog_ocfilter->decodeCategory($keywords);
    
          if ($path_info && $path_info->path) {
          	$this->path = $path_info->path;
    
            $ignored = $path_info->keywords;
          }
        }
    
        if (!$this->path) {
        	return;
        }
    
        $parts = explode('_', $this->path);
    
        $category_id = (int)end($parts);
    
        // Ignore language
        $key = array_search($this->session->data['language'], $keywords);
    
        if (false !== $key) {
        	$ignored[] = $keywords[$key];
        }
    
        // Get SEO Page
        foreach ($keywords as $key => $keyword) {
          if (in_array($keyword, $ignored)) {
          	continue;
          }
    
          $page_info = $this->model_catalog_ocfilter->decodePage($category_id, $keyword);
    
          if ($page_info) {
          	$this->page_info = $page_info;
    
      			$keywords = explode('/', $this->page_info['params']);
    
      			// remove any empty arrays from trailing
      			if (utf8_strlen(end($keywords)) == 0) {
      				array_pop($keywords);
      			}
    
            break;
          }
        }
    
        $params = array();
    
        // Special filters
        foreach ($keywords as $key => $keyword) {
          if (in_array($keyword, $ignored)) {
          	continue;
          }
    
          if ($keyword == 'price') {
            unset($keywords[$key++]);
    
            $page_keywords[] = $keyword;
    
            if (isset($keywords[$key]) && isRange($keywords[$key])) {
          	  $params['p'] = array($keywords[$key]);
    
              $page_keywords[] = $keywords[$key];
    
              unset($keywords[$key]);
            }
          } else if ($keyword == 'sklad' && $this->config->get('ocfilter_stock_status_method') == 'quantity') {
            unset($keywords[$key++]);
    
            $page_keywords[] = $keyword;
    
            if (isset($keywords[$key]) && ($keywords[$key] == 'in' || $keywords[$key] == 'out')) {
              if (!isset($params['s'])) {
                $params['s'] = array();
              }
    
              $params['s'][$keywords[$key]] = $keywords[$key];
    
              $page_keywords[] = $keywords[$key];
    
              unset($keywords[$key]);
            }
          }
        }
    
        $current = '';
    
        foreach ($keywords as $key => $keyword) {
          if (in_array($keyword, $ignored)) {
          	continue;
          }
    
          $founded = 0;
    
          // Values
          if ($current == 's' && isID($keyword) && $this->config->get('ocfilter_stock_status_method') == 'stock_status_id') {
            $params['s'][$keyword] = $keyword;
    
            $founded = 1;
          } else if ($current) {
            $value_id = $this->model_catalog_ocfilter->decodeValue($keyword, $current);
    
            if ($value_id) {
              $params[$current][$value_id] = $value_id;
    
              $founded = 1;
            } else if (isRange($keyword)) { // If Slider
              $params[$current][$keyword] = $keyword;
    
              $founded = 2;
            }
          }
    
          if ($founded > 0) {
            $page_keywords[] = $keyword;
    
            if ($founded > 1) {
            	$current = '';
            }
    
          	unset($keywords[$key]);
    
            continue;
          }
    
          // Options
          if ($keyword == 'sklad' && $this->config->get('ocfilter_stock_status_method') == 'stock_status_id') {
          	$params['s'] = array();
    
            $current = 's';
    
            $page_keywords[] = $keyword;
    
            unset($keywords[$key]);
          } else if (!isRange($keyword)) {
            $option_id = $this->model_catalog_ocfilter->decodeOption($keyword, $category_id);
    
            if ($option_id) {
              $params[$option_id] = array();
    
              $current = $option_id;
    
              $page_keywords[] = $keyword;
    
              unset($keywords[$key]);
            }
          }
        }
    
        // Manufacturer
        foreach ($keywords as $key => $keyword) {
          $manufacturer_id = $this->model_catalog_ocfilter->decodeManufacturer($keyword);
    
          if ($manufacturer_id) {
            if (!isset($params['m'])) {
              $params['m'] = array();
            }
    
           	$params['m'][$manufacturer_id] = $manufacturer_id;
    
            $page_keywords[] = $keyword;
    
            unset($keywords[$key]);
          }
        }
    
        // Add category SEO keywords to _route_
        if ($this->page_info) {
        	$path = $this->model_catalog_ocfilter->getCategorySeoPathByCategoryId($this->page_info['category_id']);
    
          if ($path) {
            $parts = explode('/', $path);
    
            foreach (array_reverse($parts) as $part) {
              array_unshift($keywords, $part);
            }
          }
        }
    
        if (!$this->page_info && $page_keywords) {
        	$this->page_info = $this->model_catalog_ocfilter->getPage($category_id, implode('/', $page_keywords));
        }
    
        if ($keywords) {
        	$this->request->get['_route_'] = implode('/', $keywords);
        }
    
        if ($params) {
          $this->request->get['filter_ocfilter'] = encodeParamsToString($params, $this->config);
    
          if (isset($this->request->get['route'])) {
          	unset($this->request->get['route']);
          }
        }
      }
    
      public function rewrite($link) {
        $url_info = parse_url(str_replace('&amp;', '&', $link));
    
        if (!isset($url_info['query'])) {
        	return $link;
        }
    
    		$data = array();
    
    		parse_str($url_info['query'], $data);
    
        if (!isset($data['filter_ocfilter'])) {
          return $link;
        }
    
        $params = decodeParamsFromString($data['filter_ocfilter'], $this->config);
    
        unset($data['filter_ocfilter']);
    
        $path = '';
    
        foreach ($params as $option_id => $values) {
          if ($option_id == 'p') {
          	$path .= '/price';
          } else if ($option_id == 's') {
          	$path .= '/sklad';
          } else if ($option_id != 'm') {
            $query = $this->db->query("SELECT keyword FROM " . DB_PREFIX . "ocfilter_option WHERE option_id = '" . (int)$option_id . "'");
    
            if ($query->num_rows && $query->row['keyword']) {
            	$path .= '/' . $query->row['keyword'];
            } else {
            	$path .= '/' . $option_id;
            }
          }
    
          foreach ($values as $value_id) {
            $query = false;
    
            if ($option_id == 'm') {
              $query = $this->db->query("SELECT keyword FROM " . DB_PREFIX . "url_alias WHERE `query` = 'manufacturer_id=" . (int)$value_id . "'");
            } else if (isID($value_id)) {
              $query = $this->db->query("SELECT keyword FROM " . DB_PREFIX . "ocfilter_option_value WHERE value_id = '" . $this->db->escape((string)$value_id) . "'");
            }
    
            if ($query && $query->num_rows && $query->row['keyword']) {
            	$path .= '/' . $query->row['keyword'];
            } else {
            	$path .= '/' . $value_id;
            }
          }
        }
    
        if ($path) {
          $page_path = ltrim($path, '/');
    
          $page_info = $this->model_catalog_ocfilter->getPage($this->category_id, $page_path);
    
          if ($page_info && $page_info['keyword']) {
          	$path = '/' . $page_info['keyword'];
          }
        }
    
        $rewrite = $url_info['scheme'] . '://' . $url_info['host'];
    
        if (isset($url_info['port'])) {
        	$rewrite .= ':' . $url_info['port'];
        }
    
        if (isset($url_info['path'])) {
        	$rewrite .= str_replace('/index.php', '', $url_info['path']);
        } else {
          $rewrite .= '/index.php';
        }
    
        if ($path) {
        	$rewrite = rtrim($rewrite, '/') . $path;
    
          if ($this->config->has('config_seo_url_type') && $this->config->get('config_seo_url_type') == 'seo_pro') {
          	$rewrite .= '/';
          }
        }
    
    		$query = '';
    
    		if ($data) {
    			foreach ($data as $key => $value) {
    				$query .= '&' . rawurlencode((string)$key) . '=' . rawurlencode((is_array($value) ? http_build_query($value) : (string)$value));
    			}
    
    			if ($query) {
    				$query = '?' . str_replace('&', '&amp;', trim($query, '&'));
    			}
    		}
    
        $rewrite .= $query;
    
    		return $rewrite;
      }
    
      public function getPageInfo() {
        return $this->page_info;
      }
    
      public function getSelectedsFilterTitle() {
        $filter_title = '';
    
        $selecteds = $this->getSelectedOptions();
    
        foreach ($selecteds as $option_id => $option) {
          if ($filter_title) {
            $filter_title .= ', ';
          }
    
          if ($option_id == 'm') {
            $values_name  = '';
    
            foreach ($option['values'] as $value) {
              if ($values_name) {
              	$values_name .= ', ';
              }
    
          	  $values_name .= $value['name'];
            }
    
            if ($values_name) {
            	$filter_title .= $values_name;
            }
          } else if ($option_id == 'p') {
            $price = array_shift($option['values']);
    
            $filter_title .= $price['name'];
          } else if ($option_id == 's') {
            if ($this->config->get('ocfilter_stock_status_method') == 'quantity') {
              $stock_status = array_shift($option['values']);
    
              if ($stock_status['name'] == 'in') {
                $filter_title .= 'в наличии';
              } else if ($stock_status['name'] == 'out') {
                $filter_title .= 'нет в наличии';
              }
            } else {
              $values_name  = '';
    
              foreach ($option['values'] as $value) {
                if ($values_name) {
                	$values_name .= ', ';
                }
    
            	  $values_name .= $value['name'];
              }
    
              if ($values_name) {
              	$filter_title .= $values_name;
              }
            }
          } else {
            $values_name  = '';
    
            foreach ($option['values'] as $value) {
              if ($values_name) {
              	$values_name .= ', ';
              }
    
          	  $values_name .= $value['name'];
            }
    
            if ($values_name) {
            	$filter_title .= $option['name'] . ' ' . $values_name;
            }
          }
        }
    
        return $filter_title;
      }
    
      protected function link($filter_ocfilter = '') {
        $url = '';
    
        if ($this->path) {
          $url .= '&path=' . (string)$this->path;
        }
    
        if ($filter_ocfilter) {
          $url .= '&filter_ocfilter=' . (string)$filter_ocfilter;
        }
    
        if (isset($this->request->get['sort'])) {
          $url .= '&sort=' . (string)$this->request->get['sort'];
        }
    
        if (isset($this->request->get['order'])) {
          $url .= '&order=' . (string)$this->request->get['order'];
        }
    
        if (isset($this->request->get['limit'])) {
          $url .= '&limit=' . (int)$this->request->get['limit'];
        }
    
        return $this->url->link('product/category', $url);
      }
    
      public function callback() {
        if (!$this->path) {
        	return;
        }
    
        $this->load->language('extension/module/ocfilter');
    
        $json = array();
    
        if (isset($this->request->get['option_id'])) {
        	$option_id = $this->request->get['option_id'];
        } else {
        	$option_id = 0;
        }
    
        $filter_data = array(
    			'filter_category_id' => $this->category_id,
          'filter_ocfilter' => $this->params,
          'limit' => 1,
    		);
    
        if ($this->config->get('ocfilter_sub_category')) {
        	$filter_data['filter_sub_category'] = true;
        }
    
    		$total_products = $this->model_catalog_product->getTotalProducts($filter_data);
    
        $json['total'] = $total_products;
        $json['text_total'] = declOfNum($total_products, array(
                                          $this->language->get('button_show_total_1'),
                                          $this->language->get('button_show_total_2'),
                                          $this->language->get('button_show_total_3')
                                        ));
    
        $json['values'] = array();
        $json['sliders'] = array();
    
        if ($this->config->get('ocfilter_show_price') && $option_id != 'p') {
          $_filter_data = $filter_data;
    
          $_filter_data['filter_ocfilter'] = $this->cancelOptionParams('p');
    
          $product_prices = $this->model_catalog_ocfilter->getProductPrices($_filter_data);
    
          if ($product_prices) {
            $json['sliders']['p'] = array(
              'min' => $this->currency->format(floor($product_prices['min']), $this->session->data['currency'], '', false),
              'max' => $this->currency->format(ceil($product_prices['max']), $this->session->data['currency'], '', false),
            );
          }
        }
    
        $options = $this->getOCFilterOptions();
    
        foreach ($options as $option) {
          if ($option['type'] == 'slide' || $option['type'] == 'slide_dual') {
            if ($option['option_id'] != $option_id) {
              $json['sliders'][$option['option_id']] = $this->model_catalog_ocfilter->getSliderRange($option['option_id'], $filter_data);
            }
    
            continue;
          }
    
          if ($option['type'] == 'select' || $option['type'] == 'radio') {
            $params = $this->cancelOptionParams($option['option_id']);
    
            $json['values']['cancel-' . $option['option_id']] = array(
              't' => 1,
              'p' => $params,
    					's' => false
            );
    			}
    
          foreach ($option['values'] as $value) {
            $json['values'][$value['id']] = array(
              't' => $value['count'],
              'p' => $value['params'],
    					's' => isset($this->options_get[$option['option_id']][$value['value_id']])
            );
          }
        }
    
        $json['href'] = str_replace('&amp;', '&', $this->link($this->params));
    
    		$this->response->addHeader('Content-Type: application/json');
    		$this->response->setOutput(json_encode($json));
      }
    }
    ?>

     

     

  5. Подскажите, как в один контейнер вывести несколько определённых опций (если они есть)?
    Хочу получить такое:

    <div class="options">
      <div class="option-1">
         Опция ID1
      </div>
      <div class="option-2">
         Опция ID3
      </div>
    </div>

    Пробовал так

    <?php if ($options) { ?>
        <?php foreach ($options as $option) { ?>
        <?php if ($option['type'] == 'checkbox') { ?>
            <div class="options">
                <?php if ($option['option_id'] == '1' || $option['option_id'] == '2') { ?>
                    <div class="option-<?php echo $option['option_id'] ?>">
                        Опция ID<?php echo $option['option_id'] ?>
                    </div>
                <?php } ?>
            </div>
        <?php } ?>    
        <?php } ?>
    <?php } ?>

    Но получил результат

    <div class="options">
      <div class="option-1">
        Опция-1
      </div>
    </div>
    <div class="options">
      <div class="option-2">
        Опция-2
      </div>
    </div>

     

  6. Я насколько понял, цена там формируется в строке 885, но потом в контроллере переопределяется в oldprice, а в price идёт цена по акции. Как мне сделать, чтобы в price шла цена по акции + цена за опцию?

  7. В модуле для формирования YML есть проблема. Если товар идёт по акции, то при разбивке по опции исходная цена каждой опции идёт с одинаковой ценой (ценой акции). Мне надо, чтобы было цена по акции + значение цены опции (в теге price). <price> формируется не правильно, а <oldprice> правильно, без учёта акции.

    Контроллер:

    Спойлер
    <?php
    class ControllerExtensionFeedOcextFeedGeneratorYaMarket extends Controller {
    	private $shop = array();
    	private $currencies = array();
    	private $categories = array();
            private $product_categories = array();
    	private $offers = array();
            private $offers_fwrire = array('offers'=>array(),'cache_files'=>array());
            private $prices = array();
            private $parse_yml = array();
            private $delivery_option = array();
            private $general_setting = array();
            private $setting_yml = array();
            private $eol = "\n";
            private $debug = 0;
            private $memory_limit_on_fwrite = 0.7;///0.020625;
            private $l_data = array();
            private $HTTP_SERVER;
            private $count_skips = 0;
            private $count_offers = 0;
            private $total_memory = 0;
            private $log_errors = array();
            private $path_on_model = 'model_extension_feed_ocext_feed_generator_yamarket';
            private $path_oc_version = 'extension/feed';
            private $cfiles = array(
                'offers_cache'=>'multi_yml_offers_',
                'yml_parts_cache'=>'multi_yml_yml_parts_',
                'fb_parts_cache'=>'multi_yml_fb_parts_',
            );
    
    
    
    
            public function index() {
                
                    $error = array();                                                                                                                                                                                                                                                                                                                                                                   eval(base64_decode('JHRoaXMtPmNoZWNrbGljZW5zZSgpOw=='));//OCext.com: do not delete this line | не удаляйте эту строку
                
                    if (!$this->config->get('ocext_feed_generator_yamarket_status')) {
                        $error[] = 'Модуль выключен';
                    }
                    
                    $general_setting = $this->config->get('ocext_feed_generator_yamarket_general_setting');
                    
                    if(!isset($general_setting['user_key']) || !$general_setting['user_key']){
                        $error[] = 'Не указан лицензионный ключ. Отправьте запрос на welcome@ocext.com, в котором укажите сайт, где приобретался модуль, номер заказа и email аккаунта';
                    }
                    
                    if(!isset($general_setting['user_email']) || !$general_setting['user_email']){
                        $error[] = 'Не указан лицензионный email покупателя. В настройках модуля укажите email, который отправлялся при запросе лицензинного ключа';
                    }
                    
                    if(!file_exists($_SERVER["DOCUMENT_ROOT"].'/system/library/vendor/ocext/ocext_feed_generator_yamarket_license.php')){
                        $error[] = 'Неверно лицензионный ключ. Отправьте запрос на welcome@ocext.com, в котором укажите сайт, где приобретался модуль, номер заказа и email аккаунта';
                    }
                    
                    $token_get = '';
                    
                    $filter_data_group_id = '';
                    
                    if(isset($this->request->get['token'])){
                        
                        $token_get = $this->request->get['token'];
                        
                        if(isset($general_setting['filter_data'])){
                            
                            foreach ($general_setting['filter_data'] as $filter_data) {
                                
                                if(isset($this->setting_yml['path_token']) && isset($filter_data[$this->setting_yml['path_token']]) && $filter_data[$this->setting_yml['path_token']] ===$token_get){
                                    
                                    $general_setting['path_token_export'] = $token_get;
                                    if(isset($filter_data['fb_filename_export'])){
                                        $general_setting['fb_filename_export'] = $filter_data['fb_filename_export'];
                                    }
    				
    				$general_setting['promos_ids'] = array();
    				if(isset($filter_data['promos_ids'])){
                                        $general_setting['promos_ids'] = $filter_data['promos_ids'];
                                    }
                                    
                                    $general_setting['filename_export'] = $filter_data['filename_export'];
                                    $general_setting['yml_currencies'] = $filter_data['yml_currencies'];
                                    $filter_data_group_id = $filter_data['filter_data_group_id'];
                                    
                                    if(!isset($filter_data['content_language_id']) || !$filter_data['content_language_id']){
                                        
                                        $content_language_id = $this->config->get('config_language_id');
                                        
                                    }else{
                                        
                                        $content_language_id = $filter_data['content_language_id'];
                                        
                                    }
                                    
                                }
                                
                            }
                            
                        }
                        
                    }
                    if(!isset($general_setting['path_token_export']) || !$general_setting['path_token_export']){
                        $error[] = 'Не задан защитный параметр ссылки - token';
                    }
                    
                    if(isset($general_setting['path_token_export']) && $token_get!=$general_setting['path_token_export']){
                        $error[] = 'Неверный защитный параметр ссылки - token';
                    }
                    
                    
                    if(!isset($general_setting['yml_currencies']) || !$general_setting['yml_currencies']){
                        $error[] = 'Не указана валюта - обязательный параметр';
                    }else{
                        $this->setCurrencyAttributes($general_setting['yml_currencies']);
                    }
                    
                    if(!isset($general_setting['name']) || !$general_setting['name']){
                        $error[] = 'Не указано краткое название магазина';
                    }else{
                        $this->setShopAttributes('name', $general_setting['name']);
                    }
                    
                    if(!isset($general_setting['company']) || !$general_setting['company']){
                        $error[] = 'Не указано название компании';
                    }else{
                        $this->setShopAttributes('company', $general_setting['company']);
                    }
                    
                    if(!$this->config->get('config_secure')){
                        $this->setShopAttributes('url', HTTP_SERVER);
                        $this->HTTP_SERVER = HTTP_SERVER;
                    }else{
                        $this->setShopAttributes('url', HTTPS_SERVER);
                        $this->HTTP_SERVER = HTTPS_SERVER;
                    }
                    
                    if(isset($general_setting['platform']) && $general_setting['platform']){
                        $this->setShopAttributes('platform', $this->config->get('ayeogs_platform'));
                    }
                    
                    if(isset($general_setting['version']) && $general_setting['version']){
                        $this->setShopAttributes('version', $general_setting['version']);
                    }
                    
                    $this->general_setting = $general_setting;
    		
    		$this->load->model($this->path_oc_version.'/ocext_feed_generator_yamarket');
    		
    		if(isset($general_setting['promos_ids']) && $general_setting['promos_ids']){
    		    
    		    foreach ($general_setting['promos_ids'] as $key => $promos_id) {
    			
    			$promos = $this->{$this->path_on_model}->getPromoGift($promos_id);
    			
    			if($promos){
    			    
    			    if($promos['promos_type']=='gift-with-purchase'){
    				
    				foreach ($promos['promo-gifts'] as $promo_gifts_id => $promo_gifts) {
    				    
    				    if($promo_gifts['name']!=='' && $promo_gifts['picture']!==''){
    					
    					$this->general_setting['gifts'][ $promos_id.'000'.$promo_gifts_id ] = array(
    					    'name' => $promo_gifts['name'],
    					    'picture' => $promo_gifts['picture'],
    					    'gift_id' => $promos_id.'000'.$promo_gifts_id,
    					);
    					
    					$promos['gift_ids_selected'][$promos_id.'000'.$promo_gifts_id] = $promos_id.'000'.$promo_gifts_id;
    					
    				    }
    				    
    				}
    				
    			    }
    			    
    			    $this->general_setting['promos'][$promos_id] = $promos;
    			    
    			}
    			
    		    }
    		    
    		}
                    
                    $this->general_setting['filter_and_raplace_tags'] = $this->{$this->path_on_model}->getFilterData('ocext_feed_generator_yamarket_ym_filter_columns',$filter_data_group_id);
                    
                    if(!$error){
                        //создаем список категорий
                        $categories_end_offers = $this->getCategoriesAndOffers($filter_data_group_id,$content_language_id,$this->setting_yml);
                        if(!$categories_end_offers){
                            $error[] = 'Не найдены категории и/или товары. Невозможно создать файл без категорий и/или товаров';
                        }
                    }
                    
                    if(isset($categories_end_offers['add_settings'])){
                        
                        $this->general_setting['add_settings'] = $categories_end_offers['add_settings'];
                        
                    }
                    
                    
                    if($error){
                        $this->sendErrorXML($error);
                        return;
                    }
                    
                     $this->load->model($this->path_oc_version.'/ocext_feed_generator_yamarket');
                
                    $unlink_all_cache = array($this->cfiles['offers_cache'].$this->request->get['token'].'-');
                    
                    if(isset($this->request->get['fb'])){
                        
                        $unlink_all_cache[] = $this->cfiles['fb_parts_cache'].$this->request->get['token'].'-';
                        
                    }else{
                        
                        $unlink_all_cache[] = $this->cfiles['yml_parts_cache'].$this->request->get['token'].'-';
                        
                    }
                    
                    $this->{$this->path_on_model}->unlinkAllCache($unlink_all_cache);
                    
                    foreach ($categories_end_offers['categories'] as $category) {
                        $this->setCategoryAttrubite($category['name'], $category['category_id'], $category['parent_id'], $category);
                    }
                    
                    if( isset($this->general_setting['replace_cid_to_product_on_this'])){
                        
                        foreach($this->general_setting['replace_cid_to_product_on_this'] as $replace_cid_to_product_on_this){
                            
                            if(isset($this->categories[$replace_cid_to_product_on_this])){
                                
                                $parentId = $this->categories[$replace_cid_to_product_on_this]['parentId'];
                                
                                unset($this->categories[$replace_cid_to_product_on_this]['parentId']);
                                
                                if(isset($this->categories[$parentId])){
                                
                                    $parentId_this = $parentId;
                                    
                                    if(isset($this->categories[$parentId]['parentId'])){
                                        
                                        $parentId = $this->categories[$parentId]['parentId'];
                                    
                                        unset($this->categories[$parentId]);
                                        
                                    }
                                    
                                    unset($this->categories[$parentId_this]);
                                    
                                }
                                
                                if(isset($this->categories[$parentId])){
                                
                                    $parentId_this = $parentId;
                                    
                                    if(isset($this->categories[$parentId]['parentId'])){
                                        
                                        $parentId = $this->categories[$parentId]['parentId'];
                                    
                                        unset($this->categories[$parentId]);
                                        
                                    }
                                    
                                    unset($this->categories[$parentId_this]);
                                    
                                }
                                if(isset($this->categories[$parentId])){
                                
                                    $parentId_this = $parentId;
                                    
                                    if(isset($this->categories[$parentId]['parentId'])){
                                        
                                        $parentId = $this->categories[$parentId]['parentId'];
                                    
                                        unset($this->categories[$parentId]);
                                        
                                    }
                                    
                                    unset($this->categories[$parentId_this]);
                                    
                                }
                                if(isset($this->categories[$parentId])){
                                
                                    $parentId_this = $parentId;
                                    
                                    if(isset($this->categories[$parentId]['parentId'])){
                                        
                                        $parentId = $this->categories[$parentId]['parentId'];
                                    
                                        unset($this->categories[$parentId]);
                                        
                                    }
                                    
                                    unset($this->categories[$parentId_this]);
                                    
                                }
                                
                            }
                            
                        }
                        
                        
                        
                        foreach($this->categories as $category_id_on_delete => $category_on_delete){
                            
                            if(isset($category_on_delete['parentId']) && in_array($category_on_delete['parentId'], $this->general_setting['replace_cid_to_product_on_this'])){
                                
                                $category_id_on_delete_this = $category_on_delete['id'];
                                
                                unset($this->categories[$category_id_on_delete]);
                                
                                foreach($this->categories as $category_id_on_delete2 => $category_on_delete2){
    
                                    if(isset($category_on_delete2['parentId']) && $category_on_delete2['parentId']==$category_id_on_delete_this){
                                        
                                        $category_id_on_delete_this3 = $category_on_delete2['id'];
                                        
                                        unset($this->categories[$category_id_on_delete2]);
                                        
                                        foreach($this->categories as $category_id_on_delete3 => $category_on_delete3){
                                            
                                            if(isset($category_on_delete2['parentId']) && $category_on_delete2['parentId']==$category_id_on_delete_this3){
                                                
                                                unset($this->categories[$category_id_on_delete3]);
                                                
                                            }
                                            
                                        }
                                        
                                    }
    
                                }
                                
                            }
    
                        }
    
                    }
                    
                    if($this->debug){
                        
                        $this->log_errors[] = 'memory_limit '.ini_get('memory_limit').', max_execution_time '.ini_get('max_execution_time');
                        
                        foreach ($categories_end_offers['log_errors'] as $log_error) {
    
                            $this->log_errors[] = $log_error;
    
                        }
                        
                    }
                    
                    $cache_status = 0;
                    
                    if(isset($this->general_setting['yml_cache_enable']) && $this->general_setting['yml_cache_enable']){
                
                        $cache_status = 1;
    
                    }
                    
                    if($cache_status && isset($categories_end_offers['cache']) &&  $categories_end_offers['cache']){
                        
                        foreach ($categories_end_offers['cache'] as $cache_file_name) {
                            
                            $cache_offers = $this->getCache($cache_file_name);
                            
                            if($cache_offers){
                                
                                $this->delivery_option += $this->getShopDeliveryOptionAttrubite($cache_offers);
                                
                                foreach ($cache_offers as $i_cache_offer => $product) {
                            
                                    $this->getOfferAttrubite($product);
    
                                    unset($cache_offers[$i_cache_offer]);
    
                                }
                                
                                if($this->debug){
                                    
                                    $this->total_memory += memory_get_usage()/1024/1024;
                                    
                                    $this->log_errors[] = 'memory_get_usage for '.$cache_file_name.' '.round((memory_get_usage()/1024/1024),2).' M';
                                    
                                    $this->offers = array();
                                    
                                }
                                
                            }
                            
                            $cache_status++;
                            
                        }
                        
                        if($this->debug){
                            
                            $this->log_errors[] = "count_skips: ".  $this->count_skips.', count_offers: '.$this->count_offers;
                            
                            $this->log_errors[] = "total memory usage: ".  round($this->total_memory,2).' M';
                            
                        }
                        
                    }else{
                        
                        $this->delivery_option = $this->getShopDeliveryOptionAttrubite($categories_end_offers['offers']);
                        
                        foreach ($categories_end_offers['offers'] as $i_product => $product) {
                            
                            $this->getOfferAttrubite($product);
                            
                            unset($categories_end_offers['offers'][$i_product]);
                            
                        }
                        
                        $this->total_memory += memory_get_usage()/1024/1024;
                                    
                        $this->log_errors[] = "count_skips: ".  $this->count_skips.', count_offers: '.$this->count_offers;
                            
                        $this->log_errors[] = "total memory usage: ". round($this->total_memory,2).' M';
                        
                    }
                    
                    if($this->product_categories){
                        
                        foreach ($this->categories as $category_id => $category) {
                            
                            if(!isset($this->product_categories[$category_id])){
                                
                                unset($this->categories[$category_id]);
                                
                            }
                            
                        }
                        
                    }
    		
    		if(isset($this->general_setting['promos']) && $this->general_setting['promos']){
    		    
    		    $currency = '';
    		    
    		    if(isset($this->currencies[0]['id'])){
    			
    			$currency = $this->currencies[0]['id'];
    			
    		    }
    		    
    		    if(isset($this->general_setting['gifts'])){
    			
    			$gifts_result = '<gifts>'.$this->eol;
    			
    			foreach ($this->general_setting['gifts'] as $gifts) {
    			    
    			    $gifts_result .= '<gift id="'.$gifts['gift_id'].'">';
    
    			    $gifts_result .= '<name>'.$gifts['name'].'</name>';
    			    
    			    $gifts_result .= '<picture>'.$gifts['picture'].'</picture>';
    			    
    			    $gifts_result .= '</gift>';
    			    
    			}
    			
    			$gifts_result .= '</gifts>'.$this->eol;
    			
    			$this->general_setting['gifts_result'] = $gifts_result;
    			
    		    }
    		    
    		    foreach ($this->general_setting['promos'] as $promos_id => $promo) {
    			
    			$promos_result = '';
    			
    			if($promo['promos_type']=='promo-code'){
    			    
    			    $general_values = array(
    				'start-date' => $promo['start-date'],
    				'end-date' => $promo['end-date'],
    				'description' => '<![CDATA['. html_entity_decode($promo['description']).']]>',
    				'url' => $this->prepareField($promo['url']),
    				'promo-code' => $promo['promo-code']
    			    );
    			    
    			    if($promo['discount_percent']!==''){
    				
    				$general_values['discount'] = array(
    				    'attributes' => array('unit'=>'percent'),
    				    'value' => (int)$promo['discount_percent'],
    				);
    				
    			    }elseif($promo['discount_currency']!==''){
    				
    				$general_values['discount'] = array(
    				    'attributes' => array('unit'=>'currency','currency'=>$currency),
    				    'value' => (int)$promo['discount_currency'],
    				);
    				
    			    }
    			    
    			    $purchase = array();
    			    
    			    if(isset($promo['product_ids_selected'])){
    				
    				foreach ($promo['product_ids_selected'] as $offer_id) {
    				    
    				    $purchase[]['product'] = array(
    					'attributes' => array('offer-id'=>$offer_id),
    					'value' => '',
    				    );
    				    
    				}
    				
    			    }
    			    
    			    if(isset($promo['category_ids_selected'])){
    				
    				foreach ($promo['category_ids_selected'] as $categoryId) {
    				    
    				    if(isset($this->general_setting['mapping_market_place_categories_replace']) && isset($this->general_setting['mapping_market_place_categories_replace'][$categoryId])){
    
    					$categoryId = $this->general_setting['mapping_market_place_categories_replace'][$categoryId];
    
    				    }
    				    
    				    $purchase[]['product'] = array(
    					'attributes' => array('category-id'=>$categoryId),
    					'value' => '',
    				    );
    				    
    				}
    				
    			    }
    			    
    			    $general_values['purchase'] = $purchase;
    			    
    			    $promos_result = '<promo id="'.$promos_id.'" type="promo code">'.$this->eol;
    			    
    			    foreach ($general_values as $tag_name => $value) {
    				
    				if($tag_name=='purchase'){
    				    
    				    $promos_result .= '<purchase>'.$this->eol;
    				    
    				    foreach ($value as $value2) {
    					
    					foreach ($value2 as $tag_name2 => $value3) {
    					
    					    $promos_result .= '<'.$tag_name2.' ';
    					
    					    foreach ($value3['attributes'] as $attr_name => $attr_value) {
    						$promos_result .= $attr_name .'="'.$attr_value.'" ';
    					    }
    
    					    $promos_result .= ($value3['value']!=='' ? '>'.$value3['value'].'</'.$tag_name2.'>' : '/>').$this->eol;
    					    
    					}
    					
    				    }
    				    
    				    $promos_result .= '</purchase>'.$this->eol;
    				    
    				}elseif($tag_name=='discount'){
    				    
    				    $promos_result .= '<'.$tag_name.' ';
    				    
    				    foreach ($value['attributes'] as $attr_name => $attr_value) {
    					
    					$promos_result .= $attr_name .'="'.$attr_value.'" ';
    					
    				    }
    				    
    				    $promos_result .= ($value['value']!=='' ? '>'.$value['value'].'</'.$tag_name.'>' : '/>').$this->eol;
    				    
    				}else{
    				    
    				    $promos_result .= '<'.$tag_name.'>'. ($value!=='' ? $value.'</'.$tag_name.'>' : '/>').$this->eol;
    				    
    				}
    				
    			    }
    			    
    			    $promos_result .= '</promo>'.$this->eol;
    			    
    			    $this->general_setting['promos_result'][$promos_id]  =  $promos_result;
    			    
    			}
    			elseif($promo['promos_type']=='flash-discount'){
    			    
    			    $general_values = array(
    				'start-date' => $promo['start-date'],
    				'end-date' => $promo['end-date'],
    				'description' => '<![CDATA['. html_entity_decode($promo['description']).']]>',
    				'url' => $this->prepareField($promo['url'])
    			    );
    			    
    			    $purchase = array();
    			    
    			    if(isset($promo['product_ids_selected'])){
    				
    				foreach ($promo['product_ids_selected'] as $offer_id) {
    				    
    				    $purchase[]['product'] = array(
    					'attributes' => array('offer-id'=>$offer_id),
    					'value' => '<discount-price currency="'.$currency.'">'.$promo['discount-price'].'</discount-price>',
    				    );
    				    
    				}
    				
    			    }
    			    
    			    $general_values['purchase'] = $purchase;
    			    
    			    $promos_result = '<promo id="'.$promos_id.'" type="flash discount">'.$this->eol;
    			    
    			    foreach ($general_values as $tag_name => $value) {
    				
    				if($tag_name=='purchase'){
    				    
    				    $promos_result .= '<purchase>'.$this->eol;
    				    
    				    foreach ($value as $value2) {
    					
    					foreach ($value2 as $tag_name2 => $value3) {
    					
    					    $promos_result .= '<'.$tag_name2.' ';
    					
    					    foreach ($value3['attributes'] as $attr_name => $attr_value) {
    						$promos_result .= $attr_name .'="'.$attr_value.'" ';
    					    }
    
    					    $promos_result .= ($value3['value']!=='' ? '>'.$value3['value'].'</'.$tag_name2.'>' : '/>').$this->eol;
    					    
    					}
    					
    				    }
    				    
    				    $promos_result .= '</purchase>'.$this->eol;
    				    
    				}elseif($tag_name=='discount'){
    				    
    				    $promos_result .= '<'.$tag_name.' ';
    				    
    				    foreach ($value['attributes'] as $attr_name => $attr_value) {
    					
    					$promos_result .= $attr_name .'="'.$attr_value.'" ';
    					
    				    }
    				    
    				    $promos_result .= ($value['value']!=='' ? '>'.$value['value'].'</'.$tag_name.'>' : '/>').$this->eol;
    				    
    				}else{
    				    
    				    $promos_result .= '<'.$tag_name.'>'. ($value!=='' ? $value.'</'.$tag_name.'>' : '/>').$this->eol;
    				    
    				}
    				
    			    }
    			    
    			    $promos_result .= '</promo>'.$this->eol;
    			    
    			    $this->general_setting['promos_result'][$promos_id]  =  $promos_result;
    			    
    			}
    			elseif($promo['promos_type']=='n-plus-m'){
    			    
    			    $general_values = array(
    				'start-date' => $promo['start-date'],
    				'end-date' => $promo['end-date'],
    				'description' => '<![CDATA['. html_entity_decode($promo['description']).']]>',
    				'url' => $this->prepareField($promo['url'])
    			    );
    			    
    			    $purchase = array();
    			    
    			    $purchase[]['required-quantity'] = array(
    				'attributes' => array(),
    				'value' => $promo['required-quantity'],
    			    );
    			    
    			    $purchase[]['free-quantity'] = array(
    				'attributes' => array(),
    				'value' => $promo['free-quantity'],
    			    );
    			    
    			    if(isset($promo['product_ids_selected'])){
    				
    				foreach ($promo['product_ids_selected'] as $offer_id) {
    				    
    				    $purchase[]['product'] = array(
    					'attributes' => array('offer-id'=>$offer_id),
    					'value' => '',
    				    );
    				    
    				}
    				
    			    }
    			    
    			    if(isset($promo['category_ids_selected'])){
    				
    				foreach ($promo['category_ids_selected'] as $categoryId) {
    				    
    				    if(isset($this->general_setting['mapping_market_place_categories_replace']) && isset($this->general_setting['mapping_market_place_categories_replace'][$categoryId])){
    
    					$categoryId = $this->general_setting['mapping_market_place_categories_replace'][$categoryId];
    
    				    }
    				    
    				    $purchase[]['product'] = array(
    					'attributes' => array('category-id'=>$categoryId),
    					'value' => '',
    				    );
    				    
    				}
    				
    			    }
    			    
    			    $general_values['purchase'] = $purchase;
    			    
    			    $promos_result = '<promo id="'.$promos_id.'" type="n plus m">'.$this->eol;
    			    
    			    foreach ($general_values as $tag_name => $value) {
    				
    				if($tag_name=='purchase'){
    				    
    				    $promos_result .= '<purchase>'.$this->eol;
    				    
    				    foreach ($value as $value2) {
    					
    					foreach ($value2 as $tag_name2 => $value3) {
    					
    					    $promos_result .= '<'.$tag_name2.' ';
    					
    					    foreach ($value3['attributes'] as $attr_name => $attr_value) {
    						$promos_result .= $attr_name .'="'.$attr_value.'" ';
    					    }
    
    					    $promos_result .= ($value3['value']!=='' ? '>'.$value3['value'].'</'.$tag_name2.'>' : '/>').$this->eol;
    					    
    					}
    					
    				    }
    				    
    				    $promos_result .= '</purchase>'.$this->eol;
    				    
    				}elseif($tag_name=='discount'){
    				    
    				    $promos_result .= '<'.$tag_name.' ';
    				    
    				    foreach ($value['attributes'] as $attr_name => $attr_value) {
    					
    					$promos_result .= $attr_name .'="'.$attr_value.'" ';
    					
    				    }
    				    
    				    $promos_result .= ($value['value']!=='' ? '>'.$value['value'].'</'.$tag_name.'>' : '/>').$this->eol;
    				    
    				}else{
    				    
    				    $promos_result .= '<'.$tag_name.'>'. ($value!=='' ? $value.'</'.$tag_name.'>' : '/>').$this->eol;
    				    
    				}
    				
    			    }
    			    
    			    $promos_result .= '</promo>'.$this->eol;
    			    
    			    $this->general_setting['promos_result'][$promos_id]  =  $promos_result;
    			    
    			}
    			elseif($promo['promos_type']=='gift-with-purchase'){
    			    
    			    $general_values = array(
    				'start-date' => $promo['start-date'],
    				'end-date' => $promo['end-date'],
    				'description' => '<![CDATA['. html_entity_decode($promo['description']).']]>',
    				'url' => $this->prepareField($promo['url'])
    			    );
    			    //product_as_gift_ids_selected 
    			    $purchase = array();
    			    
    			    $purchase[]['required-quantity'] = array(
    				'attributes' => array(),
    				'value' => $promo['required-quantity-present'],
    			    );
    			    
    			    if(isset($promo['product_ids_selected'])){
    				
    				foreach ($promo['product_ids_selected'] as $offer_id) {
    				    
    				    $purchase[]['product'] = array(
    					'attributes' => array('offer-id'=>$offer_id),
    				    );
    				    
    				}
    				
    			    }
    			    
    			    $promo_gifts = array();
    			    
    			    if(isset($promo['gift_ids_selected'])){
    				
    				foreach ($promo['gift_ids_selected'] as $gift_id) {
    				    
    				    $promo_gifts[]['promo-gift'] = array(
    					'attributes' => array('gift-id'=>$gift_id),
    				    );
    				    
    				}
    				
    			    }
    			    
    			    if(isset($promo['product_as_gift_ids_selected'])){
    				
    				foreach ($promo['product_as_gift_ids_selected'] as $offer_id) {
    				    
    				    $promo_gifts[]['promo-gift'] = array(
    					'attributes' => array('offer-id'=>$offer_id),
    				    );
    				    
    				}
    				
    			    }
    			    
    			    $general_values['purchase'] = $purchase;
    			    
    			    $general_values['promo-gifts'] = $promo_gifts;
    			    
    			    $promos_result = '<promo id="'.$promos_id.'" type="gift with purchase">'.$this->eol;
    			    
    			    foreach ($general_values as $tag_name => $value) {
    				
    				if($tag_name=='purchase' || $tag_name=='promo-gifts'){
    				    
    				    $promos_result .= '<'.$tag_name.'>'.$this->eol;
    				    
    				    foreach ($value as $value2) {
    					
    					foreach ($value2 as $tag_name2 => $value3) {
    					
    					    $promos_result .= '<'.$tag_name2.' ';
    					
    					    foreach ($value3['attributes'] as $attr_name => $attr_value) {
    						$promos_result .= $attr_name .'="'.$attr_value.'" ';
    					    }
    
    					    $promos_result .= ( (isset($value3['value']) && $value3['value']!=='') ? '>'.$value3['value'].'</'.$tag_name2.'>' : '/>').$this->eol;
    					    
    					}
    					
    				    }
    				    
    				    $promos_result .= '</'.$tag_name.'>'.$this->eol;
    				    
    				}else{
    				    
    				    $promos_result .= '<'.$tag_name.'>'. ($value!=='' ? $value.'</'.$tag_name.'>' : '/>').$this->eol;
    				    
    				}
    				
    			    }
    			    
    			    $promos_result .= '</promo>'.$this->eol;
    			    
    			    $this->general_setting['promos_result'][$promos_id]  =  $promos_result;
    			    
    			}
    			
    		    }
    		    
    		}
                    
                    if(!$this->debug && isset($this->setting_yml['status_validation']) && isset($this->parse_yml[$this->setting_yml['status_validation']]) && $this->parse_yml[$this->setting_yml['status_validation']]){
                        $yml = $this->getYml();
                        if($yml){
                            $this->response->addHeader('Content-Type: application/xml');
                            $this->response->setOutput($yml);
                        }
                        
                        $unlink_all_cache = array($this->cfiles['offers_cache'].$this->request->get['token'].'-');
                    
                        if(isset($this->request->get['fb'])){
    
                            $unlink_all_cache[] = $this->cfiles['fb_parts_cache'].$this->request->get['token'].'-';
    
                        }else{
    
                            $unlink_all_cache[] = $this->cfiles['yml_parts_cache'].$this->request->get['token'].'-';
    
                        }
    
                        $this->{$this->path_on_model}->unlinkAllCache($unlink_all_cache);
                        
                    }else{
                        
                        $this->sendErrorXML($this->log_errors);
    		    
                        return;
                        
                    }
    	}
            
            public function setLogErrors($message) {
                
                if($this->debug){
                    
                    $this->log_errors[] = $message;
                    
                }
                
            }
            
            public function getCache($filename) {
                
                $cache_offers = array();
                
                if(file_exists(DIR_CACHE.$filename)){
                    
                    $cache_offers = json_decode(file_get_contents(DIR_CACHE.$filename),TRUE);
                    
                    if( (!$cache_offers or is_null($cache_offers)) && $this->debug ){
                        
                        $this->log_errors[] = "parsing cache error to file ".  DIR_CACHE.$filename;
                        
                    }
                    
                    unlink(DIR_CACHE.$filename);
                    
                }else{
                    
                    if($this->debug){
                            
                        $this->log_errors[] = "no cache file ".  DIR_CACHE.$filename;
    
                    }
                    
                }
                
                return $cache_offers;
                
            }
            
            public function getShopDeliveryOptionAttrubite($products) {
                
                $data = array();
                if($products){
                    foreach ($products as $product) {
    		    
    		    $product['setting'] = array();
    		    
    		    if(isset($product['settings_id']) && isset($this->general_setting['settings']) && isset($this->general_setting['settings'][$product['settings_id']]) ) {
    			
    			$product['setting'] = $this->general_setting['settings'][$product['settings_id']];
    			
    		    }
    		    
                        if($product['setting'] && $product['setting']['delivery-options']['status']){
                            
                            $weight = '';
                            $stock_status_id = '';
                            $price = '';
                            
                            
                            if(isset($product['weight']) && $product['weight']>0){
                                $weight = (float)$weight;
                            }
                            if(isset($product['weight']) && $product['weight']>0){
                                $stock_status_id = $product['stock_status_id'];
                            }
                            if(isset($product['price'])){
                                $price = $product['price'];
                            }
                            
                            $delivery_options = $this->getDeliveryOption($product['setting'],$price,$weight,$stock_status_id);
                            
                            if($delivery_options){
                                $data['delivery-options'] = $delivery_options;
                            }
                        }
                    }
                }
                return $data;
                
            }
            
            public function setProductCategories($category_id) {
                
                if(isset($this->categories[$category_id])){
                    $this->product_categories[$category_id] = $category_id;
                }
                
                if(isset($this->categories[$category_id]['parentId'])){
                    
                    $this->setProductCategories($this->categories[$category_id]['parentId']);
                    
                }
                
            }
            
            public function getOfferAttrubite($product) {
                $data = array();
                $template_setting = array();
                $skip_this_offer = FALSE;
    	    
    	    $product['setting'] = array();
    		    
    	    if(isset($product['settings_id']) && isset($this->general_setting['settings']) && isset($this->general_setting['settings'][$product['settings_id']]) ) {
    
    		$product['setting'] = $this->general_setting['settings'][$product['settings_id']];
    
    	    }
                
                if($product['setting']){
                    $template_setting = $product['setting'];
                }
                
                $data['id'] = $product['product_id'];
                
                if($product['product_id_by_option_id']){
                    
                    $data['id'] = $product['product_id_by_option_id'];
                    
                }
                
                if(isset($template_setting['custom_offer_id']['field']['status']) && $template_setting['custom_offer_id']['field']['status']){
                    
                    $custom_offer_id = $this->getNameAttributeForType($product,$template_setting,$template_setting['custom_offer_id']['field']['status'],'custom_offer_id');
                    
                    $data['id'] = str_replace($data['id'], $custom_offer_id, $data['id']);
                    
                    if($product['product_id_by_option_id'] && $template_setting['custom_offer_id']['field']['status']=='product_id'){
    
                        $data['id'] = $product['product_id_by_option_id'];
    
                    }
                    
                }
                
                if(isset($template_setting['product_id_from']) && $template_setting['product_id_from']!='' && $product['product_id']<$template_setting['product_id_from']){
                    $skip_this_offer = TRUE;
                }
                
                if(isset($template_setting['product_id_to']) && $template_setting['product_id_to']!='' &&  $product['product_id']>$template_setting['product_id_to']){
                    $skip_this_offer = TRUE;
                }
                
                if(isset($template_setting['disable_this_product']) && $template_setting['disable_this_product']){
                    $skip_this_offer = TRUE;
                }
                
                if(isset($template_setting['url_whis_path']) && $template_setting['url_whis_path']){
                    $data['url'] = $this->url->link('product/product', 'path='.$this->getPathWhisCategories($product['category_id']).'&product_id='.$product['product_id']);
                }else{
                    $data['url'] = $this->url->link('product/product', 'product_id='.$product['product_id']);
                }
                
                $data['url'] .= $product['option_url_param'];
                
                //цены
                
                $product['price'] = $this->getPrice($product['price'],$product,$template_setting);
                
                if($product['special_price']>0){
                    $product['special_price'] = $this->getPrice($product['special_price'],$product,$template_setting);
                }
                if($product['discount_special_price']>0){
                    $product['discount_special_price'] = $this->getPrice($product['discount_special_price'],$product,$template_setting);
                }
                
                if(isset($template_setting['oldprice']) && $template_setting['oldprice'] && ($product['special_price'] || $product['discount_special_price']) > 0){
                    if($product['special_price']>0 && $product['special_price'] < $product['price'] ){
                        
                        $data['oldprice'] = $product['price'];
                        $data['price'] = $product['special_price'];
                        $product['oldprice'] = $product['price'];
                        $product['price'] = $product['special_price'];
                        
                    }elseif( $product['discount_special_price']>0 && $product['discount_special_price'] < $product['price']  ){
                        
                        $data['oldprice'] = $product['price'];
                        $data['price'] = $product['discount_special_price'];
                        $product['oldprice'] = $product['price'];
                        $product['price'] = $product['discount_special_price'];
                        
                    }else{
                        
                        $data['price'] = $product['price'];
                        
                    }
                }
                
                if(isset($template_setting['price_currencies_to'])){
                    $decimal_place = (int)$this->currency->getDecimalPlace($template_setting['price_currencies_to']);
                }else{
                    $decimal_place = (int)$this->currency->getDecimalPlace(0);
                }
                
                $data['price'] = round($product['price'],$decimal_place);
                
                if(isset($data['oldprice']) && $data['oldprice'] && isset($product['oldprice']) && $product['oldprice']){
                    
                    $data['oldprice'] = round($product['oldprice'],$decimal_place);
                    
                }
                        
                if(isset($this->parse_yml['zero']) && isset($template_setting[$this->parse_yml['zero']]) && !$template_setting[$this->parse_yml['zero']] && $data['price']==0){
                    $skip_this_offer = TRUE;
                }
                
                if(isset($template_setting['price_from']) && $template_setting['price_from']!='' && $template_setting['price_from']>$data['price']){
                    $skip_this_offer = TRUE;
                }
                
                if(isset($template_setting['price_to']) && $template_setting['price_to']!='' && $data['price'] > $template_setting['price_to']){
                    $skip_this_offer = TRUE;
                }
                
                
                if((!$data['price'] || $data['price']==0.0) && (!isset($template_setting['zero_price']) || !$template_setting['zero_price']) ){
                    $skip_this_offer = TRUE;
                }else{
                    //используется для составных заголовков
                    $this->prices[$product['product_id']] = $data['price'];
                }
                //валюта
                $data['currencyId'] = $this->currencies[0]['id'];
                
                
                if(isset($product['market_category']) && $product['market_category']){
                    //категория market_category
                    $data['market_category'] = $product['market_category'];
                }
                
                //изображения
                $data['picture'] = $this->getPictureAttributes($product,$template_setting);
                
                //если без картинок не выгружать, и картинок нет, то это предложение не делаем
                if(isset($template_setting['no_pictures']) && $template_setting['no_pictures'] && !$data['picture']){
                    $skip_this_offer = TRUE;
                }
                
                if(isset($template_setting['store']) && $template_setting['store']){
                    $data['store'] = 'true';
                }else{
                    $data['store'] = 'false';
                }
                //
                if(isset($template_setting['pickup']) && $template_setting['pickup']){
                    $data['pickup'] = 'true';
                }else{
                    $data['pickup'] = 'false';
                }
                
                //
                if(isset($template_setting['delivery']) && $template_setting['delivery']){
                    $data['delivery'] = 'true';
                }else{
                    $data['delivery'] = 'false';
                }
                
                if(!isset($template_setting['delivery'])){
                    
                    $data['delivery'] = 'true';
                    
                }
                
                //delivery-options
                if(isset($template_setting['delivery-options']['status']) && $template_setting['delivery-options']['status']){
                    
                    $w = '';
                    if(isset($product['weight']) && $product['weight']>0){
                        $w = (float)$w;
                    }
                    $ssi = '';
                    if(isset($product['stock_status_id']) && $product['stock_status_id']>0){
                        $ssi = $product['stock_status_id'];
                    }
                    $p = '';
                    if(isset($product['price'])){
                        $p = $product['price'];
                    }
                    
                    $delivery_options = $this->getDeliveryOption($template_setting,$p,$w,$ssi);
                    if($delivery_options){
                        $data['delivery-options'] = $delivery_options;
                    }
                }
                
                if(isset($product['delivery_option_by_manufacturer']) && $product['delivery_option_by_manufacturer']){
                    
                    if(isset($data['delivery-options'])){
                        
                        $data['delivery-options'][] = $product['delivery_option_by_manufacturer'];
                        
                    }else{
                        
                        $data['delivery-options'] = array($product['delivery_option_by_manufacturer']);
                        
                    }
                    
                }
                
                if((isset($template_setting['offer_name']['field']['status'])  && $template_setting['offer_name']['field']['status']) ){
                    
                    //название товара
                    $data['name'] = $this->getNameAttribute($product,$template_setting,'offer_name');
                    
                }elseif(!isset($template_setting['offer_name']['field']['status'])){
                    
                    $data['name'] = $this->prepareField($product['name']);
                    
                }
                      
                if(isset($template_setting['divide_on_option_add_to_name']) && $template_setting['divide_on_option_add_to_name'] && isset($data['name']) && isset($product['option_add_model_name']) && $product['option_add_model_name']){
                    $data['name'] .= ' '.$this->prepareField($product['option_add_model_name']);
                }
                
                if(isset($template_setting['text_capitalize']) && $template_setting['text_capitalize'] && isset($data['name'])){
                    $data['name'] = mb_convert_case($data['name'], MB_CASE_TITLE, "UTF-8");
                }
                
                //вендор
                if(isset($template_setting['vendor']['field']['status'])){
                    $data['vendor'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['vendor']['field']['status'],'vendor');
                }
                
                if(isset($template_setting['vendorCode']['field']['status'])){
                    $data['vendorCode'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['vendorCode']['field']['status'],'vendorCode');
                }
                
                //если вендор модель, выход без вендора
                if(isset($template_setting['vendor.model']) && $template_setting['vendor.model'] && ( !isset($data['vendor']) || !$data['vendor'] )){
                    //return;
                    $data['type'] = 'vendor.model';
                }elseif(isset ($template_setting['vendor.model']) && $template_setting['vendor.model']){
                    $data['type'] = 'vendor.model';
                }
                
                //описание
                if(isset($template_setting['offer_description']['field']) && $template_setting['offer_description']['field']){
                    $data['description'] = $this->getDescriptionAttribute($product, $template_setting);
                }
                
                //manufacturer_warranty
                if(isset($template_setting['manufacturer_warranty']) && $template_setting['manufacturer_warranty']){
                    $data['manufacturer_warranty'] = 'true';
                }
                
                //country_of_origin
                if(isset($template_setting['country_of_origin'])){
                    $data['country_of_origin'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['country_of_origin']['field']['status'],'country_of_origin');
                }
                
                //barcode
                if(isset($template_setting['barcode'])){
                    $data['barcode'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['barcode']['field']['status'],'barcode');
                }
                
                //expiry
                if(isset($template_setting['expiry'])){
                    $data['expiry'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['expiry']['field']['status'],'expiry');
                }
                
                //weight
                if(isset($template_setting['weight'])){
                    $data['weight'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['weight']['field']['status'],'weight');
                }
                
                //weight
                if(isset($template_setting['dimensions'])){
                    $data['dimensions'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['dimensions']['field']['status'],'dimensions');
                }
                
                //age
                if(isset($template_setting['age']['field']['status']) && $template_setting['age']['field']['status']){
                    if($template_setting['age']['unit']){
                        $data['age']['value'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['age']['field']['status'],'age');
                        $data['age']['unit'] = $template_setting['age']['unit'];
                    }
                }
                
                //typePrefix
                if(isset($template_setting['typePrefix']) && $template_setting['typePrefix']){
                    $data['typePrefix'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['typePrefix']['field']['status'],'typePrefix');
                }
                
                //cpa
                if(isset($template_setting['cpa']) && $template_setting['cpa']){
                    $data['cpa'] = '1';
                }
                
                //rec
                if(isset($template_setting['rec']) && $template_setting['rec'] && $product['rec']){
                    $data['rec'] = implode(',', $product['rec']);
                }
                
                //adult
                if(isset($template_setting['adult']) && $template_setting['adult']){
                    $data['adult'] = 'true';
                }
                
                //available
                $stock_status_id = $product['stock_status_id'];
                $quantity = (int)$product['quantity'];
                $minimum = (int)$product['minimum'];
                $data['available'] = 'false';
                
                
                if(isset($template_setting['available_by_quantity']) && $template_setting['available_by_quantity']){
                    
                    if(!$quantity || $quantity<$minimum){
                        $data['available'] = 'false';
                    }elseif($quantity || $quantity>=$minimum){
                        $data['available'] = 'true';
                    }
                    
                }else{
                    
                    if(isset ($template_setting['available_true']) && $template_setting['available_true']==$stock_status_id){
                        $data['available'] = 'true';
                    }elseif(isset ($template_setting['available_false'][$stock_status_id])){
                        $data['available'] = 'false';
                    }
                    
                }
                
                
                
                
                
                //fee в селекторе
                if(isset($template_setting['fee_select']['field']['status']) && $template_setting['fee_select']['field']['status']){
                    $data['fee'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['fee_select']['field']['status'],'fee_select');
                }elseif(isset($template_setting['fee_input']) && $template_setting['fee_input']){
                    $data['fee'] = $this->prepareField($template_setting['fee_input']);
                }
                
                if(!isset($template_setting['model']['field']['status']) || (isset($template_setting['model']['field']['status'])  && $template_setting['model']['field']['status']) ){
                    
                    //модель
                    $data['model'] = $this->getNameAttribute($product,$template_setting,'model');
                    
                }
                
                if(isset($template_setting['divide_on_option_add_to_model']) && $template_setting['divide_on_option_add_to_model'] && isset($data['model']) && isset($product['option_add_model_name']) && $product['option_add_model_name']){
                    $data['model'] .= ' '.$this->prepareField($product['option_add_model_name']);
                }
                
                if(isset($template_setting['text_capitalize']) && $template_setting['text_capitalize'] && isset($data['model'])){
                    $data['model'] = mb_convert_case($data['model'], MB_CASE_TITLE, "UTF-8");
                }
                
                if(isset($template_setting['dispublic_quantity']) && !$template_setting['dispublic_quantity'] && $data['available']=='false' ){
                    $skip_this_offer = TRUE;
                }
                
                //sales_notes в селекторе
                if(isset($template_setting['sales_notes_select']['field']['status']) && $template_setting['sales_notes_select']['field']['status']){
                    $data['sales_notes'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['sales_notes_select']['field']['status'],'sales_notes_select');
                }elseif(isset($template_setting['sales_notes']) && $template_setting['sales_notes']){
                    $data['sales_notes'] = $this->prepareField($template_setting['sales_notes']);
                }
                
                if(isset($template_setting['sales_notes_select_on_available_true']['field']['status']) && $template_setting['sales_notes_select_on_available_true']['field']['status'] && $data['available'] == 'true'){
                    $data['sales_notes'] = $this->getNameAttributeForType($product,$template_setting,$template_setting['sales_notes_select_on_available_true']['field']['status'],'sales_notes_select_on_available_true');
                }elseif(isset($template_setting['sales_notes_on_available_true']) && $template_setting['sales_notes_on_available_true'] && $data['available'] == 'true'){
                    $data['sales_notes'] = $this->prepareField($template_setting['sales_notes_on_available_true']);
                }
                
                if(isset($template_setting['sales_notes_on_available_false']) && $template_setting['sales_notes_on_available_false'] && $data['available'] == 'false'){
                    $data['sales_notes'] = $this->prepareField($template_setting['sales_notes']);
                }elseif(isset($template_setting['sales_notes_on_available_false']) && $template_setting['sales_notes_on_available_false'] && $data['available'] == 'true'){
                    $data['sales_notes'] = '';
                }
                
                if(isset($template_setting['sales_note_by_rule'])){
                    
                    for($sni=0;$sni<count($template_setting['sales_note_by_rule']);$sni++){
                        
                        $sales_note_by_rule_status = $this->{$this->path_on_model}->getStatusByWhere($template_setting['sales_note_by_rule'][$sni],$product);
                        if($sales_note_by_rule_status){
                            $data['sales_notes'] = $this->prepareField($template_setting['sales_note_by_rule'][$sni]['sales_note']);
                        }
                        
                    }
                    
                }
                //param
                $param_atributes = array();
                if($product['ym_attributes']){
                    $param_atributes = $this->getParamAttribute($product['ym_attributes'],$template_setting);
                }
                
                $param_options = array();
                if($product['ym_options']){
                    $param_options = $this->getParamOption($product['ym_options']);
                    
                    if($param_options){
                        
                        $param_options_temp = $param_options;
                        
                        $param_options = array();
                        
                        foreach ($param_options_temp as $param_option_value) {
                            $param_options[$param_option_value['name'].'_'.$param_option_value['value']] = $param_option_value;
                        }
                        
                    }
                }
                
                if($param_options || $param_atributes){
                    $data['param'] = array_merge($param_options,$param_atributes);
                }
                
                if(isset($template_setting['text_capitalize']) && $template_setting['text_capitalize'] && isset($data['param'])){
                    
                    $param_name = $data['param'];
                    
                    $data['param'] = array();
                    
                    foreach ($param_name as $key_param => $value_param) {
                        $data['param'][ $key_param ]['name'] = mb_convert_case($value_param['name'], MB_CASE_TITLE, "UTF-8");
                        $data['param'][ $key_param ]['value'] = mb_convert_case($value_param['value'], MB_CASE_TITLE, "UTF-8");
                        if(isset($value_param['unit'])){
                            
                            $data['param'][ $key_param ]['unit'] = $value_param['unit'];
                            
                        }
                    }
                    
                }
                
                $param_to_url = array();
                
                //дополнительные элементы
                if(isset($this->general_setting['count_custom_elements'])){
                    
                    $count_custom_elements = (int)$this->general_setting['count_custom_elements'];
                    
                    if($count_custom_elements){
                        
                        for($i=0;$i<$count_custom_elements;$i++){
                            
                            $name_element_key = 'custom_elements_name_'.$i;
                            
                            $field_element_key = 'custom_elements_field_'.$i;
                            
                            if(isset($template_setting[$name_element_key]) && $template_setting[$name_element_key] && isset($template_setting[$field_element_key]) && $template_setting[$field_element_key]['field']['status']){
                                
                                $data['custom_elements'][$template_setting[$name_element_key]] = $this->getNameAttributeForType($product,$template_setting,$template_setting[$field_element_key]['field']['status'],$field_element_key);
                                
                            }
                            
                        }
                        
                        for($i=0;$i<$count_custom_elements;$i++){
                            
                            $name_element_key = 'param_to_url_name_'.$i;
                            
                            $field_element_key = 'param_to_url_value_'.$i;
                            
                            if(isset($template_setting[$name_element_key]) && $template_setting[$name_element_key]!=='' && isset($template_setting[$field_element_key]) && $template_setting[$field_element_key]['field']['status']){
                                
                                $param_to_url[] = $template_setting[$name_element_key].'='.$this->getNameAttributeForType($product,$template_setting,$template_setting[$field_element_key]['field']['status'],$field_element_key);
                                
                            }
                            
                        }
                        
                    }
                    
                }
                
                if($param_to_url){
                    
                    $data['url'] .= '&'.implode('&', $param_to_url);
                    
                }
                
                $data['bid'] = '';
                
                for($i=0;$i<5;$i++){
                            
                    $name_element_key = 'bid_field_to_db_'.$i;
    
                    $field_element_key = 'bid_field_to_db_oper_'.($i-1);
    
                    if($i==0 && isset($template_setting[$name_element_key]['field']['status']) && $template_setting[$name_element_key]['field']['status']){
    
                        $data['bid'] = $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
    
                    }
                    
                    if(isset($template_setting[$field_element_key]) && isset($template_setting[$name_element_key]['field']['status']) && $template_setting[$name_element_key]['field']['status']){
                        
                        if($template_setting[$field_element_key]=='+'){
                            
                            $data['bid'] = $data['bid'] + $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
                            
                        }elseif($template_setting[$field_element_key]=='-'){
                            
                            $data['bid'] = $data['bid'] - $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
                            
                        }elseif($template_setting[$field_element_key]=='*'){
                            
                            $data['bid'] = $data['bid'] * $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
                            
                        }elseif($template_setting[$field_element_key]=='/'){
                            
                            $data['bid'] = $data['bid'] / $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
                            
                        }
                        
                    }
                    
                }
                
                if($data['bid']>0){
                    
                    $data['bid'] = round($data['bid']*100);
                    
                }
                
                if(isset($product['group_id'])){
                    
                    $data['group_id'] = $product['group_id'];
                    
                }
                
                $data['cbid'] = '';
                
                for($i=0;$i<5;$i++){
                            
                    $name_element_key = 'cbid_field_to_db_'.$i;
    
                    $field_element_key = 'cbid_field_to_db_oper_'.($i-1);
    
                    if($i==0 && isset($template_setting[$name_element_key]['field']['status']) && $template_setting[$name_element_key]['field']['status']){
    
                        $data['cbid'] = $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
    
                    }
                    
                    if(isset($template_setting[$field_element_key]) && isset($template_setting[$name_element_key]['field']['status']) && $template_setting[$name_element_key]['field']['status']){
                        
                        if($template_setting[$field_element_key]=='+'){
                            
                            $data['cbid'] = $data['cbid'] + $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
                            
                        }elseif($template_setting[$field_element_key]=='-'){
                            
                            $data['cbid'] = $data['cbid'] - $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
                            
                        }elseif($template_setting[$field_element_key]=='*'){
                            
                            $data['cbid'] = $data['cbid'] * $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
                            
                        }elseif($template_setting[$field_element_key]=='/'){
                            
                            $data['cbid'] = $data['cbid'] / $this->getNameAttributeForType($product,$template_setting,$template_setting[$name_element_key]['field']['status'],$name_element_key);;
                            
                        }
                        
                    }
                    
                }
                
                if($data['cbid']>0){
                    
                    $data['cbid'] = round($data['cbid']*100);
                    
                }
                
                if(isset($this->request->get['fb'])){
                    
                    $data['condition'] = 'new';
                    
                    if(isset($template_setting['fb_condition'])){
                        
                        $data['condition'] = $template_setting['fb_condition'];
                        
                    }
                    
                }
                
                if(isset($product['product_to_category']['main_category']) && $product['product_to_category']['main_category']){
                    
                    $data['categoryId'] = $product['product_to_category']['main_category'];
                    
                }else{
                    
                    $data['categoryId'] = $product['category_id'];
                    
                }
                
                //категория
                
                if(!$skip_this_offer && isset($this->general_setting['dall_categories_to_yml']) && $this->general_setting['dall_categories_to_yml']){
                    
                    
                    $this->setProductCategories($data['categoryId']);
                    
                    
                }
                
                if(isset($this->general_setting['replace_cid_to_product_on_this']) && isset($product['product_to_category']['category_ids'])){
                    
                    $p_category_ids = $product['product_to_category']['category_ids'];
                    
                    $replace_cid = FALSE;
                    
                    foreach ($p_category_ids as $p_category_id) {
                        
                        if(in_array($p_category_id, $this->general_setting['replace_cid_to_product_on_this'])){
                            
                            $replace_cid = TRUE;
                            
                        }
                        
                    }
                    
                    if($replace_cid){
                        
                        
                        foreach ($p_category_ids as $p_category_id_key => $p_category_id) {
                        
                            if(!in_array($p_category_id, $this->general_setting['replace_cid_to_product_on_this'])){
    
                                unset($p_category_ids[$p_category_id_key]);
    
                            }
    
                        }
                        
                        $product['product_to_category']['category_ids'] = $p_category_ids;
                        
                        $data['categoryId'] = current($p_category_ids);
                        
                    }
                    
                }
                
                if(isset($template_setting['all_product_category']) && $template_setting['all_product_category'] && isset($product['product_to_category']['category_ids'])){
                    
                    $main_category = $data['categoryId'];
    				
                    $data['categoryId'] = $product['product_to_category']['category_ids'];
    				
                    $data['categoryId'][$main_category] = $main_category;
                    
                }
    	    
    	    if(isset($this->general_setting['promos'])){
    		
    		$this->checkPromosByOfferData($data);
    		
    	    }
    	    
    	    if(isset($data['categoryId']) && isset($this->general_setting['mapping_market_place_categories_replace'])){
    		
    		if(is_array($data['categoryId'])){
    		    
    		    foreach ($data['categoryId'] as $categoryId => $tmp) {
    
    			if(isset($this->general_setting['mapping_market_place_categories_replace']) && isset($this->general_setting['mapping_market_place_categories_replace'][$categoryId])){
    
    			    $data['categoryId'][$this->general_setting['mapping_market_place_categories_replace'][$categoryId]] = $this->general_setting['mapping_market_place_categories_replace'][$categoryId];
    
    			}
    
    		    }
    		    
    		}else{
    		    
    		    if(isset($this->general_setting['mapping_market_place_categories_replace']) && isset($this->general_setting['mapping_market_place_categories_replace'][$data['categoryId']])){
    
    			$data['categoryId'] = $this->general_setting['mapping_market_place_categories_replace'][$data['categoryId']];
    
    		    }
    		    
    		}
    		
    	    }
                
                $data['url'] = str_replace(' ', '%20', $data['url']); 
                
                if(isset($template_setting['replace_av_true']) && $template_setting['replace_av_true']!='true' && $data['available']=='true'){
                    
                    $data['available'] = $template_setting['replace_av_true'];
                    
                }
                
                if(isset($template_setting['replace_av_false']) && $template_setting['replace_av_false']!='false' && $data['available']=='false'){
                    
                    $data['available'] = $template_setting['replace_av_false'];
                    
                }
                
                if(!$skip_this_offer){
                    
                    $this->setOffer($data,$template_setting);
                    
                    $this->count_offers++;
                    
                }else{
                    
                    $this->count_skips++;
                }
                
                return;
            }
    	
    	public function checkPromosByOfferData($offer){
    	    
    	    $offer_id = $offer['id'];
    	    
    	    $category_ids = array();
    	    
    	    if(isset($offer['categoryId']) && is_array($offer['categoryId'])){
    		
    		$category_ids = $offer['categoryId'];
    		
    	    }elseif(isset($offer['categoryId'])){
    		
    		$category_ids = array($offer['categoryId']=>$offer['categoryId']);
    		
    	    }
    	    
    	    foreach ($this->general_setting['promos'] as $promos_id => $promos) {
    		
    		if(!isset($promos['product_ids_checked'])){
    		    
    		    $product_ids_checked = $this->{$this->path_on_model}->cleanExplode(',',$promos['product_ids']);
    		    
    		    $promos['product_ids_checked'] = $product_ids_checked;
    		    
    		    $promos['product_ids_selected'] = array();
    		    
    		}
    		
    		if(!isset($promos['product_as_gift_ids_checked'])){
    		    
    		    $product_as_gift_ids_checked = $this->{$this->path_on_model}->cleanExplode(',',$promos['product_as_gift_ids']);
    		    
    		    $promos['product_as_gift_ids_checked'] = $product_as_gift_ids_checked;
    		    
    		    $promos['product_as_gift_ids_selected'] = array();
    		    
    		}
    		
    		if(in_array($offer_id,$promos['product_ids_checked'])){
    		    
    		    $promos['product_ids_selected'][$offer_id] = $offer_id;
    		    
    		}
    		
    		if(in_array($offer_id,$promos['product_as_gift_ids_checked'])){
    		    
    		    $promos['product_as_gift_ids_selected'][$offer_id] = $offer_id;
    		    
    		}
    		
    		if(!isset($promos['category_ids_checked'])){
    		    
    		    $promos['category_ids_checked'] = array();
    		    
    		    $promos['category_ids_selected'] = array();
    		    
    		}
    		
    		if(isset($promos['category_ids']) && $promos['category_ids']){
    		    
    		    $promos['category_ids_checked'] = $promos['category_ids'];
    		    
    		}
    		
    		foreach ($promos['category_ids_checked'] as $key => $category_id_checked) {
    		    
    		    if(isset($category_ids[$category_id_checked])){
    			
    			$promos['category_ids_selected'][$category_id_checked] = $category_id_checked;
    			
    			$promos['product_ids_selected'][$offer_id] = $offer_id;
    			
    			unset($promos['category_ids_checked'][$key]);
    			
    		    }
    		    
    		}
    		
    		$this->general_setting['promos'][$promos_id] = $promos;
    		
    	    }
    	    
    	}
            
            public function getParamOption($ym_options) {
                $result = array();
                foreach ($ym_options as $key => $value) {
                    $name = $this->prepareField($value['name']);
                    $value['unit'] = $this->prepareField($value['unit']);
                    $unit = '';
                    if($value['unit']){
                        $unit = $value['unit'];
                    }
                    if(isset($value['product_option_value']) && $value['product_option_value']){
                        foreach ($value['product_option_value'] as $key => $product_option_value) {
                            if(!$unit){
                                $result[] = array('name'=>  $name,'value'=>  $this->prepareField($product_option_value['name']));
                            }else{
                                $result[] = array('name'=>  $name,'value'=>  $this->prepareField($product_option_value['name']),'unit'=>$unit);
                            }
                        }
                    }
                }
                return $result;
            }
            
            public function getParamAttribute($ym_attributes,$template_setting=array()) {
                $result = array();
                foreach ($ym_attributes as $key => $value) {
                    $value['unit'] = $this->prepareField($value['unit']);
                    $unit = '';
                    if($value['unit']){
                        $unit = $value['unit'];
                    }
                    if(isset($value['attribute']) && $value['attribute']){
                        foreach ($value['attribute'] as $key => $attribute) {
                            
                            $unit_result = $unit;
                            
                            if(isset($attribute['unit']) && $attribute['unit']!==''){
                                
                                $unit_result = $attribute['unit'];
                                
                            }
                            
                            if(isset($template_setting['attribute_sintaxis']) && $template_setting['attribute_sintaxis']){
                        
                                $name_attribute = $this->prepareField($attribute['name']);
                                $value_attribute = $this->prepareField($attribute['text']);
    
                            }else{
    
                                $name_attribute = $this->prepareField($value['name']);
                                $value_attribute = $this->prepareField($attribute['name'].' '.$attribute['text']);
    
                            }
                            
                            
                            if(!$unit_result){
                                $result[] = array('name'=>  $name_attribute,'value'=>  $value_attribute);
                            }else{
                                $result[] = array('name'=>  $name_attribute,'value'=>  $value_attribute,'unit'=>$unit_result);
                            }
                        }
                    }
                }
                return $result;
            }
            
            public function getNameAttributeForType($product,$template_setting,$composite_types,$field_name) {
                
                $result = '';
                switch ($composite_types){
                    case 'attribute_id':
                        if(isset($template_setting[$field_name]['field'][$composite_types])){
                            $attributes_parts = explode('___', $template_setting[$field_name]['field'][$composite_types]);
                            $attribute_group_id = $attributes_parts[0];
                            $attribute_id = $attributes_parts[1];
                            if($product['all_attributes']){
                                foreach ($product['all_attributes'] as $group_attributes) {
                                    if($group_attributes['attribute_group_id'] == $attribute_group_id && $group_attributes['attribute']){
                                        foreach ($group_attributes['attribute'] as $attribute_group_value) {
                                            if($attribute_group_value['attribute_id']==$attribute_id){
                                                $result = trim($this->prepareField($attribute_group_value['text']));
                                            }
                                        }
    
                                    }
                                }
                            }
                        }
                        break;
                    case 'option_id':
                        if(isset($template_setting[$field_name]['field'][$composite_types])){
                            $option_id = $template_setting[$field_name]['field'][$composite_types];
                            if($product['all_options']){
                                foreach ($product['all_options'] as $option) {
                                    if($option['option_id'] == $option_id){
    
                                        $name_option = trim($this->prepareField($option['name']));
                                        $name_option_vields = array();
                                        foreach ($option['product_option_value'] as $product_option_value) {
                                            $name_option_vields[] = trim($this->prepareField($product_option_value['name']));
                                        }
                                        $result = implode(' ', $name_option_vields);
                                    }
                                }
                            }
                        }
                        break;
                    case 'manufacturer_id':
                        $product['manufacturer'] = $this->prepareField($product['manufacturer']);
                        if($product['manufacturer']){
                            $result = $product['manufacturer'];
                        }
                        break;
    
                    case 'price':
                        if(isset($this->prices[$product['product_id']])){
                            $result = $this->prices[$product['product_id']];
                        }
                        break;
    
                    case 'weight':
                        if((float)$product['weight']>0){
                            $result = (float)$this->weight->format($product['weight'],$product['weight_class_id']);
                        }
                        break;
    
                    case 'length_width_height':
                        $length_width_height = array();
                        if((float)$product['length']>0){
                            $length_width_height[] = (float)$this->length->format($product['length'],$product['length_class_id']);
                        }
                        if((float)$product['width']>0){
                            $length_width_height[] = (float)$this->length->format($product['width'],$product['length_class_id']);
                        }
                        if((float)$product['height']>0){
                            $length_width_height[] = (float)$this->length->format($product['height'],$product['length_class_id']);
                        }
                        if($length_width_height){
                            $result = implode('/', $length_width_height);
                        }
                        break;
                    case 'category_id':
                        if(isset($this->categories[$product['category_id']]['name'])){
                            $result = $this->categories[$product['category_id']]['name'];
                        }
                        break;
                    case 'text_field':
                        if(isset($template_setting[$field_name]['field']['text_field'])){
                            $result = $this->prepareField($template_setting[$field_name]['field']['text_field']);
                        }
                        break;
                    case 'keywords':
                        if(isset($product['tag'])){
                            $result = str_replace(', ',',', $this->prepareField($product['tag'])) ;
                        }
                        break;
                    case 'description_whis_html':
                        if($product['description']){
                            $result = '<![CDATA['. html_entity_decode($product['description']).']]>';
                        }
                        break;
                    case 'date_add':
                        if($product['date_added']){
                            $result = $product['date_added'];
                        }
                        break;
                    case 'date_mod':
                        if($product['date_modified']){
                            $result = $product['date_modified'];
                        }
                        break;
                        
                        
                    case 'product_meta_description':
                            if(isset($product['meta_description'])){
                                $result = $product['meta_description'];
                            }
                        break;
                    case 'product_meta_title':
                            if(isset($product['meta_title'])){
                                $result = $product['meta_title'];
                            }
                        break;
                    case 'product_meta_keyword':
                            if(isset($product['meta_keyword'])){
                                $result = $product['meta_keyword'];
                            }
                        break; 
                        
                    default:
                    if(isset($product[$composite_types])){
                        $product[$composite_types] = $this->prepareField($product[$composite_types]);
                        if($product[$composite_types]){
                            $result = $product[$composite_types];
                        }
                    }
                    break;
                }
                return $result;
            }
    
            public function getDescriptionAttribute($product,$template_setting){
                
                if(!isset($template_setting['offer_description']['field']) || !$template_setting['offer_description']['field']){
                    $description = $this->prepareField($product['description'],TRUE);
                    return $description;
                }
                else{
                    
                    $key = $template_setting['offer_description']['field'];
                    
                    switch ($key){
                        case 'option_id':
                        $description = '';
                        $option = $this->getParamOption($product['ym_options']);
                        if($option){
                            foreach ($option as $value) {
                                $description .= ' '.implode(' ', $value);
                            }
                        }
                        break;
    
                        case 'attribute_id':
                        $description = '';
                        $attributes = $this->getParamAttribute($product['ym_attributes']);
                        if($attributes){
                            foreach ($attributes as $value) {
                                $description .= ' '.implode(' ', $value);
                            }
                        }
                        break;
    
                        case 'meta_title':
                            if(isset($product['meta_title']))
                            $description = $this->prepareField($product['meta_title'],TRUE);
                        break;
                    
                        case 'meta_keyword':
                            if(isset($product['meta_keyword']))
                            $description = $this->prepareField($product['meta_keyword'],TRUE);
                        break;
    
                        case 'meta_description':
                            if(isset($product['meta_description']))
                            $description = $this->prepareField($product['meta_description'],TRUE);
                        break;
                        
                        case 'description':
                            if(isset($product['description']))
                            $description = $this->prepareField($product['description'],TRUE);
                        break;
                        
                        default:
                            $description = '';
                        break;
                    }
                    return $description;
                }
                
                $result = $this->prepareField($product['name']);
                if(isset($template_setting['offer_name']['field']) && $template_setting['offer_name']['field']=='name'){
                    return $result;
                }
                if(isset($template_setting['offer_name']['field']) && $template_setting['offer_name']['field']=='meta_title' && isset($product['meta_title'])){
                    $result = $this->prepareField($product['meta_title']);
                    return $result;
                }
                if(isset($template_setting['offer_name']['field']) && $template_setting['offer_name']['field']=='composite' && $template_setting['offer_name']['composite']){
                    ksort($template_setting['offer_name']['composite']);
                    $name = array();
                    foreach ($template_setting['offer_name']['composite'] as $composite) {
                        //атрибут
                        if($composite['status']=='attribute_id'){
                            $attributes_parts = explode('___', $composite['attribute_id']);
                            $attribute_group_id = $attributes_parts[0];
                            $attribute_id = $attributes_parts[1];
                            if($product['all_attributes']){
                                foreach ($product['all_attributes'] as $group_attributes) {
                                    if($group_attributes['attribute_group_id'] == $attribute_group_id && $group_attributes['attribute']){
                                        foreach ($group_attributes['attribute'] as $attribute_group_value) {
                                            if($attribute_group_value['attribute_id']==$attribute_id){
                                                $name[] = trim($this->prepareField($attribute_group_value['name'])).': '.trim($this->prepareField($attribute_group_value['text']));
                                            }
                                        }
                                        
                                    }
                                }
                            }
                        }
                        //опция
                        elseif($composite['status']=='option_id'){
                            $option_id = $composite['option_id'];
                            if($product['all_options']){
                                foreach ($product['all_options'] as $option) {
                                    if($option['option_id'] == $option_id){
                                        
                                        $name_option = trim($this->prepareField($option['name']));
                                        $name_option_vields = array();
                                        foreach ($option['product_option_value'] as $product_option_value) {
                                            $name_option_vields[] = trim($this->prepareField($product_option_value['name']));
                                        }
                                        if($name_option_vields){
                                            $name[] = $name_option.': '.  implode(', ', $name_option_vields);
                                        }else{
                                            $name[] = $name_option;
                                        }
                                    }
                                }
                            }
                        }
                        //цена
                        elseif($composite['status']=='price'){
                            $name[] = $this->prices[$product['product_id']];
                        }
                        //вес
                        elseif($composite['status']=='weight'){
                            if((float)$product['weight']>0){
                                $name[] = $this->weight->format($product['weight'],$product['weight_class_id']);
                            }
                        }
                        //производитель
                        elseif($composite['status']=='manufacturer_id'){
                            $product['manufacturer'] = $this->prepareField($product['manufacturer']);
                            if($product['manufacturer']){
                                $name[] = $product['manufacturer'];
                            }
                        }
                        //категория
                        elseif($composite['status']=='category_id'){
                            $name[] = $this->categories[$product['category_id']]['name'];
                        }
                        //габариты
                        elseif($composite['status']=='length_width_height'){
                            $length_width_height = array();
                            if((float)$product['length']>0){
                                $length_width_height[] = $this->length->format($product['length'],$product['length_class_id']);
                            }
                            if((float)$product['width']>0){
                                $length_width_height[] = $this->length->format($product['width'],$product['length_class_id']);
                            }
                            if((float)$product['height']>0){
                                $length_width_height[] = $this->length->format($product['height'],$product['length_class_id']);
                            }
                            if($length_width_height){
                                $name[] = implode('/', $length_width_height);
                            }
                        }
                        //остальные
                        elseif (isset ($product[$composite['status']])) {
                            $product[$composite['status']] = $this->prepareField($product[$composite['status']]);
                            if($product[$composite['status']]){
                                $name[] = $product[$composite['status']];
                            }
                        }
                    }
                    $result = trim($this->prepareField(implode(' ', $name)));
                    return $result;
                }
            }
            
            public function getNameAttribute($product,$template_setting,$field_name){
                
                $result = '';
                
                if(isset($template_setting[$field_name]['field']['status']) && $template_setting[$field_name]['field']['status']!='composite'){
                    
                    $result = $this->getNameAttributeForType($product,$template_setting,$template_setting[$field_name]['field']['status'],$field_name);
                    
                }elseif(isset($template_setting[$field_name]['field']['status']) && $template_setting[$field_name]['field']['status']=='composite'){
                    
                    $field_type = 'composite';
                    
                    $count_composite_elements = 10;
                    
                    $result_parts = array();
                    
                    for($i=1;$i<$count_composite_elements;$i++){
                        
                        if(isset($template_setting[ $field_name.'_'.$field_type.'_'.$i ]) && $template_setting[ $field_name.'_'.$field_type.'_'.$i ]){
                            
                            $result_parts[] = $this->getNameAttributeForType($product,$template_setting,$template_setting[ $field_name.'_'.$field_type.'_'.$i ]['field']['status'],$field_name.'_'.$field_type.'_'.$i);
                            
                        }
                        
                    }
                    
                    if($result_parts){
                        
                        $result = implode(' ', $result_parts);
                        
                    }
                    
                    
                }
                return $result;
            }
            
            public function getTemplateSettingNameComposite() {
                $columns_product_description = $this->db->query('SHOW COLUMNS FROM '.DB_PREFIX.'product_description');
                $columns_product = $this->db->query('SHOW COLUMNS FROM '.DB_PREFIX.'product');
    
                $template_setting_name_composite['name'] = 'name';
                if($columns_product_description->rows){
                    foreach($columns_product_description->rows as $column){
                        if($column['Field']=='meta_title'){
                            $template_setting_name_composite['meta_title'] = 'meta_title';
                        }
                    }
                }
                $unset_product_fileds = array_flip(array('quantity','stock_status_id','image','shipping','points','tax_class_id','date_available','weight_class_id','length_class_id','subtract','minimum','sort_order','status','viewed','date_added','date_modified'));
                $product_fileds = array();
                if($columns_product->rows){
                    foreach($columns_product->rows as $key=>$column){
                        if(!isset($unset_product_fileds[$column['Field']])){
                            $product_fileds[$column['Field']] = $column['Field'];
                        }
                    }
                }
                if(isset($product_fileds['length']) && isset($product_fileds['width']) && isset($product_fileds['height'])){
                    unset($product_fileds['length']);
                    unset($product_fileds['width']);
                    unset($product_fileds['height']);
                    $product_fileds['length_width_height'] = 'length_width_height';
                }
                $template_setting_name_composite += $product_fileds;
                $template_setting_name_composite['category_id'] = 'category_id';
                $template_setting_name_composite['option_id'] = 'option_id';
                $template_setting_name_composite['attribute_id'] = 'attribute_id';
                return $template_setting_name_composite;
            }
    
            public function getDeliveryOption($tamplate_setting,$price='',$weight='',$stock_status_id=''){
                $result = array();
                if(isset($tamplate_setting['delivery-options']['status'])){
                    unset($tamplate_setting['delivery-options']['status']);
                }
                foreach ($tamplate_setting['delivery-options'] as $delivery_options) {
                    $delivery_options['days'] = trim($delivery_options['days']);
                    $delivery_options['order-before'] = trim($delivery_options['order-before']);
                    $delivery_options['cost'] = trim($delivery_options['cost']);
                    
                    $skip = FALSE;
                    //var_dump($delivery_options['price_from']);exit();
                    if(isset($delivery_options['price_to']) && $delivery_options['price_to']!='' && isset($delivery_options['price_from']) && $delivery_options['price_from']!='' && $price!=''){
                        
                        
                        if($price>=$delivery_options['price_to'] || $price<$delivery_options['price_from']){
                            
                            $skip = TRUE;
                            
                        }
                        
                    }elseif(isset($delivery_options['weight_from']) && $delivery_options['weight_from']!='' && isset($delivery_options['weight_to']) && $delivery_options['weight_to']!='' && $weight!=''){
                        
                        if($weight>=$delivery_options['weight_to'] || $weight<$delivery_options['weight_from']){
                            
                            $skip = TRUE;
                            
                        }
                        
                    }
                    
                    if(isset($delivery_options['stock_status_id']) && $stock_status_id!='' && !isset($delivery_options['stock_status_id'][$stock_status_id])){
                        
                        $skip = TRUE;
                        
                    }
                    if(!$skip && ($delivery_options['cost']!='' || $delivery_options['days']!='' || $delivery_options['order-before']!='')){
                        if($delivery_options['cost']!=''){
                            $option['cost'] = (int)$delivery_options['cost'];
                        }
                        if($delivery_options['days']!=''){
                            $option['days'] = $delivery_options['days'];
                        }
                        if($delivery_options['order-before']!=''){
                            $option['order-before'] = $delivery_options['order-before'];
                        }
                        $result[] = $option;
                        unset($option);
                    }
                }
                return $result;
            }
            
            public function getPrice($price,$product,$tamplate_setting){
                
                $result_price = 0.0;
                $price = $this->tax->calculate($price, $product['tax_class_id']);
                $new_price = (float)$price;
                if(isset($tamplate_setting['ymlprice']) && $tamplate_setting['ymlprice']){
                    $tamplate_setting['ymlprice'] = (float)$tamplate_setting['ymlprice'];
                    $new_price = $new_price + $tamplate_setting['ymlprice']/100*$price;
                }
                
                if($new_price==0.0){
                    $result_price =  $price;
                }else{
                    $result_price = $new_price;
                }
                
                if(isset($tamplate_setting['price_currencies_from']) && $tamplate_setting['price_currencies_from'] && isset($tamplate_setting['price_currencies_to']) && $tamplate_setting['price_currencies_to']){
                    
                    $result_price = $this->currency->convert($result_price,$tamplate_setting['price_currencies_from'],$tamplate_setting['price_currencies_to']);
                    
                }
                
                return $result_price;
            }
            
            public function getPictureAttributes($product,$tamplate_setting) {
                if(isset($tamplate_setting['count_pictures']) && !$tamplate_setting['count_pictures']){
                    return array();
                }elseif(isset($tamplate_setting['count_pictures'])){
                    $count_pictures = (int)$tamplate_setting['count_pictures'];
                }else{
                    $count_pictures = 1;
                }
                
                $pictures_sizes = 500;
                $default_scale = '';
                $no_cache = FALSE;
                
                if(isset($tamplate_setting['pictures_sizes'])){
                    $tamplate_setting['pictures_sizes'] = (int)$tamplate_setting['pictures_sizes'];
                    if($tamplate_setting['pictures_sizes']>0){
                        $pictures_sizes = $tamplate_setting['pictures_sizes'];
                    }
                }
                if(isset($tamplate_setting['rule_picture'])){
                    if($tamplate_setting['rule_picture']=='by_w_side'){
                        $default_scale = 'w';
                    }
                    elseif($tamplate_setting['rule_picture']=='by_h_side'){
                        $default_scale = 'h';
                    }
                    elseif($tamplate_setting['rule_picture']=='no_cache'){
                        $no_cache = TRUE;
                    }
                }
                $result = array();
                if ($product['image'] && $product['image']!='no_image.jpg' && $product['image']!='no_image.png' && $product['image']!='no-image.jpg' && $product['image']!='no-image.png' && file_exists(DIR_IMAGE.$product['image'])) {
                    
                    $this->load->model('tool/image');
                    if($no_cache){
                        $result[] = $this->HTTP_SERVER.'image/'.$product['image'];
                    }else{
                        $result[] = $this->resizeImage($product['image'],$pictures_sizes,$pictures_sizes,$default_scale,  $this->HTTP_SERVER);
                    }
                    
                    if($product['images']){
                        for($i=0;($i<($count_pictures-1) && isset($product['images'][$i]));$i++){
                            if($no_cache && file_exists(DIR_IMAGE.$product['images'][$i]['image'])){
                                $result[] = $this->HTTP_SERVER.'image/'.$product['images'][$i]['image'];
                            }elseif($product['images'][$i]['image']!=$product['image'] && $product['images'][$i]['image'] && file_exists(DIR_IMAGE.$product['images'][$i]['image'])){
                                //$result[] = $this->model_tool_image->resize($product['images'][$i]['image'], $pictures_sizes, $pictures_sizes);
                                $result[] = $this->resizeImage($product['images'][$i]['image'],$pictures_sizes,$pictures_sizes,$default_scale,  $this->HTTP_SERVER);
                            }
                        }
                    }
                }
                return $result;
            }
            
            public function resizeImage($file,$w,$h,$d,$HTTP_SERVER) {
                
                $image = $this->{$this->path_on_model}->resizeImage($file,$w,$h,$d,  $HTTP_SERVER);
                
                return $image;
            }
    
            public function getCategoriesAndOffers($filter_data_group_id,$content_language_id,$setting_yml=array()) {
                
                $ym_categories = array();
                $this->load->model($this->path_oc_version.'/ocext_feed_generator_yamarket');
                
                $all_yml_export_ocext_ym_filter_data_categories = $this->{$this->path_on_model}->getFilterData('ocext_feed_generator_yamarket_ym_filter_category',$filter_data_group_id);
                
    	    /*
    	    
                foreach ($all_yml_export_ocext_ym_filter_data_categories as $c_id => $crow) {
                    
                    if(FALSE && isset($crow['disable_parent_child_categories']) && $crow['disable_parent_child_categories']){
                        
                        $this->general_setting['replace_cid_to_product_on_this'][$c_id] = $c_id;
                        
                    }
                    
                }
    	    
    	    */
                
                if($all_yml_export_ocext_ym_filter_data_categories){
                    $ym_categories = $all_yml_export_ocext_ym_filter_data_categories;
                    if($ym_categories){
                        foreach ($ym_categories as $category_id=>$ym_category){
                            if(!isset($ym_category['category_id'])){
                                unset($ym_categories[$category_id]);
                            }
                        }
                        
                        if(!$ym_categories){
                            $ym_categories = $all_yml_export_ocext_ym_filter_data_categories;
                        }
                    }
                }
                $ym_manufacturers = array();
                $all_yml_export_ocext_ym_filter_data_manufacturers = $this->{$this->path_on_model}->getFilterData('ocext_feed_generator_yamarket_ym_filter_manufacturers',$filter_data_group_id);
                if($all_yml_export_ocext_ym_filter_data_manufacturers){
                    $ym_manufacturers = $all_yml_export_ocext_ym_filter_data_manufacturers;
                    if($ym_manufacturers){
                        foreach ($ym_manufacturers as $manufacturer_id=>$ym_manufacturer){
                            if(!isset($ym_manufacturer['manufacturer_id'])){
                                unset($ym_manufacturers[$manufacturer_id]);
                            }
                        }
                        
                        if(!$ym_manufacturers){
                            $ym_manufacturers = $all_yml_export_ocext_ym_filter_data_manufacturers;
                            $ym_manufacturers[''] = array("setting_id"=>"0");
                            $ym_manufacturers[0] = array("setting_id"=>"0");
                        }
                    }
                }
                
                
                $this->load->model($this->path_oc_version.'/ocext_feed_generator_yamarket');
                $categories_and_products = $this->{$this->path_on_model}->getCategoriesAndProducts($ym_categories,$ym_manufacturers,$filter_data_group_id,$content_language_id,  $this->general_setting);
                
                if(isset($this->general_setting['replace_cid_to_product_on_this']) && isset($categories_and_products['categories']) && $categories_and_products['categories']){
                    
                    foreach ($categories_and_products['categories'] as $key => $category_info) {
                        
                        if(in_array($category_info['category_id'], $this->general_setting['replace_cid_to_product_on_this'])){
                            
                            $category_info['replace_cid_to_product_on_this'] = TRUE;
                            
                            $categories_and_products['categories'][$key] = $category_info;
                            
                        }
                        
                    }
                    
                }
    	    
    	    $this->general_setting['mapping_market_place_categories_replace'] = array();
    	    
    	    if(isset($categories_and_products['mapping_market_place_categories'])){
    		
    		foreach ($categories_and_products['mapping_market_place_categories'] as $mapping_market_place_category) {
    		    
    		    $categories_and_products['categories'][] = $mapping_market_place_category;
    		    
    		    $this->general_setting['mapping_market_place_categories_replace'][$mapping_market_place_category['site_category_id']] = $mapping_market_place_category['category_id'];
    		    
    		}
    		
    	    }
    	    
    	    $this->general_setting['settings'] = array();
    	    
    	    if(isset($categories_and_products['settings'])){
    		
    		$this->general_setting['settings'] = $categories_and_products['settings'];
    		
    	    }
                
                if(!isset($setting_yml['products']) || !isset($setting_yml['catalog']) || ( !$categories_and_products[$setting_yml['products']] && !$categories_and_products['cache'] ) || !$categories_and_products[$setting_yml['catalog']]){
                    return FALSE;
                }else{
                    return $categories_and_products;
                }
            }
            
            private function prepareField($field,$description=FALSE) {
                if(is_string($field) && !$description){
                    $field = strip_tags(htmlspecialchars_decode($field));
                    $from = array('"', '&', '>', '<', '\'','`','&acute;','™','©');
                    $to = array('&quot;', '&amp;', '&gt;', '&lt;', '&apos;','','','','');
                    $field = str_replace($from, $to, $field);
                    $field = trim($field);
                }elseif(is_string($field) && $description){
                    $field = htmlspecialchars_decode($field);
                    $from = array('<br>', '</br>','<br />', '<hr>', '\n', '\r','&nbsp;');
                    $to = array($this->eol.' ');
                    $field = str_replace($from, $to, $field);
                    $field = strip_tags($field);
                    $from = array('"', '&', '>', '<', '\'','`','&acute;','™','©');
                    $to = array('&quot;', '&amp;', '&gt;', '&lt;', '&apos;','','','','');
                    $field = str_replace($from, $to, $field);
                    $field = trim($field);
                }
                return $field;
    	}
            
            private function setShopAttributes($name, $value) {
                $attributes = array('name', 'company', 'url', 'platform', 'version');
                if (in_array($name, $attributes)) {
                        $this->shop[$name] = $this->prepareField($value);
                }
    	}
            
            private function setCurrencyAttributes($currency, $rate = 'CBRF') {
                if($currency){
                    if(!isset($this->currencies[0])){
                        $this->currencies[] = array(
                            'id'=>$currency,
                            'rate'=>1
                        );
                    }else{
                        $this->currencies[] = array(
                            'id'=>$currency,
                            'rate'=>$rate
                        );
                    }
                    return TRUE;
                }else{
                    return FALSE;
                }
    	}
            
            private function setCategoryAttrubite($name, $category_id, $parent_id = 0, $category=array()) {
                $name = $this->prepareField($name);
                if(!$category_id || !$name) {
                    return;
                }
                
                if($parent_id) {
                    $this->categories[$category_id] = array(
                            'id'=>$category_id,
                            'parentId'=>$parent_id,
                            'name'=>$this->prepareField($name)
                    );
                }else{
                    $this->categories[$category_id] = array(
                        'id'=>$category_id,
                        'name'=>$this->prepareField($name)
                    );
                }
                
                if(isset($this->general_setting['add_settings']) && isset($this->general_setting['add_settings']['add_ordering_to_category']) && $this->general_setting['add_settings']['add_ordering_to_category']){
                    
                    $this->categories[$category_id]['attributes']['ordering'] = (int)$category['sort_order'];
                    
                }
                
                if(isset($this->general_setting['add_settings']) && isset($this->general_setting['add_settings']['add_url_to_category']) && $this->general_setting['add_settings']['add_url_to_category']){
                    
                    $this->categories[$category_id]['attributes']['url'] = $this->prepareField($this->url->link('product/category', 'category_id='.$category_id));
                    
                }
                
    	}
            
            protected function getPathWhisCategories($category_id,$old_path = '') {
                if (isset($this->categories[$category_id])) {
                    if (!$old_path) {
                        $new_path = $this->categories[$category_id]['id'];
                    } else {
                        $new_path = $this->categories[$category_id]['id'].'_' .$old_path;
                    }	
                    if (isset($this->categories[$category_id]['parentId'])) {
                        return $this->getPathWhisCategories($this->categories[$category_id]['parentId'], $new_path);
                    } else {
                        return $new_path;
                    }
                }
    	}
            
            
            private function setOffer($data,$template_setting=array()) {
                
                $optimization_file_feed_write = 0;
                
                $memory_limit = 0;
                
                if(isset($this->general_setting['optimization_file_feed_write']) && $this->general_setting['optimization_file_feed_write']){
                    
                    $optimization_file_feed_write = $this->general_setting['optimization_file_feed_write'];
                    
                    $this->load->model($this->path_oc_version.'/ocext_feed_generator_yamarket');
                
                    $memory_limit = $this->{$this->path_on_model}->getMemoryLimit($this->memory_limit_on_fwrite);
                    
                }
                
                $custom_elements = array();
                
                if(isset($data['custom_elements'])){
                    
                    $custom_elements = $data['custom_elements'];
                    
                }
                
                $offer = array();
                $attributes = array('id', 'type', 'available', 'bid', 'cbid', 'param', 'fee', 'group_id');
                $attributes = array_intersect_key($data, array_flip($attributes));
                
                foreach ($attributes as $key => $value) {
                    switch ($key){
                        case 'id':
                        if ($value > 0) {
                                $offer[$key] = $value;
                        }
                        case 'cbid':
                        if ($value!='') {
                                $offer[$key] = $value;
                        }
                        case 'bid':
                        if ($value!='') {
                                $offer[$key] = $value;
                        }
                        break;
                        
                        case 'fee':
                        $value = (int)$value;
                        if ($value > 0) {
                                $offer[$key] = $value;
                        }
                        break;
    
                        case 'type':
                        if (in_array($value, array('vendor.model'))) {
                                $offer['type'] = $value;
                        }
                        break;
    
                        case 'available':
                        //$offer['available'] = (($value=='true') ? 'true' : 'false');
                        $offer['available'] = $value;
                        break;
    
                        case 'param':
                        if (is_array($value)) {
                            $offer['param'] = $value;
                        }
                        break;
                        
                        case 'group_id':
                        $offer['group_id'] = (int)$value;
                        break;
                    
                        default:
                        break;
                    }
                }
                $type = isset($offer['type']) ? $offer['type'] : '';
                $finded_tags = array('url'=>0, 'price'=>0);
                
                if(isset($data['oldprice']) && $data['oldprice']>0){
                    $finded_tags['oldprice'] = 1;
                }
                
                $finded_tags = array_merge($finded_tags,array('currencyId'=>1, 'categoryId'=>1,'market_category'=>0, 'picture'=>0, 'store'=>0, 'pickup'=>0, 'delivery'=>0,'delivery-options'=>0));
                
                switch ($type) {
                    case 'vendor.model':
                        $finded_tags = array_merge($finded_tags, array('name'=>0,'vendor'=>0, 'vendorCode'=>0, 'model'=>0));
                        break;
                    default:
                        $finded_tags = array_merge($finded_tags, array('name'=>0, 'vendor'=>0, 'vendorCode'=>0, 'model'=>0));
                        break;
                }
                $finded_tags = array_merge($finded_tags, array('description'=>0, 'condition'=>0 , 'typePrefix'=>0, 'sales_notes'=>0, 'manufacturer_warranty'=>0, 'country_of_origin'=>0, 'adult'=>0, 'barcode'=>0, 'weight'=>0,'description'=>0, 'dimensions'=>0, 'age'=>0, 'cpa'=>0, 'rec'=>0));
                $requiredes = array_filter($finded_tags);
                if (sizeof(array_intersect_key($data, $requiredes)) != sizeof($requiredes)) {
                        return;
                }
                $data = array_intersect_key($data, $finded_tags);
                $finded_tags = array_intersect_key($finded_tags, $data);
                $offer['data'] = array();
                foreach ($finded_tags as $key => $value) {
                        $offer['data'][$key] = $this->prepareField($data[$key]);
                }
                
                if($custom_elements){
                    
                    foreach ($custom_elements as $key => $value) {
                        $offer['data'][$key] = $value;
                    }
                }
                
                if(isset($template_setting['replace_tags']) && $template_setting['replace_tags']!==''){
                    
                    $replace_tags_parts = explode('|', $template_setting['replace_tags']);
                    
                    $replace_tags = array();
                    
                    foreach ($replace_tags_parts as $replace_tags_part) {
                        
                        $replace_tags_this = explode('---', $replace_tags_part);
                        
                        if(isset($replace_tags_this[1]) && $replace_tags_this[1] && $replace_tags_this[0]){
                            
                            $replace_tags[$replace_tags_this[0]] = $replace_tags_this[1];
                            
                        }
                        
                    }
                    
                    if($replace_tags){
                        
                        foreach ($offer['data'] as $tag_name => $tmp) {
                            
                            if(isset($replace_tags[$tag_name])){
                                
                                $offer['data'][$replace_tags[$tag_name]] = $tmp;
                                unset($offer['data'][$tag_name]);
                                
                            }
                            
                        }
                        
                    }
                    
                }
                
                if($optimization_file_feed_write){
                 
                    $memory_get_usage = memory_get_usage();
                    
                    $this->offers_fwrire['offers'][] = $offer;
                    
                    if($memory_get_usage >= $memory_limit){
    
                        $fname = $this->cfiles['offers_cache'].$this->request->get['token'].'-'.  count($this->offers_fwrire['cache_files']).'.txt';
                        
                        $this->{$this->path_on_model}->writeCache($fname, $this->offers_fwrire['offers']);
                        
                        $this->offers_fwrire['offers'] = array();
    
                        $this->offers_fwrire['cache_files'][$fname] = $fname;
    
                    }
                    
                }else{
                    
                    $this->offers[] = $offer;
                    
                }
    	}
            
            
            private function getYml() {
                
                if($this->offers_fwrire['offers'] || $this->offers_fwrire['cache_files']){
                    
                    $xml_parts = array();
                    
                    $result = '';
                    
                    if($this->offers_fwrire['offers']){
                        
                        $fname = $this->cfiles['offers_cache'].$this->request->get['token'].'-'.  count($this->offers_fwrire['cache_files']).'.txt';
                        
                        $this->{$this->path_on_model}->writeCache($fname, $this->offers_fwrire['offers']);
    
                        $this->offers_fwrire['offers'] = array();
    
                        $this->offers_fwrire['cache_files'][$fname] = $fname;
                        
                    }
                    
                    //$this->offers_fwrire['offers']
                    
                    if(isset($this->request->get['fb'])){
                        
                        $fb  = '<?xml version="1.0"?>' . $this->eol;
                        $fb .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">' . $this->eol;
                        $fb .= '<title>'.$this->shop['name'].'</title>'. $this->eol;
                        $fb .= $this->createFBTag(array('link'=>''),array('link'=>array('rel'=>'self','href'=>$this->shop['url'])));
                        
                        $fb_parts_cache = $this->cfiles['fb_parts_cache'].$this->request->get['token'].'-'.  count($xml_parts);
                        
                        $fb = $this->replaceTags($fb);
                        
                        $this->{$this->path_on_model}->writeCache($fb_parts_cache,array(), $fb);
                        
                        $xml_parts[$fb_parts_cache] = $fb_parts_cache;
                        
                        $fb = '';
                        
                        if($this->offers_fwrire['cache_files']){
                            
                            foreach ($this->offers_fwrire['cache_files'] as $cache_file) {
                                
                                $offers = $this->getCache($cache_file);
                                
                                foreach ($offers as $num_offer=>$offer) {
                                    
                                    if(isset($offer['id']) && $offer['id'] && isset($offer['available']) && $offer['available'] && isset($offer['data']['description']) && $offer['data']['description'] && isset($offer['data']['vendor']) && $offer['data']['vendor'] && isset($offer['data']['picture']) && $offer['data']['picture'] && isset($offer['data']['price']) && $offer['data']['price'] && isset($offer['data']['name']) && $offer['data']['name']){
    
                                        $fb_data = array();
    
                                        $fb_data['id'] = $offer['id'];
    
                                        $fb_data['availability'] = 'out of stock';
    
                                        if($offer['available']=='true'){
    
                                            $fb_data['availability'] = 'in stock';
    
                                        }
    
                                        $fb_data['condition'] = $offer['data']['condition'];
    
                                        $fb_data['description'] = $offer['data']['description'];
    
                                        foreach ($offer['data']['picture'] as $picture) {
    
                                            if(!isset($fb_data['image_link'])){
    
                                                $fb_data['image_link'] = $picture;
    
                                            }else{
    
                                                $fb_data['additional_image_link'] = $picture;
    
                                            }
    
                                        }
                                        
                                        if(isset($offer['data']['google_product_category'])){
    
                                            $fb_data['google_product_category'] = $offer['data']['google_product_category'];
    
                                        }else{
                                            
                                            unset($fb_data['google_product_category']);
                                            
                                        }
    
                                        $fb_data['link'] = $offer['data']['url'];
    
                                        $fb_data['title'] = $offer['data']['name'];
    
                                        $fb_data['price'] = number_format(round($offer['data']['price'],2),2, '.', '').' '.$offer['data']['currencyId'];
    
                                        $fb_data['brand'] = $offer['data']['vendor'];
    
                                        for($i=0;$i<5;$i++){
    
                                            if(isset($offer['data']['custom_label_'.$i])){
    
                                                $fb_data['custom_label_'.$i] = $offer['data']['custom_label_'.$i];
    
                                            }
    
                                        }
    
                                        $rows = $this->createFBTag($fb_data,array(),'g:');
    
                                        $fb .= $this->getFBElement(array(), 'entry', $rows);
    
                                    }
                                }
                                
                                if($fb){
                                    
                                    $fb_parts_cache = $this->cfiles['fb_parts_cache'].$this->request->get['token'].'-'.  count($xml_parts);
                                
                                    $fb = $this->replaceTags($fb);
                                    
                                    $this->{$this->path_on_model}->writeCache($fb_parts_cache,array(), $fb);
    
                                    $xml_parts[$fb_parts_cache] = $fb_parts_cache;
    
                                    $fb = '';
                                    
                                }
                                
                            }
                            
                        }
                        
                        $fb .= '</feed>';
                    
                        $fb = $this->replaceTags($fb);
                        
                        $fb_parts_cache = $this->cfiles['fb_parts_cache'].$this->request->get['token'].'-'.  count($xml_parts);
    
                        $this->{$this->path_on_model}->writeCache($fb_parts_cache,array(), $fb);
    
                        $xml_parts[$fb_parts_cache] = $fb_parts_cache;
    
                        $rootPath = realpath(DIR_APPLICATION . '..'); 
    
                        if($xml_parts && isset($this->general_setting['fb_filename_export']) && $this->general_setting['fb_filename_export']){
    
                            $file_name_and_path = $rootPath.'/'.$this->general_setting['fb_filename_export'].'.xml';
    
                            if(file_exists($file_name_and_path)){
                                
                                $handle = fopen($file_name_and_path, 'w+');
    
                                fclose($handle);
                                
                            }
    
                            foreach ($xml_parts as $xml_part) {
    
                                if(file_exists(DIR_CACHE.$xml_part) && is_writable($file_name_and_path)){
    
                                    $cache_offers = file_get_contents(DIR_CACHE.$xml_part);
    
                                    $handle = fopen($file_name_and_path, 'a');
    
                                    fwrite($handle, $cache_offers . $this->eol);
    
                                    fclose($handle);
    
                                }else{
    
                                    $this->sendErrorXML(array('Файл не может быть записан. Выключите "Оптимизацию при формировании итогового YML (запись файла частями). Если is_writable = 0 (см. далее), то установите права на запись 755 для папки: '.$this->eol. dirname($file_name_and_path).$this->eol.' is_writable: '.is_writable($file_name_and_path).', cache file_exists: '.file_exists(DIR_CACHE.$xml_part)));
    
                                }
    
                            }
    
                        }
                        
                    }else{
                        
                        $yml  = '<?xml version="1.0" encoding="UTF-8"?>' . $this->eol;
                        $yml .= '<!DOCTYPE yml_catalog SYSTEM "shops.dtd">' . $this->eol;
                        $yml .= '<yml_catalog date="' . date('Y-m-d H:i') . '">' . $this->eol;
                        $yml .= '<shop>' . $this->eol;
                        $yml .= $this->createTag($this->shop);
                        $yml .= '<currencies>' . $this->eol;
                        foreach ($this->currencies as $currency) {
                                $yml .= $this->getElement($currency, 'currency');
                        }
                        $yml .= '</currencies>' . $this->eol;
                        $yml .= '<categories>' . $this->eol;
                        foreach ($this->categories as $category) {
                                $category_name = $category['name'];
                                
                                if(isset($category['attributes'])){
                                    
                                    $category = array_merge($category,$category['attributes']);
                                    unset($category['attributes']);
                                    
                                }
                                
                                unset($category['name'], $category['export']);
                                $yml .= $this->getElement($category, 'category', $category_name);
                        }
                        $yml .= '</categories>' . $this->eol;
                        if($this->delivery_option){
                            $yml .= $this->createTag($this->delivery_option);
                        }
                        $yml .= '<offers>' . $this->eol;
                        
                        $yml_parts_cache = $this->cfiles['yml_parts_cache'].$this->request->get['token'].'-'.  count($xml_parts);
                        
                        $yml = $this->replaceTags($yml);
                        
                        $this->{$this->path_on_model}->writeCache($yml_parts_cache,array(), $yml);
                        
                        $xml_parts[$yml_parts_cache] = $yml_parts_cache;
                        
                        $yml = '';
                        
                        if($this->offers_fwrire['cache_files']){
                            
                            foreach ($this->offers_fwrire['cache_files'] as $cache_file) {
                                
                                $offers = $this->getCache($cache_file);
                                
                                foreach ($offers as $num_offer=>$offer) {
                                    
                                    $rows = $this->createTag($offer['data']);
                                    unset($offer['data']);
                                    if (isset($offer['param'])) {
                                        $rows .= $this->createParam($offer['param']);
                                        unset($offer['param']);
                                    }
                                    $yml .= $this->getElement($offer, 'offer', $rows);
                                    unset($this->offers[$num_offer]);
                                    
                                }
                                
                                if($yml){
                                    
                                    $yml = $this->replaceTags($yml);
                                    
                                    $yml_parts_cache = $this->cfiles['yml_parts_cache'].$this->request->get['token'].'-'.  count($xml_parts);
                                
                                    $this->{$this->path_on_model}->writeCache($yml_parts_cache,array(), $yml);
    
                                    $xml_parts[$yml_parts_cache] = $yml_parts_cache;
    
                                    $yml = '';
                                    
                                }
                                
                            }
                            
                        }
                        
                        $yml .= '</offers>' . $this->eol;
    			    
    		    if(isset($this->general_setting['gifts_result'])){
    			
    			$yml .= $this->general_setting['gifts_result'];
    			
    		    }
    		    
    		    if(isset($this->general_setting['promos_result'])){
    			
    			$yml .= '<promos>' . $this->eol;
    			
    			foreach ($this->general_setting['promos_result'] as $promos_result) {
    			    
    			    $yml .= $promos_result;
    			    
    			}
    			
    			$yml .= '</promos>' . $this->eol;
    			
    		    }
                        
                        $yml .= '</shop>';
                        
                        $yml .= '</yml_catalog>';
                        
                        $yml = $this->replaceTags($yml);
                        
                        $yml_parts_cache = $this->cfiles['yml_parts_cache'].$this->request->get['token'].'-'.  count($xml_parts);
                        
                        $this->{$this->path_on_model}->writeCache($yml_parts_cache,array(), $yml);
                        
                        $xml_parts[$yml_parts_cache] = $yml_parts_cache;
                        
                        $rootPath = realpath(DIR_APPLICATION . '..'); 
    
                        if($xml_parts && isset($this->general_setting[$this->parse_yml['export_filename']]) && $this->general_setting[$this->parse_yml['export_filename']]){
    
                            $file_name_and_path = $rootPath.'/'.$this->general_setting['filename_export'].'.xml';
                            
                            if(file_exists($file_name_and_path)){
                                
                                $handle = fopen($file_name_and_path, 'w+');
    
                                fclose($handle);
                                
                            }
    
                            foreach ($xml_parts as $xml_part) {
    
                                if(file_exists(DIR_CACHE.$xml_part) && is_writable($file_name_and_path)){
    
                                    $cache_offers = file_get_contents(DIR_CACHE.$xml_part);
    
                                    $handle = fopen($file_name_and_path, 'a');
    
                                    fwrite($handle, $cache_offers . $this->eol);
    
                                    fclose($handle);
    
                                }else{
    
                                    $this->sendErrorXML(array('Файл не может быть записан. Выключите "Оптимизацию при формировании итогового YML (запись файла частями). Если is_writable = 0 (см. далее), то установите права на запись 755 для папки: '.$this->eol. dirname($file_name_and_path).$this->eol.' is_writable: '.is_writable($file_name_and_path).', cache file_exists: '.file_exists(DIR_CACHE.$xml_part)));
    
                                }
    
                            }
    
                        }
                        
                    }
                    
                    if(file_exists($file_name_and_path) && is_writable($file_name_and_path)){
                            
                        $result = file_get_contents($file_name_and_path);
    
                    }else{
                        
                        $this->sendErrorXML(array('Файл не записан, is_writable: '.is_writable($file_name_and_path).', cache file_exists: '.file_exists(DIR_CACHE.$xml_part)));
                        
                    }
                    
                    return $result;
                    
                }elseif(isset($this->request->get['fb'])){
                    
                    $fb  = '<?xml version="1.0"?>' . $this->eol;
    		$fb .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">' . $this->eol;
                    $fb .= '<title>'.$this->shop['name'].'</title>'. $this->eol;
    		$fb .= $this->createFBTag(array('link'=>''),array('link'=>array('rel'=>'self','href'=>$this->shop['url'])));
                    
    		foreach ($this->offers as $num_offer=>$offer) {
                        
                            if(isset($offer['id']) && $offer['id'] && isset($offer['available']) && $offer['available'] && isset($offer['data']['description']) && $offer['data']['description'] && isset($offer['data']['vendor']) && $offer['data']['vendor'] && isset($offer['data']['picture']) && $offer['data']['picture'] && isset($offer['data']['price']) && $offer['data']['price'] && isset($offer['data']['name']) && $offer['data']['name']){
                                
                                $fb_data = array();
                                
                                $fb_data['id'] = $offer['id'];
                                
                                $fb_data['availability'] = 'out of stock';
                                
                                if($offer['available']=='true'){
                                    
                                    $fb_data['availability'] = 'in stock';
                                    
                                }
                                
                                $fb_data['condition'] = $offer['data']['condition'];
                                
                                $fb_data['description'] = $offer['data']['description'];
                                
                                foreach ($offer['data']['picture'] as $picture) {
                                    
                                    if(!isset($fb_data['image_link'])){
                                        
                                        $fb_data['image_link'] = $picture;
                                        
                                    }else{
                                        
                                        $fb_data['additional_image_link'] = $picture;
                                        
                                    }
                                    
                                }
                                
                                if(isset($offer['data']['google_product_category'])){
    
                                    $fb_data['google_product_category'] = $offer['data']['google_product_category'];
    
                                }else{
    
                                    unset($fb_data['google_product_category']);
    
                                }
                                
                                $fb_data['link'] = $offer['data']['url'];
                                
                                $fb_data['title'] = $offer['data']['name'];
                                
                                $fb_data['price'] = number_format(round($offer['data']['price'],2),2, '.', '').' '.$offer['data']['currencyId'];
                                
                                $fb_data['brand'] = $offer['data']['vendor'];
                                
                                for($i=0;$i<5;$i++){
                                    
                                    if(isset($offer['data']['custom_label_'.$i])){
                                        
                                        $fb_data['custom_label_'.$i] = $offer['data']['custom_label_'.$i];
                                        
                                    }
                                    
                                }
                                
                                $rows = $this->createFBTag($fb_data,array(),'g:');
                                
                                $fb .= $this->getFBElement(array(), 'entry', $rows);
                                
                            }
                            
                            unset($this->offers[$num_offer]);
                            
    		}
    		$fb .= '</feed>';
                    
                    $fb = $this->replaceTags($fb);
                    
                    $rootPath = realpath(DIR_APPLICATION . '..'); 
                    
                    if(isset($this->general_setting['fb_filename_export']) && $this->general_setting['fb_filename_export']){
                        
                        $file_name_and_path = $rootPath.'/'.$this->general_setting['fb_filename_export'].'.xml';
                        
                        $dirname = dirname($file_name_and_path);
    
                        $handle = FALSE;
    
                        if($file_name_and_path && !file_exists($file_name_and_path)){
    
                            if(!is_dir($dirname)){
    
                                mkdir($dirname,0777,TRUE);
    
                            }
    
                            $handle = fopen($file_name_and_path, "w");
    
                        }elseif(file_exists($file_name_and_path)){
    
                            $handle = fopen($file_name_and_path, "w");
    
                        }
    
                        if($handle){
                            fwrite($handle, $fb);
                            fclose($handle);
                        }
                        
                    }
    		return $fb;
                    
                }else{
                    
                    $yml  = '<?xml version="1.0" encoding="UTF-8"?>' . $this->eol;
    		$yml .= '<!DOCTYPE yml_catalog SYSTEM "shops.dtd">' . $this->eol;
    		$yml .= '<yml_catalog date="' . date('Y-m-d H:i') . '">' . $this->eol;
    		$yml .= '<shop>' . $this->eol;
    		$yml .= $this->createTag($this->shop);
    		$yml .= '<currencies>' . $this->eol;
    		foreach ($this->currencies as $currency) {
    			$yml .= $this->getElement($currency, 'currency');
    		}
    		$yml .= '</currencies>' . $this->eol;
    		$yml .= '<categories>' . $this->eol;
    		foreach ($this->categories as $category) {
    			$category_name = $category['name'];
    			
    			if(isset($category['attributes'])){
    
    			    $category = array_merge($category,$category['attributes']);
    			    unset($category['attributes']);
    
    			}
    			
    			unset($category['name'], $category['export']);
    			$yml .= $this->getElement($category, 'category', $category_name);
    		}
    		$yml .= '</categories>' . $this->eol;
                    if($this->delivery_option){
                        $yml .= $this->createTag($this->delivery_option);
                    }
    		$yml .= '<offers>' . $this->eol;
    		foreach ($this->offers as $num_offer=>$offer) {
    			$rows = $this->createTag($offer['data']);
    			unset($offer['data']);
    			if (isset($offer['param'])) {
                                $rows .= $this->createParam($offer['param']);
                                unset($offer['param']);
    			}
    			$yml .= $this->getElement($offer, 'offer', $rows);
                            unset($this->offers[$num_offer]);
    		}
    		$yml .= '</offers>' . $this->eol;
    		$yml .= '</shop>';
    		$yml .= '</yml_catalog>';
                    
                    $yml = $this->replaceTags($yml);
                    
                    //пишем файл
                    $rootPath = realpath(DIR_APPLICATION . '..'); 
                    
                    if(isset($this->general_setting[$this->parse_yml['export_filename']]) && $this->general_setting[$this->parse_yml['export_filename']]){
                        
                        
                        $file_name_and_path = $rootPath.'/'.$this->general_setting['filename_export'].'.xml';
                    
                        $dirname = dirname($file_name_and_path);
    
                        $handle = FALSE;
    
                        if($file_name_and_path && !file_exists($file_name_and_path)){
    
                            if(!is_dir($dirname)){
    
                                mkdir($dirname,0777,TRUE);
    
                            }
    
                            $handle = fopen($file_name_and_path, "w");
    
                        }elseif(file_exists($file_name_and_path)){
    
                            $handle = fopen($file_name_and_path, "w");
    
                        }
    
                        if($handle){
                            fwrite($handle, $yml);
                            fclose($handle);
                        }
                        
                    }
    		return $yml;
                    
                }
    	}
            
            
            public function replaceTags($string){
                
                if(isset($this->general_setting['filter_and_raplace_tags']['replace_tags']) && $this->general_setting['filter_and_raplace_tags']['replace_tags']!==''){
                    
                    $replace_tags_parts = explode('|', $this->general_setting['filter_and_raplace_tags']['replace_tags']);
                    
                    $find_tags = array();
                    
                    $replace_tags = array();
                    
                    $num_replace = 0;
                    
                    foreach ($replace_tags_parts as $replace_tags_part) {
                        
                        $replace_tags_this = explode('---', $replace_tags_part);
                        
                        if(isset($replace_tags_this[1]) && $replace_tags_this[1] && $replace_tags_this[0]){
                            
                            $find_tags[] = '<'.$replace_tags_this[0].' ';
                            
                            $replace_tags[] = '<'.$replace_tags_this[1].' ';
                            
                            $find_tags[] = '</'.$replace_tags_this[0].'>';
                            
                            $replace_tags[] = '</'.$replace_tags_this[1].'>';
                            
                            $find_tags[] = '<'.$replace_tags_this[0].'>';
                            
                            $replace_tags[] = '<'.$replace_tags_this[1].'>';
                            
                        }
                        
                    }
                    
                    if($replace_tags){
                        
                        $string = str_replace($find_tags, $replace_tags, $string);
                        
                    }
                    
                }
                
                return $string;
                
            }
            
            private function getFBElement($attributes, $element_name, $element_value = '') {
                $retval = '<'.$element_name.' ';
                foreach ($attributes as $key => $value) {
                    $retval .= $key .'="'.$value.'" ';
                }
                $retval .= $element_value ? '>' .$this->eol. $element_value.'</'.$element_name.'>' : '/>';
                $retval .= $this->eol;
                return $retval;
    	}
            
    	private function createFBTag($tags,$attributes=array(),$tag_add='') {
                
                $retval = '';
                foreach ($tags as $key => $value) {
                    
                    $attribute = '';
                    
                    if(isset($attributes[$key])){
                        
                        foreach ($attributes[$key] as $attribute_name => $attribute_value) {
                            
                            $attribute .= ' '.  $attribute_name.'="'.  $attribute_value.'"';
                            
                        }
                        
                    }
                    
                    if($tag_add){
                        $key = $tag_add.$key;
                    }
                    
                    
                    if(!is_array($value) && $value){
                        $retval .= '<'.$key.$attribute.'>'.$value.'</'.$key .'>'.$this->eol;
                    }elseif (is_array($value) && $key == $tag_add.'shipping') {
                        $retval .= $this->createDeliveryOptions($value); 
                    }elseif (is_array($value)) {
                        foreach ($value as $key_two=>$value_two) {
                            $retval .= '<'.$key.$attribute.'>'.$value_two.'</'.$key.'>' . $this->eol;
                        }
                    }elseif(!is_array($value) && !$value){
                        $retval .= '<'.$key.$attribute.'/>'. $this->eol;
                    }
                }
                return $retval;
    	}
            
            public function checklicense() {
                //asju
                eval(base64_decode('JGdlbmVyYWxfc2V0dGluZyA9ICR0aGlzLT5jb25maWctPmdldCgnb2NleHRfZmVlZF9nZW5lcmF0b3JfeWFtYXJrZXRfZ2VuZXJhbF9zZXR0aW5nJyk7DQogICAgICAgICAgICBpZihpc3NldCgkZ2VuZXJhbF9zZXR0aW5nWyd1c2VyX2tleSddKSAmJiBpc3NldCgkZ2VuZXJhbF9zZXR0aW5nWyd1c2VyX2VtYWlsJ10pKXsNCiAgICAgICAgICAgICAgICAkdGhpcy0+bF9kYXRhWyd1J10gPSAkZ2VuZXJhbF9zZXR0aW5nWyd1c2VyX2tleSddOw0KICAgICAgICAgICAgICAgICR0aGlzLT5sX2RhdGFbJ2UnXSA9ICRnZW5lcmFsX3NldHRpbmdbJ3VzZXJfZW1haWwnXTsNCiAgICAgICAgICAgIH1lbHNlew0KICAgICAgICAgICAgICAgICR0aGlzLT5sX2RhdGFbJ3UnXSA9IG1kNSh0aW1lKCkpOw0KICAgICAgICAgICAgICAgICR0aGlzLT5sX2RhdGFbJ2UnXSA9IHRpbWUoKTsNCiAgICAgICAgICAgIH0='));//OCext.com: do not delete this line | не удаляйте эту строку
                //indjds
                eval(base64_decode('aWYoZmlsZV9leGlzdHMoJF9TRVJWRVJbJ0RPQ1VNRU5UX1JPT1QnXS4nL3N5c3RlbS9saWJyYXJ5L3ZlbmRvci9vY2V4dC9vY2V4dF9mZWVkX2dlbmVyYXRvcl95YW1hcmtldF9saWNlbnNlLnBocCcpKXsNCiAgICAgICAgICAgICAgICBpbmNsdWRlX29uY2UgJF9TRVJWRVJbJ0RPQ1VNRU5UX1JPT1QnXS4nL3N5c3RlbS9saWJyYXJ5L3ZlbmRvci9vY2V4dC9vY2V4dF9mZWVkX2dlbmVyYXRvcl95YW1hcmtldF9saWNlbnNlLnBocCc7DQogICAgICAgICAgICB9'));//OCext.com: do not delete this line | не удаляйте эту строку
            }
    
    	private function getElement($attributes, $element_name, $element_value = '') {
                $retval = '<'.$element_name.' ';
                foreach ($attributes as $key => $value) {
                    $retval .= $key .'="'.$value.'" ';
                }
                $retval .= $element_value ? '>' .$element_value.'</'.$element_name.'>' : '/>'.$this->eol;
                return $retval;
    	}
    	
    	private function getXMLFromArray($value,$result) {
    	    
    	    $result = '';
    	    
    	    if(is_array($value)){
    		
    		foreach ($value as $tag_name => $value2) {
    		    
    		    foreach ($attributes as $key => $value) {
    			
    			$result .= $key .'="'.$value.'" ';
    			
    		    }
    		    
    		}
    		
    	    }
    	    
    	    
    	    
                $retval = '<'.$element_name.' ';
                foreach ($attributes as $key => $value) {
                    $retval .= $key .'="'.$value.'" ';
                }
                $retval .= $element_value ? '>' .$element_value.'</'.$element_name.'>' : '/>'.$this->eol;
                return $retval;
    	}
            
    	private function createTag($tags) {
                $retval = '';
                foreach ($tags as $key => $value) {
                    
                    if(!is_array($value) && $value!==''){
                        
                        $key_parts = explode(' ', $key);
                        
                        $key_attr = '';
                        
                        if(isset($key_parts[1])){
                            
                            $key = trim($key_parts[0]);
                            
                            for($kp=1;$kp<=count($key_parts);$kp++){
                                
                                if(isset($key_parts[$kp])){
                                    
                                    $key_parts[$kp] = trim($key_parts[$kp]);
                            
                                    if($key_parts[$kp]){
                                        $key_attr .= ' '.  str_replace("&quot;", '"', $key_parts[$kp]);
                                    }
                                    
                                }
                                
                            }
                            
                        }
                        
                        $retval .= '<'.$key.$key_attr.'>'.$value.'</'.$key .'>'.$this->eol;
                        
                    }elseif (is_array($value) && $key == 'delivery-options') {
                        $retval .= $this->createDeliveryOptions($value); 
                    }elseif (is_array($value) && $key == 'age') {
                        $retval .= '<'.$key.' unit="'.$value['unit'].'">'.$value['value'].'</'.$key.'>' . $this->eol;
                    }elseif (is_array($value)) {
                        foreach ($value as $key_two=>$value_two) {
                            $retval .= '<'.$key.'>'.$value_two.'</'.$key.'>' . $this->eol;
                        }
                    }elseif (!is_array($value) && $value==='') {
                        
                        $key_parts = explode(' ', $key);
                        
                        $key_attr = '';
                        
                        if(isset($key_parts[1])){
                            
                            $key = trim($key_parts[0]);
                            
                            for($kp=1;$kp<=count($key_parts);$kp++){
                                
                                if(isset($key_parts[$kp])){
                                    
                                    $key_parts[$kp] = trim($key_parts[$kp]);
                            
                                    if($key_parts[$kp]){
                                        $key_attr = ' '.  str_replace("&quot;", '"', $key_parts[$kp]);
                                    }
                                    
                                }
                                
                            }
                            
                        }
                        
                        if($key_attr){
                            $retval .= '<'.$key.$key_attr.'></'.$key.'>'.$this->eol;
                        }
                        
                    }
                }
                return $retval;
    	}
            
    	private function createParam($params) {
                $retval = '';
                foreach ($params as $param) {
                    $retval .= '<param name="'.$this->prepareField($param['name']);
                    if (isset($param['unit'])) {
                            $retval .= '" unit="'.$this->prepareField($param['unit']);
                    }
                    $retval .= '">'.$this->prepareField($param['value']) . '</param>'.$this->eol;
                }
                return $retval;
    	}
            
            private function createDeliveryOptions($delivery_options) {
                $retval = '';
                if($delivery_options){
                    foreach ($delivery_options as $option) {
                        if(isset($option['cost']) && isset($option['days'])){
                            $retval .= '<option cost="' . trim($option['cost']).'" days="'.trim($option['days']).'';
                            if (isset($option['order-before']) && $option['order-before']) {
                                    $retval .= '" order-before="' . trim($option['order-before']);
                                    unset($option['order-before']);
                            }
                            $retval .= '"/>'.$this->eol;
                        }
                    }
                }
                if($retval){
                    $retval = '<delivery-options>'.$this->eol.$retval.'</delivery-options>'.$this->eol;
                }
                
                return $retval;
    	}
            
            public function sendErrorXML($errors) {
                $yml  = '<?xml version="1.0" encoding="UTF-8"?>' . $this->eol;
                $yml .= '<msgs date="' . date('Y-m-d H:i') . '">' . $this->eol;
                foreach ($errors as $error) {
                    $yml .= $this->createTag(array('msg'=>$error)) . $this->eol;
                }
                $yml .= '</msgs>';
                $this->response->addHeader('Content-Type: application/xml');
                $this->response->setOutput($yml);
            }
    }
    ?>

     

    Модель:

    Спойлер
    <?php
    class ModelExtensionFeedOcextFeedGeneratorYaMarket extends Model {
        
        public function __construct($registry) {
            
            $this->registry = $registry;
            $this->setSettingVersion();
            
        }
        
        public function setSettingVersion(){
            
            require_once(DIR_SYSTEM . 'library/vendor/ocext/multiyml_setting_version.php');
            $this->registry->set('setting_version',new multiYMLSettingVersion($this->registry,  $this->path_oc_version, $this->language,$this->load,$this->db));
            
        }
    
        public function getFilterData($key,$filter_data_group_id) {
            
            $sql = "SELECT * FROM `" . DB_PREFIX . "ocext_feed_generator_yamarket_filter_data` WHERE `key` = '".$key."' AND filter_data_group_id = '".$filter_data_group_id."' ";
            $query = $this->db->query($sql);
            $result = array();
            if($query->row){
                $result = json_decode($query->row['filter_data'], true);
            }
            
            return $result;
        }
        
        private function replaceOperator($operator){
    
            $find = array('&lt;','≤','=','≥','&gt;','≠');
    
            $replace = array('<','<=','=','>=','>','!=');
    
            $operator = str_replace($find, $replace, $operator);
    
            return $operator;
    
        }
        
        public function getStatusByWhere($product_data_where,$product) {
    
            $result = FALSE;
                
            if($product_data_where['product_field'] && $product_data_where['operator']){
    
                $operator = $this->replaceOperator($product_data_where['operator']);
    
                $product_field = $product_data_where['product_field'];
    
                $value = trim($product_data_where['value']);
    
                if($operator && $product_field){
    
                    if($operator=='like' && isset($product[$product_field]) && strstr($product[$product_field], $value)){
    
                        $result = TRUE;
    
                    }elseif($operator=='not_like' && isset($product[$product_field]) && !strstr($product[$product_field], $value)){
    
                        $result = TRUE;
    
                    }else{
    
                        if($operator=='<' && isset($product[$product_field]) && $product[$product_field] < $value){
    
                            $result = TRUE;
    
                        }elseif($operator=='<=' && isset($product[$product_field]) && $product[$product_field] <= $value){
    
                            $result = TRUE;
    
                        }elseif($operator=='=' && isset($product[$product_field]) && $product[$product_field] == $value){
    
                            $result = TRUE;
    
                        }elseif($operator=='>=' && isset($product[$product_field]) && $product[$product_field] >= $value){
    
                            $result = TRUE;
    
                        }elseif($operator=='>' && isset($product[$product_field]) && $product[$product_field] > $value){
    
                            $result = TRUE;
    
                        }elseif($operator=='!=' && isset($product[$product_field]) && $product[$product_field] != $value){
    
                            $result = TRUE;
    
                        }
    
                    }
    
                }
    
            }
            
            return $result;
    
        }
        
        public function resizeImage($file,$w,$h,$d,$HTTP_SERVER) {
                
            $image = $this->setting_version->resizeImage($file,$w,$h,$d,  $HTTP_SERVER);
    
            return $image;
        }
        
        public function getWhere($product_data) {
    
            $where = array();
            
            foreach ($product_data as $product_data_where){
    
                if($product_data_where['product_field'] && $product_data_where['operator']){
    
                    $operator = $this->replaceOperator($product_data_where['operator']);
    
                    $product_field = $product_data_where['product_field'];
    
                    $value = trim($product_data_where['value']);
                    
                    $sql_operator = $product_data_where['logic'];
    
                    if($operator && $product_field){
                        
                        $sql = '';
    
                        if($operator=='like_right'){
    
                            $sql = ' p.'.$product_field.' LIKE  "%'.$this->db->escape($value).'" ';
    
                        }elseif($operator=='like_left'){
    
                            $sql = ' p.'.$product_field.' LIKE  "'.$this->db->escape($value).'%" ';
    
                        }elseif($operator=='like'){
    
                            $sql = ' p.'.$product_field.' LIKE  "%'.$this->db->escape($value).'%" ';
    
                        }elseif($operator=='not_like_right'){
    
                            $sql = ' p.'.$product_field.' NOT LIKE  "%'.$this->db->escape($value).'" ';
    
                        }elseif($operator=='not_like_left'){
    
                            $sql = ' p.'.$product_field.' NOT LIKE  "'.$this->db->escape($value).'%" ';
    
                        }elseif($operator=='not_like'){
    
                            $sql = ' p.'.$product_field.' NOT LIKE  "%'.$this->db->escape($value).'%" ';
    
                        }else{
    
                            $sql = ' p.'.$product_field.' '.$operator.' "'.$this->db->escape($value).'" ';
    
                        }
    
                        $where[][$sql_operator] = $sql;
                        
                    }
                    
                }
    
            }
            
            $where_result = '';
            
            if($where){
                
                $count = 1;
                
                foreach ($where as $sql_where) {
                    
                    $sql_operator = key($sql_where);
                    
                    $sql_where = current($sql_where);
                    
                    if($count<count($where)){
                        
                        $where_result .= $sql_where.$sql_operator;
                        
                    }else{
                        
                        $where_result .= $sql_where;
                        
                    }
                    
                    $count++;
                    
                }
                
            }
            
            return $where_result;
    
        }
        
        
        
        
        
        public function getSettings($setting_type=0,$setting_id=FALSE,$setting_product_id=0) {
            
            $sql = "SELECT * FROM `" .   DB_PREFIX   . 'ocext_feed_generator_yamarket_setting` ';
            
            $where = array();
            
            if($setting_type){
                $where[] = " setting_type = '".$setting_type."' ";
            }
            //$setting_id===0 - иначе придут все настройки, когда вызван новый фид, т.к. на $where[] = " setting_type = '".$setting_type."' "; много результатов
            if($setting_id || $setting_id===0){
                $where[] = " setting_id = ".$setting_id." ";
            }
            
            if($setting_product_id){
                
                $where[] = " setting LIKE '%\"setting_product_id\":\"".$setting_product_id."\"%' "; //"setting_product_id":"0"
                
            }
            
            if($where){
                $sql .= 'WHERE '.implode(' AND ', $where);
            }
            
            $result = $this->db->query($sql);
            
            return $result->rows;
            
        }
        
        public function getMemoryLimit($level=0.3){
            
            $memory_limit = ini_get('memory_limit');
            
            if(strstr($memory_limit, 'M')){
    			
    			$memory_limit = (int)str_replace('M','',$memory_limit);
                
                $memory_limit *= (1024*1024*$level); 
                
            }elseif(strstr($memory_limit, 'G')){
    			
    			$memory_limit = (int)str_replace('G','',$memory_limit);
                
                $memory_limit *= (1024*1024*1024*$level); 
                
            }else{
    			
                $memory_limit = (int)$memory_limit;
                
                $memory_limit *= $level;
                
            }
            
            return $memory_limit;
            
        }
        
        public function getProductCategories($product_id) {
            
            $mcat = '';
            
            if($this->checkColumnTable('product_to_category', 'main_category')){
                
                $mcat .= " p2c.main_category, ";
                
            }
            
            $result = array('main_category'=>0,'category_ids'=>array());
            
            $categories = $this->db->query("SELECT ".$mcat." p2c.category_id FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "category ctg ON (p2c.category_id = ctg.category_id)  WHERE p2c.product_id = '" . (int)$product_id."' AND ctg.status = '1' ");
            
            if($categories->rows){
                
                foreach ($categories->rows as $category) {
                    
                    if(isset($category['main_category']) && $category['main_category']){
                        
                        $result['main_category'] = $category['category_id'];
                        
                    }else{
                        
                        $result['category_ids'][$category['category_id']] = $category['category_id'];
                        
                    }
                    
                }
                
            }
            
            return $result;
            
        }
        
        private function checkColumnTable($table,$column) {
    
            if($this->showTable($table, DB_PREFIX)){
                
                $check = $this->db->query(" SHOW columns FROM `".DB_PREFIX.$table."` WHERE `Field` = '".$column."'  ");
                
                if(!$check->num_rows){
                    return FALSE;
                }else{
                    return TRUE;
                }
                
            }else{
                
                return FALSE;
                
            }
    
        }
    
        
        public function getCategoriesAndProducts($ym_categories,$ym_manufacturers,$filter_data_group_id,$content_language_id,$general_setting) {
            
                $cache_status = 0;
                
                $memory_limit = $this->getMemoryLimit();
                
            if(isset($general_setting['yml_cache_enable']) && $general_setting['yml_cache_enable']){
                
                $cache_status = 1;
                
                $memory_limit = $this->getMemoryLimit((float)$general_setting['yml_cache_level']);
                
            }
            
            $cache_file_name = 'yml_cache_'.$this->request->get['token'];
            
            $add_settings = array();
            
            $p2c = '';
            $ym_attributes = array();
            $all_yml_export_ocext_ym_filter_data_attributes = $this->getFilterData('ocext_feed_generator_yamarket_ym_filter_attributes',$filter_data_group_id,$content_language_id);
            if($all_yml_export_ocext_ym_filter_data_attributes){
                $ym_attributes = $all_yml_export_ocext_ym_filter_data_attributes;
            }
            $ym_options = array();
            $all_yml_export_ocext_ym_filter_data_options = $this->getFilterData('ocext_feed_generator_yamarket_ym_filter_options',$filter_data_group_id,$content_language_id);
            if($all_yml_export_ocext_ym_filter_data_options){
                $ym_options = $all_yml_export_ocext_ym_filter_data_options;
            }
            
            $delivery_option_by_manufacturer = $this->getFilterData('ocext_feed_generator_yamarket_ym_filter_delivery_option_by_manufacturer',$filter_data_group_id,$content_language_id);
    	
    	$mapping_market_place_categories = $this->getFilterData('ocext_feed_generator_yamarket_ym_filter_mapping_market_place_categories',$filter_data_group_id,$content_language_id);
            
    	if($ym_categories){
                $sql_cats = array();
                foreach ($ym_categories as $category_id => $ym_category) {
                    $sql_cats[] = " p2c.category_id = '".(int)$category_id."' ";
                }
                if($sql_cats){
                    $p2c = ' AND ( '.implode(' OR ', $sql_cats).' ) ';
                }
            }
            /*$mcat = '';
            
            if($this->checkColumnTable('product_to_category', 'main_category')){
                
                $mcat .= " AND p2c.main_category = '1' ";
                
            }
            
            $sql = "SELECT p.*, pd.name, pd.*, m.name AS manufacturer, p2c.category_id, ps.price AS special_price, pds.price AS discount_special_price FROM " . DB_PREFIX . "product p JOIN " . DB_PREFIX . "product_to_category AS p2c ON (p.product_id = p2c.product_id) LEFT JOIN " . DB_PREFIX . "category ctg ON (p2c.category_id = ctg.category_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ps.date_start < NOW() AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW()) LEFT JOIN " . DB_PREFIX . "product_discount pds ON (p.product_id = pds.product_id)  AND pds.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND pds.date_start < NOW() AND (pds.date_end = '0000-00-00' OR pds.date_end > NOW())   WHERE p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND pd.language_id = '" . (int)$content_language_id . "' AND p.date_available <= NOW() AND ctg.status = '1' AND p.status = '1' ".$mcat.$p2c." GROUP BY p.product_id";*/
            
            $sql_columns = '';
            
            $columns_where = $this->getFilterData('ocext_feed_generator_yamarket_ym_filter_columns',$filter_data_group_id,$content_language_id);
            
            if(isset($columns_where['product'])){
                
                $sql_columns = $this->getWhere($columns_where['product']);
                
                if($sql_columns){
                    
                    $sql_columns = " AND ( ".$sql_columns." ) ";
                    
                }
                
            }
            
            $sql = "SELECT p.*, pd.name, pd.*, m.name AS manufacturer, p2c.category_id, ps.price AS special_price, pds.price AS discount_special_price FROM " . DB_PREFIX . "product p JOIN " . DB_PREFIX . "product_to_category AS p2c ON (p.product_id = p2c.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ps.date_start <= NOW() AND ( ps.date_end = '0000-00-00' OR ps.date_end >= NOW() ) AND ps.priority in ( SELECT min(ps.priority) ) LEFT JOIN " . DB_PREFIX . "product_discount pds ON (p.product_id = pds.product_id)  AND pds.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND pds.date_start < NOW() AND (pds.date_end = '0000-00-00' OR pds.date_end > NOW())   WHERE p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND pd.language_id = '" . (int)$content_language_id . "' AND p.date_available <= NOW() AND p.status = '1' ".$sql_columns.$p2c." GROUP BY p.product_id";
            $count_sql = "SELECT p.status FROM " . DB_PREFIX . "product p JOIN " . DB_PREFIX . "product_to_category AS p2c ON (p.product_id = p2c.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ps.date_start <= NOW() AND ( ps.date_end = '0000-00-00' OR ps.date_end >= NOW() ) AND ps.priority in ( SELECT min(ps.priority) ) LEFT JOIN " . DB_PREFIX . "product_discount pds ON (p.product_id = pds.product_id)  AND pds.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND pds.date_start < NOW() AND (pds.date_end = '0000-00-00' OR pds.date_end > NOW())   WHERE p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND pd.language_id = '" . (int)$content_language_id . "' AND p.date_available <= NOW() AND p.status = '1' ".$sql_columns.$p2c." GROUP BY p.product_id";
            if($this->config->get('ocext_feed_generator_yamarket_ym_filter_prioritet')){
                $prioritet = $this->config->get('ocext_feed_generator_yamarket_ym_filter_prioritet');
            }else{
                $prioritet['categories'] = 1;
                $prioritet['manufacturers'] = 2;
            }
            
            $parts_select = array($sql);
            
            if(isset($general_setting['optimization_feed_limit_products'])){
                
                $parts_select = $this->setting_version->getPartsSelect($sql,$count_sql,$general_setting['optimization_feed_limit_products'],$parts_select);
                
            }
            
            $ym_categories_whis_categories = $this->getYmCategoriesFromDb();
            $result['categories'] = array();
            $result['cache'] = array();
            $result['offers'] = array();
    	$result['settings'] = array();
    	$result['mapping_market_place_categories'] = $this->getMappingMarketPlaceCategories($mapping_market_place_categories);
    	
            $products_filtered = array();
            
            foreach ($parts_select as $sql) {
                
                $query = $this->db->query($sql);
                
                $result['log_errors'][] =  'total offers selected to db: '.$query->num_rows;
    
                if($query->rows){
    
                    foreach ($query->rows as $i_product => $product) {
    
                        if($ym_categories){
                            foreach ($ym_categories as $category_id => $ym_category) {
                                if($category_id==$product['category_id'] && (!$ym_manufacturers || ($ym_manufacturers && isset($ym_manufacturers[$product['manufacturer_id']])))){
                                    $products_filtered[$product['product_id']] = $product;
                                    if(isset($ym_manufacturers[$product['manufacturer_id']]['setting_id']) && $ym_manufacturers[$product['manufacturer_id']]['setting_id']){
                                        $products_filtered[$product['product_id']]['manufacturer_setting_id'] = $ym_manufacturers[$product['manufacturer_id']]['setting_id'];
                                    }else{
                                        $products_filtered[$product['product_id']]['manufacturer_setting_id'] = 0;
                                    }
                                    if(isset($ym_categories[$product['category_id']]['setting_id']) && $ym_categories[$product['category_id']]['setting_id']){
                                        $products_filtered[$product['product_id']]['category_setting_id'] = $ym_categories[$product['category_id']]['setting_id'];
                                    }else{
                                        $products_filtered[$product['product_id']]['category_setting_id'] = 0;
                                    }
                                }
                            }
                        }elseif ($ym_manufacturers) {
                            foreach ($ym_manufacturers as $manufacturer_id => $ym_manufacturer) {
                                if($manufacturer_id==$product['manufacturer_id']  && (!$ym_categories || ($ym_categories && isset($ym_categories[$product['category_id']]))) ){
    
                                    $products_filtered[$product['product_id']] = $product;
                                    if(isset($ym_manufacturers[$product['manufacturer_id']]['setting_id']) && $ym_manufacturers[$product['manufacturer_id']]['setting_id']){
                                        $products_filtered[$product['product_id']]['manufacturer_setting_id'] = $ym_manufacturers[$product['manufacturer_id']]['setting_id'];
                                    }else{
                                        $products_filtered[$product['product_id']]['manufacturer_setting_id'] = 0;
                                    }
                                    if(isset($ym_categories[$product['category_id']]['setting_id']) && $ym_categories[$product['category_id']]['setting_id']){
                                        $products_filtered[$product['product_id']]['category_setting_id'] = $ym_categories[$product['category_id']]['setting_id'];
                                    }else{
                                        $products_filtered[$product['product_id']]['category_setting_id'] = 0;
                                    }
    
                                }
                            }
                        }
    
                        unset($query->rows[$i_product]);
    
                    }
    
                    $result['log_errors'][] =  'total offers after cat/manuf filter: '.count($products_filtered);
    
                    if($products_filtered){
    
                        foreach ($products_filtered as $i_product => $product) {
    
                            $memory_get_usage = memory_get_usage();
    
                            $set = array();
                            $setting = array();
                            if($prioritet['manufacturers']<$prioritet['categories']){
    
                                $set[$product['manufacturer_setting_id']] = $product['manufacturer_setting_id'];
    
                            }else{
    
                                $set[$product['category_setting_id']] = $product['category_setting_id'];
    
                            }
    
                            if($set){
                                $setting_row = $this->getSettings(0, end($set));
                                if($setting_row){
                                    $setting = json_decode($setting_row[0]['setting'],TRUE);
    				$setting['setting_id'] = $setting_row[0]['setting_id'];
                                }
                                if(!isset($setting['status']) || !$setting['status']){
                                    $setting = array();
                                }
                            }
    
                            //получаем настройку продукта, если есть и меняем на неё шаблон продукта
                            $product_setting = $this->getSettings('product_setting', FALSE, $product['product_id']);
                            if($product_setting){
                                $set = array();
                                $set[$product_setting[0]['setting_id']] = $product_setting[0]['setting_id'];
                                $setting_update = json_decode($product_setting[0]['setting'],TRUE);
    
                                //если выключен и нет более верхнего шаблона, то обнуляем шаблон, иначе делаем более верхний
                                if(!$setting_update['status'] && !$setting){
                                    $setting = array();
                                }elseif($setting_update['status']){
                                    $setting = $setting_update;
                                }
                            }
    
                            $dis_product_ids = array();
    
                            if(isset($setting['dis_product_ids']) && $setting['dis_product_ids']){
    
                                $dis_product_ids_ids = explode(',', $setting['dis_product_ids']);
    
                                foreach ($dis_product_ids_ids as $dis_product_ids_id) {
    
                                    $dis_product_ids_id = trim((int)$dis_product_ids_id);
    
                                    $dis_product_ids[$dis_product_ids_id] = $dis_product_ids_id;
    
                                }
    
                            }
    
                            $enb_product_ids = array();
    
                            if(isset($setting['enb_product_ids']) && $setting['enb_product_ids']){
    
                                $enb_product_ids_ids = explode(',', $setting['enb_product_ids']);
    
                                foreach ($enb_product_ids_ids as $enb_product_ids_id) {
    
                                    $enb_product_ids_id = trim((int)$enb_product_ids_id);
    
                                    $enb_product_ids[$enb_product_ids_id] = $enb_product_ids_id;
    
                                }
    
                            }
    
                            if(isset($dis_product_ids[$product['product_id']])){
    
                                $set = array();
    
                            }
    
                            if($enb_product_ids && !isset($enb_product_ids[$product['product_id']])){
    
                                $set = array();
    
                            }
    
                            if($set){
                                
                                if(isset($setting['add_ordering_to_category']) && $setting['add_ordering_to_category']){
                                    
                                    $add_settings['add_ordering_to_category'] = $setting['add_ordering_to_category'];
                                    
                                }
                                
                                if(isset($setting['add_url_to_category']) && $setting['add_url_to_category']){
                                    
                                    $add_settings['add_url_to_category'] = $setting['add_url_to_category'];
                                    
                                }
                                
                                $result['offers'][$product['product_id']] = $product;
                                //добавлемя набор параметров по категории, если нет - нулевой шаблон
                                $result['offers'][$product['product_id']]['setting_id'] = $set;
                                $result['offers'][$product['product_id']]['ym_attributes'] = $this->getProductAttributes($product['product_id'], $ym_attributes,$content_language_id);
                                $result['offers'][$product['product_id']]['all_attributes'] = $this->getProductAttributes($product['product_id'],array(),$content_language_id);
                                $result['offers'][$product['product_id']]['ym_options'] = $this->getProductOptions($product['product_id'], $ym_options,$content_language_id);
                                $result['offers'][$product['product_id']]['all_options'] = $this->getProductOptions($product['product_id'],array(),$content_language_id);
                                $result['offers'][$product['product_id']]['images'] = $this->getProductImages($product['product_id']);
                                $result['offers'][$product['product_id']]['rec'] = $this->getProductRelated($product['product_id']);
                                $result['offers'][$product['product_id']]['product_to_category'] = $this->getProductCategories($product['product_id']);
                                $result['offers'][$product['product_id']]['option_url_param'] = '';
                                $result['offers'][$product['product_id']]['product_id_by_option_id'] = '';
                                $product_spec_or_disc_prices = $this->getSpecialAndDiscontPrices($product['product_id']);
                                $result['offers'][$product['product_id']]['discount_special_price'] = $product_spec_or_disc_prices['discount_special_price'];
                                $result['offers'][$product['product_id']]['special_price'] = $product_spec_or_disc_prices['special_price'];
    
                                if($delivery_option_by_manufacturer && isset( $delivery_option_by_manufacturer[$product['manufacturer_id']] )){
                                    
                                    $result['offers'][$product['product_id']]['delivery_option_by_manufacturer'] = $this->getDeliveryOptionByManufacturer($delivery_option_by_manufacturer[$product['manufacturer_id']],$product);
                                    
                                }
    			    
    			    $set_setting_id = 0;
    			    
    			    if(isset($setting['setting_id'])){
    				
    				$set_setting_id = $setting['setting_id'];
    				
    			    }
    
                                $result['offers'][$product['product_id']]['settings_id'] = $set_setting_id;
    
    			    $result['settings'][$set_setting_id] = $setting;
    
                                $market_category = '';
    
                                if(isset($setting['market_category'])){
    
                                    $market_category = trim($setting['market_category']);
    
                                }
    
                                if(!$market_category && isset($ym_categories_whis_categories[$product['category_id']])){
                                    $result['offers'][$product['product_id']]['market_category'] = $ym_categories_whis_categories[$product['category_id']];
                                }else{
                                    $result['offers'][$product['product_id']]['market_category'] = $market_category;
                                }
                                
                                if(isset($setting['divide_by_options']) && $setting['divide_by_options']['option_value_sku']!=='' && $result['offers'][$product['product_id']]['all_options']){
                                    
                                    $divide_on_options_selected = $setting['divide_on_options_selected'];
                                    
                                    $all_option = $result['offers'][$product['product_id']]['all_options'];
                                    
                                    $option_value_sku = $setting['divide_by_options']['option_value_sku'];
                                    
                                    $sub_offers = array();
                                    
                                    foreach ($divide_on_options_selected as $num_sel_option => $option_selected) {
                                        
                                        if($option_selected){
                                            
                                            $option_id_this = 0;
                                                
                                            if(isset($setting['divide_on_options_option_id'.$num_sel_option]['field']['option_id']) && $setting['divide_on_options_option_id'.$num_sel_option]['field']['option_id']){
    
                                                $option_id_this = $setting['divide_on_options_option_id'.$num_sel_option]['field']['option_id'];
    
                                            }
                                            
                                            foreach ($all_option as $all_option_row) {
                                                
                                                foreach ($all_option_row['product_option_value'] as $product_option_value) {
                                                    
                                                    if(isset($product_option_value[$option_value_sku]) && $option_id_this==$all_option_row['option_id']){
                                                        
                                                        $on_option_prefix = 'OPTION'.$num_sel_option;
                                                        
                                                        $option_value_id_this = $product_option_value['option_value_id'];
    
                                                        if(isset($setting['divide_on_options_prefix'][$num_sel_option]) && $setting['divide_on_options_prefix'][$num_sel_option]!==''){
    
                                                            $on_option_prefix = $setting['divide_on_options_prefix'][$num_sel_option];
    
                                                        }
                                                        
                                                        $new_offer_key = $product['product_id'].'__'.$product_option_value[$option_value_sku];
                                                        
                                                        if(!isset($sub_offers[$new_offer_key])){
                                                            
                                                            $sub_offers[$new_offer_key]['product'] = $result['offers'][$product['product_id']];
                                                            
                                                        }
                                                        
                                                        if(!isset($sub_offers[$new_offer_key]['options'][$option_value_id_this])){
                                                            
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['price'] = '';
                                                            
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['quantity'] = '';
                                                            
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['option_url_param'] = '';
                                                            
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['option_add_model_name'] = '';
                                                            
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['divide_on_option_add_to_name'] = '';
                                                            
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['product_id_by_option_id'] = '';
                                                            
                                                        }
                                                        
                                                        
                                                        if(isset($product_option_value['price']) && isset($product_option_value['price_prefix']) && $product_option_value['price_prefix']=='+'){
    
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['price'] = $product_option_value['price'];
    
                                                        }elseif (isset($product_option_value['price']) && isset($product_option_value['price_prefix']) && $product_option_value['price_prefix']=='-') {
    
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['price'] = (0-$product_option_value['price']);
    
                                                            if($sub_offers[$new_offer_key]['options'][$option_value_id_this]['price']<0){
    
                                                                $sub_offers[$new_offer_key]['options'][$option_value_id_this]['price'] = 0.0;
    
                                                            }
    
                                                        }elseif (isset($product_option_value['price']) && isset($product_option_value['price_prefix']) && $product_option_value['price_prefix']=='=') {
    
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['price'] = $product_option_value['price'];
    
                                                        }
                                                        
                                                        $sub_offers[$new_offer_key]['options'][$option_value_id_this]['option_url_param'] = '&option_id[]='.$product_option_value['product_option_value_id'];
    
                                                        if(isset($setting['divide_on_options_add_to_model'][$num_sel_option]) && $setting['divide_on_options_add_to_model'][$num_sel_option]){
    
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['option_add_model_name'] = $product_option_value['name'];
    
                                                        }
                                                        
                                                        if(isset($setting['divide_on_options_add_to_name'][$num_sel_option]) && $setting['divide_on_options_add_to_name'][$num_sel_option]){
    
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['divide_on_option_add_to_name'] = $product_option_value['name'];
                                                            
                                                        }
    
                                                        $sub_offers[$new_offer_key]['options'][$option_value_id_this]['product_id_by_option_id'] = $on_option_prefix.$product_option_value['product_option_value_id'];
    
                                                        $sub_offers[$new_offer_key]['product']['group_id'] = $product['product_id'].'-'.$product_option_value[$option_value_sku];
    
                                                        if(isset($setting['divide_on_options_available_by_option_quantity'][$num_sel_option]) && $setting['divide_on_options_available_by_option_quantity'][$num_sel_option]){
    
                                                            $sub_offers[$new_offer_key]['options'][$option_value_id_this]['quantity'] = $product_option_value['quantity'];
    
                                                        }
    
                                                        foreach ($sub_offers[$new_offer_key]['product']['all_options'] as $key => $all_option_row3) {
    
                                                            if($all_option_row3['option_id']==$option_id_this && isset($sub_offers[$new_offer_key]['product']['all_options']) && isset($sub_offers[$new_offer_key]['product']['all_options'][$key])){
    
                                                                unset($sub_offers[$new_offer_key]['product']['all_options'][$key]);
    
                                                            }
                                                            
                                                            if($all_option_row3['option_id']==$option_id_this && isset($sub_offers[$new_offer_key]['product']['ym_options']) && isset($sub_offers[$new_offer_key]['product']['ym_options'][$key])){
    
                                                                unset($sub_offers[$new_offer_key]['product']['ym_options'][$key]);
    
                                                            }
    
                                                        }
                                                        
                                                    }
                                                    
                                                }
                                                
                                            }
                                            
                                        }
                                        
                                    }
                                    
                                    $sub_offers_result = array();
                                    
                                    foreach ($sub_offers as $new_offer_key => $sub_offer) {
                                        
                                        $sub_offer_result_product = $sub_offer['product'];
                                        
                                        $sub_offers_result[$new_offer_key] = $sub_offer_result_product;
                                        
                                        foreach ($sub_offer['options'] as $sub_offer_option) {
                                            
                                            if(!isset($sub_offers_result[$new_offer_key]['option_add_model_name'])){
                                                
                                                $sub_offers_result[$new_offer_key]['option_url_param'] = '';
                                                
                                                $sub_offers_result[$new_offer_key]['option_add_model_name'] = '';
                                                
                                                $sub_offers_result[$new_offer_key]['divide_on_option_add_to_name'] = '';
                                                
                                                $sub_offers_result[$new_offer_key]['product_id_by_option_id'] = $sub_offer_result_product['product_id'];
                                                
                                            }
                                            
                                            $sub_offers_result[$new_offer_key]['price'] += $sub_offer_option['price'];
                                            
                                            $sub_offers_result[$new_offer_key]['quantity'] += $sub_offer_option['quantity'];
                                            
                                            $sub_offers_result[$new_offer_key]['option_url_param'] .= $sub_offer_option['option_url_param'];
                                            
                                            if($sub_offer_option['option_add_model_name']){
                                                
                                                $sub_offers_result[$new_offer_key]['option_add_model_name'] .= ' '.$sub_offer_option['option_add_model_name'];
                                                
                                            }
                                            
                                            if($sub_offer_option['divide_on_option_add_to_name']){
                                                
                                                $sub_offers_result[$new_offer_key]['divide_on_option_add_to_name'] .= ' '.$sub_offer_option['divide_on_option_add_to_name'];
                                                
                                            }
                                            
                                            $sub_offers_result[$new_offer_key]['product_id_by_option_id'] .= '_'.$sub_offer_option['product_id_by_option_id'];
                                            
                                        }
                                        
                                    }
                                    
                                    if($sub_offers_result){
                                        
                                        unset($result['offers'][$product['product_id']]);
                                        
                                        $result['offers'] = array_merge($result['offers'],$sub_offers_result);
                                        
                                    }
                                    
                                }
                                
    
                                if(isset($setting['divide_on_option']) && $setting['divide_on_option'] && isset($result['offers'][$product['product_id']]['all_options']) && $result['offers'][$product['product_id']]['all_options']){
    
                                    $option_id = 0;
                                    if(isset($setting['divide_on_option_option_id']['field']['status']) && $setting['divide_on_option_option_id']['field']['status']){
                                        $option_id = $setting['divide_on_option_option_id']['field']['option_id'];
                                    }
    
                                    $all_option = $result['offers'][$product['product_id']]['all_options'];
    
                                    if($option_id){
                                        foreach ($all_option as $key => $option) {
    
                                            if($option['option_id']!=$option_id){
    
                                                unset($all_option[$key]);
    
                                            }
    
                                        }
                                    }
                                    if($all_option){
    
                                        $on_option_prefix = 'OPTION';
    
                                        if(isset($setting['divide_on_option_prefix'])){
    
                                            $setting['divide_on_option_prefix'] = trim($setting['divide_on_option_prefix']);
    
                                            if($setting['divide_on_option_prefix']){
    
                                                $on_option_prefix = $setting['divide_on_option_prefix'];
    
                                            }
    
                                        }
    
                                        foreach ($all_option as $key => $option) {
    
                                            foreach ($option['product_option_value'] as $product_option_value) {
    
                                                $option_value_id_this = $product_option_value['option_value_id'];
    
                                                $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']] = $result['offers'][$product['product_id']];
    
                                                if(isset($product_option_value['price']) && isset($product_option_value['price_prefix']) && $product_option_value['price_prefix']=='+'){
    
                                                    $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['price'] += $product_option_value['price'];
    
                                                }elseif (isset($product_option_value['price']) && isset($product_option_value['price_prefix']) && $product_option_value['price_prefix']=='-') {
    
                                                    $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['price'] -= $product_option_value['price'];
    
                                                    if($result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['price']<0){
    
                                                        $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['price'] = 0.0;
    
                                                    }
    
                                                }elseif (isset($product_option_value['price']) && isset($product_option_value['price_prefix']) && $product_option_value['price_prefix']=='=') {
    
                                                    $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['price'] = $product_option_value['price'];
    
                                                }
    
                                                $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['option_url_param'] = '&option_id='.$product_option_value['product_option_value_id'];
    
                                                $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['option_add_model_name'] = $product_option_value['name'];
    
                                                $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['product_id_by_option_id'] = $product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id'];
    
                                                $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['group_id'] = $product['product_id'];
    
                                                if(isset($setting['divide_on_option_available_by_option_quantity']) && $setting['divide_on_option_available_by_option_quantity']){
    
                                                    $result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['quantity'] = $product_option_value['quantity'];
    
                                                }
    
                                                foreach ($result['offers'][$product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id']]['all_options'] as $key => $all_option_row) {
    
                                                    if($all_option_row['option_id']==$option_id){
                                                        
                                                        if(isset($result['offers'][ $product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id'] ]['all_options'][$key])){
                                                            
                                                            foreach ($result['offers'][ $product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id'] ]['all_options'][$key]['product_option_value'] as $key2 => $all_option_row2) {
    
                                                                if($all_option_row2['option_value_id']!=$option_value_id_this){
    
                                                                    unset($result['offers'][ $product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id'] ]['all_options'][$key]['product_option_value'][$key2]);
    
                                                                }
                                                            }
                                                            
                                                        }
                                                        
                                                        if(isset($result['offers'][ $product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id'] ]['ym_options'][$key])){
                                                            
                                                            foreach ($result['offers'][ $product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id'] ]['ym_options'][$key]['product_option_value'] as $key2 => $all_option_row2) {
                                                                
                                                                if($all_option_row2['option_value_id']!=$option_value_id_this){
    
                                                                    unset($result['offers'][ $product['product_id'].$on_option_prefix.$product_option_value['product_option_value_id'] ]['ym_options'][$key]['product_option_value'][$key2]);
    
                                                                }
                                                            }
                                                            
                                                        }
    
                                                    }
    
                                                }
    
                                            }
    
                                        }
    
                                        unset($result['offers'][$product['product_id']]);
    
                                    }
    
                                }
    
                            }
    
                            unset($products_filtered[$i_product]);
    
                            if($memory_get_usage >= $memory_limit && $cache_status){
    
                                $this->writeCache($cache_file_name.'_'.count($result['cache']).'.txt', $result['offers']);
    
                                $result['cache'][$cache_file_name.'_'.count($result['cache']).'.txt'] = $cache_file_name.'_'.count($result['cache']).'.txt';
    
                                $result['offers'] = array();
    
                            }
    
                        }
    
                    }
    
                }
            
                if($cache_status){
    
                    $this->writeCache($cache_file_name.'_'.count($result['cache']).'.txt', $result['offers']);
    
                    $result['cache'][$cache_file_name.'_'.count($result['cache']).'.txt'] = $cache_file_name.'_'.count($result['cache']).'.txt';
    
                    $result['offers'] = array();
    
                }
                
            }
            
            //Если товары есть, соберем данные про категории
            if($result['offers'] || $result['cache']){
                $sql = "SELECT cd.name, c.sort_order, c.category_id, c.parent_id FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE cd.language_id = '" . (int)$content_language_id . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "'  AND c.status = '1' AND c.sort_order <> '-1'";
                $query = $this->db->query($sql);
                $result['categories'] = $query->rows;
            }
            
            $result['add_settings'] = $add_settings;
            
            return $result;
        }
        
        public function getMappingMarketPlaceCategories($mapping_market_place_categories) {
    	
    	$result = array();
    	
    	$category = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "category WHERE category_id = ( SELECT max(category_id) FROM " . DB_PREFIX . "category ) ");
    	
    	$category_id_start = 0;
    	
    	if($category->row){
    	    
    	    $category_id_start = $category->row['category_id']+1;
    	    
    	}
    	
    	$new_category_ids = array();
    	
    	if($mapping_market_place_categories){
    	    
    	    foreach ($mapping_market_place_categories as $site_category_id => $mapping_market_place_category) {
    		
    		$mapping_market_place_category = html_entity_decode($mapping_market_place_category);
    		
    		$mapping_market_place_category = $this->cleanExplode('|', $mapping_market_place_category);
    		
    		foreach ($mapping_market_place_category as $mapping_market_place_category_path) {
    		    
    		    $mapping_market_place_category_path = $this->cleanExplode('>',$mapping_market_place_category_path);
    		    
    		    $parent_id = 0;
    		    
    		    foreach ($mapping_market_place_category_path as $level => $category_name) {
    			
    			$category_md5 = md5($parent_id.'-'.$this->transliterate(preg_replace('/[^a-zA-Zа-яА-Я0-9]/ui', '',  mb_strtoupper($category_name) ))); 
    			
    			if(!isset($new_category_ids[$category_md5])){
    			    
    			    $category_id = $category_id_start;
    			    
    			    $new_category_ids[$category_md5] = $category_id;
    			    
    			    $category_id_start++;
    			    
    			}else{
    			    
    			    $category_id = $new_category_ids[$category_md5];
    			    
    			}
    			
    			if($category_id && $category_name!==''){
    			    
    			    $result[$category_id] = array(
    				'category_id'=>$category_id,
    				'parent_id'=>$parent_id,
    				'name'=>$category_name,
    				'sort_order'=>0,
    				'site_category_id'=>$site_category_id
    			    );
    			    
    			    $parent_id = $category_id;
    			    
    			}
    			
    		    }
    		    
    		}
    		
    	    }
    	    
    	}
    	
    	return $result;
    	
        }
        
        public function transliterate($textcyr) {
    	$cyr = array(
    	'ж',  'ч',  'щ',   'ш',  'ю',  'а', 'б', 'в', 'г', 'д', 'е', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ъ', 'ь', 'я',
    	'Ж',  'Ч',  'Щ',   'Ш',  'Ю',  'А', 'Б', 'В', 'Г', 'Д', 'Е', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ъ', 'Ь', 'Я');
    	$lat = array(
    	'zh', 'ch', 'sht', 'sh', 'yu', 'a', 'b', 'v', 'g', 'd', 'e', 'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'y', 'x', 'q',
    	'Zh', 'Ch', 'Sht', 'Sh', 'Yu', 'A', 'B', 'V', 'G', 'D', 'E', 'Z', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'H', 'c', 'Y', 'X', 'Q');
    	return mb_strtoupper(str_replace($cyr, $lat, $textcyr));
        }
        
        public function cleanExplode($delimiter,$string) {
    	
    	$explode = explode($delimiter, $string);
    	
    	foreach ($explode as $key => $value) {
    	    
    	    $value = trim($value);
    	    
    	    if($value===''){
    		
    		unset($explode[$key]);
    		
    	    }else{
    		
    		$explode[$key] = $value;
    		
    	    }
    	    
    	}
    	
    	if(!$explode){
    	    
    	    $explode = array();
    	    
    	}
    	
    	return $explode;
    	
        }
        
        public function getPromoGift($promos_id=NULL) {
            
            $sql = "SELECT * FROM `" .   DB_PREFIX   . 'ocext_feed_generator_yamarket_promo_gift` ';
            
            $where = array();
    	
    	$where[] = " status = 1 ";
    	
    	if(!is_null($promos_id)){
    	    
    	    $where[] = " promos_id = ".$promos_id." ";
    	    
    	}
            
            if($where){
                $sql .= 'WHERE '.implode(' AND ', $where);
            }
            
            $result = $this->db->query($sql);
    	
    	if($result->row){
    	    
    	    $result = json_decode($result->row['promos'],TRUE);
    	    
    	}else{
    	    
    	    $result = array();
    	    
    	}
            
            return $result;
            
        }
        
        public function getDeliveryOptionByManufacturer($delivery_option_by_manufacturer,$product) {
            
            $weight = (float)$product['weight'];
            
            $result = array();
            
            foreach ($delivery_option_by_manufacturer as $rule) {
                
                if($rule['w_from'] !== '' && $weight > $rule['w_from'] && ($rule['w_to']==='' ||  $weight <=  $rule['w_to']) ){
                    
                    $result = array(
                        'cost' => $rule['cost'],
                        'days' => $rule['days'],
                    );
                    
                }
                
            }
            
            return $result;
            
        }
        
        public function writeCache($filename,$array,$string='') {
            
            $handle = fopen(DIR_CACHE. $filename, 'w+');
            
            if(!$handle){
                
                $log_errors = new ControllerFeedOcextFeedGeneratorYaMarket($this->registry);
                
                $log_errors->setLogErrors('cache write error to file: '.DIR_CACHE. $filename);
                
            }
            
            if($string){
                fwrite($handle, $string);
            }else{
                fwrite($handle, json_encode($array));
            }
            
            fclose($handle);
            
        }
        
        public function unlinkAllCache($cache_files) {
    
            $files = scandir(DIR_CACHE);
    
            foreach($files as $file_name){
    
                foreach($cache_files as $cache_file){
    
                    if(strstr($file_name, $cache_file)){
    
                        unlink(DIR_CACHE.$file_name);
    
                    }
    
                }
    
            }
    
        }
        
        
        public function getYmCategoriesFromDb($data=array('category_id'=>1,'status'=>0)) {
            $sql = "SELECT * FROM `" . DB_PREFIX . "ocext_feed_generator_yamarket_ym_categories` ";
            $where = array();
            if ($data['category_id']==1) {
                $where[] = " category_id != '0' ";
            }
            
            if (!empty($data['ym_category_last_child'])) {
                $where[] = " ym_category_last_child LIKE '" . $this->db->escape($data['ym_category_last_child']) . "%' ";
            }
            
            if ($data['status']!='') {
                $where[] = " status = '" . (int)$data['status'] . "' ";
            }
            
            if($where){
                $where = ' WHERE '.implode(' AND ', $where);
            }else{
                $where = '';
            }
            
            $sql .= $where;
            
            if (isset($data['start']) || isset($data['limit'])) {
                if ($data['start'] < 0) {
                        $data['start'] = 0;
                }
                if ($data['limit'] < 1) {
                        $data['limit'] = 20;
                }
                $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
            }
            $query = $this->db->query($sql);
            
            $result = array();
            if($query->rows){
                foreach ($query->rows as $ym_category) {
                    $categories = json_decode($ym_category['category_id'],TRUE);
                    if($categories){
                        foreach ($categories as $category_id) {
                            $result[$category_id] = $ym_category['ym_category_path'];
                        }
                    }
                }
            }
            
            return $result;
        }
        
        public function getProductAttributes($product_id,$ym_attributes=array(),$content_language_id) {
            
                $attributes_sql = array();
                //Вычеркнуть атрибуты
                if($ym_attributes){
                    foreach ($ym_attributes as $attribute) {
                        $attributes_parts = explode('___', $attribute);
                        //0 - группа, 1 - id атрибута
                        $attributes_sql[$attributes_parts[0]][$attributes_parts[1]] = $attributes_parts[1];
                    }
                    
                }
                $product_attribute_group_data = array();
    
                $product_attribute_group_query = $this->db->query("SELECT ag.attribute_group_id, agd.name FROM " . DB_PREFIX . "product_attribute pa LEFT JOIN " . DB_PREFIX . "attribute a ON (pa.attribute_id = a.attribute_id) LEFT JOIN " . DB_PREFIX . "attribute_group ag ON (a.attribute_group_id = ag.attribute_group_id) LEFT JOIN " . DB_PREFIX . "attribute_group_description agd ON (ag.attribute_group_id = agd.attribute_group_id) WHERE pa.product_id = '" . (int)$product_id . "' AND agd.language_id = '" . (int)$content_language_id . "' GROUP BY ag.attribute_group_id ORDER BY ag.sort_order, agd.name");
    
                
                foreach ($product_attribute_group_query->rows as $product_attribute_group) {
                        $product_attribute_data = array();
    
                        $product_attribute_query = $this->db->query("SELECT a.attribute_id, ad.name, pa.text FROM " . DB_PREFIX . "product_attribute pa LEFT JOIN " . DB_PREFIX . "attribute a ON (pa.attribute_id = a.attribute_id) LEFT JOIN " . DB_PREFIX . "attribute_description ad ON (a.attribute_id = ad.attribute_id) WHERE pa.product_id = '" . (int)$product_id . "' AND a.attribute_group_id = '" . (int)$product_attribute_group['attribute_group_id'] . "' AND ad.language_id = '" . (int)$content_language_id . "' AND pa.language_id = '" . (int)$content_language_id . "' ORDER BY a.sort_order, ad.name");
    
                        foreach ($product_attribute_query->rows as $product_attribute) {
                            if(!isset($attributes_sql[$product_attribute_group['attribute_group_id']][$product_attribute['attribute_id']])){
                                
                                /*
                                 * 
                                $product_attribute_data[] = array(
                                    'attribute_id' => $product_attribute['attribute_id'],
                                    'name'         => $product_attribute['name'],
                                    'text'         => $product_attribute['text']
                                );
                                 * 
                                 */
                                
                                $unit = $this->getUnit($product_attribute['name']);
    						
                                if($unit!==''){
                                        $product_attribute['name'] = trim(str_replace(array(', ('.$unit.')',',('.$unit.')','('.$unit.')',), '', $product_attribute['name']));
                                        $product_attribute_data[] = array(
                                                'attribute_id' => $product_attribute['attribute_id'],
                                                'name'         => $product_attribute['name'],
                                                'text'         => $product_attribute['text'],
                                                'unit'	=> $unit
                                        );
    
                                }else{
    
                                        $product_attribute_data[] = array(
                                            'attribute_id' => $product_attribute['attribute_id'],
                                            'name'         => $product_attribute['name'],
                                            'text'         => $product_attribute['text']
                                        );
    
                                }
                                
                            }
                        }
                        
                        $unit = $this->getUnit($product_attribute_group['name']);
                        
                        if($unit){
                            $product_attribute_group['name'] = trim(str_replace(array(', ('.$unit.')',',('.$unit.')','('.$unit.')',), '', $product_attribute_group['name']));
                        }
    
                        $product_attribute_group_data[] = array(
                                'attribute_group_id' => $product_attribute_group['attribute_group_id'],
                                'name'               => $product_attribute_group['name'],
                                'attribute'          => $product_attribute_data,
                                'unit'              => $unit
                        );
                }
    
                return $product_attribute_group_data;
        }
        
        public function getProductOptions($product_id,$ym_options=array(),$content_language_id) {
            
            
            $product_option_data = array();
    
            $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$content_language_id . "' ORDER BY o.sort_order");
    
            foreach ($product_option_query->rows as $product_option) {
                    $product_option_value_data = array();
    
                    $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$content_language_id . "' ORDER BY ov.sort_order");
    
                    foreach ($product_option_value_query->rows as $product_option_value) {
                        
                        $product_option_value_data_this = array();
                        
                        foreach ($product_option_value as $product_option_value_name => $product_option_value_value) {
                            $product_option_value_data_this[$product_option_value_name] = $product_option_value_value;
                        }
                        
                        $product_option_value_data[] = $product_option_value_data_this;
                        
                        /*
                            $product_option_value_data[] = array(
                                    'product_option_value_id' => $product_option_value['product_option_value_id'],
                                    'option_value_id'         => $product_option_value['option_value_id'],
                                    'name'                    => $product_option_value['name'],
                                    'image'                   => $product_option_value['image'],
                                    'quantity'                => $product_option_value['quantity'],
                                    'subtract'                => $product_option_value['subtract'],
                                    'price'                   => $product_option_value['price'],
                                    'price_prefix'            => $product_option_value['price_prefix'],
                                    'weight'                  => $product_option_value['weight'],
                                    'weight_prefix'           => $product_option_value['weight_prefix']
                            );
                            */
                    }
                    
                    $unit = $this->getUnit($product_option['name']); 
                        
                    if($unit){
                        $product_option['name'] = trim(str_replace(array(', ('.$unit.')',',('.$unit.')','('.$unit.')',), '', $product_option['name']));
                    }
                    
                    if(!isset($ym_options[$product_option['option_id']])){
                        $product_option_data[] = array(
                            'product_option_id'    => $product_option['product_option_id'],
                            'product_option_value' => $product_option_value_data,
                            'option_id'            => $product_option['option_id'],
                            'name'                 => $product_option['name'],
                            'type'                 => $product_option['type'],
                            'value'                => $product_option['value'],
                            'required'             => $product_option['required'],
                            'unit' => $unit
                        );
                    }
            }
            return $product_option_data;
    }
        
    public function getProductImages($product_id) {
            $sql = "SELECT * FROM `" . DB_PREFIX . "product_image` WHERE product_id = '".$product_id."' AND image != 'no-image.jpg' AND image != 'no-image.png' AND image != 'no_image.png' AND image != 'no_image.jpg' ORDER BY sort_order ASC ";
            $query = $this->db->query($sql);
            return $query->rows;
        }    
        
    public function getProductRelated($product_id) {
                $product_related_data = array();
    
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
    
                foreach ($query->rows as $result) {
                        $product_related_data[] = $result['related_id'];
                }
    
                return $product_related_data;
        }
    
    private function getUnit($string){
            $units_parts = explode(' (', $string);
            $unit = '';
            if($units_parts && is_array($units_parts)){
                foreach ($units_parts as $units_part) {
                    $parts = explode(')', $units_part);
                    if($parts && count($parts)>1){
                        $unit = $parts[0];
                    }
                }
            }
            return $unit;
        }
    
        public function getCategories() {
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c  LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE  c2s.store_id = '" . (int)$this->config->get('config_store_id') . "'  AND c.status = '1' AND c.sort_order <> '-1'");
                $categories = array();
                if($query->rows){
                    foreach ($query->rows as $category){
                        $categories[ $category['cvategory_id'] ] = $category['cvategory_id'];
                    }
                }
                return $categories;
        }
        
        public function getManufacturers() {
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "manufacturer m  LEFT JOIN " . DB_PREFIX . "manufacturer_to_store m2s ON (m.manufacturer_id = m2s.manufacturer_id) WHERE  m2s.store_id = '" . (int)$this->config->get('config_store_id') . "'  AND m.status = '1' AND m.sort_order <> '-1'");
                $manufacturers = array();
                if($query->rows){
                    foreach ($query->rows as $manufacturer){
                        $manufacturers[ $manufacturer['manufacturer_id'] ] = $manufacturer['manufacturer_id'];
                    }
                }
                return $manufacturers;
        }
        
        
        
        
        
        
        
        public function showTable($table='ocext_all_yml_export_filter_data') {
            
            $check = $query = $this->db->query('SHOW TABLES from `'.DB_DATABASE.'` like "'.DB_PREFIX.$table.'" ');
            if(!$check->num_rows){
                return FALSE;
            }else{
                return TRUE;
            }
            
        }
        
        
        
        
        
        public function getSpecialAndDiscontPrices($product_id) {
            
            $result = array('special_price'=>0,'discount_special_price'=>0);
            
            $sql = "SELECT * FROM `".DB_PREFIX."product_special` WHERE customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND date_start <= NOW() AND ( date_end = '0000-00-00' OR date_end >= NOW() ) AND product_id=".$product_id;
            
            $special_prices = $this->db->query($sql." ORDER BY priority ASC ");
            
            if($special_prices->row){
                $result['special_price'] = $special_prices->row['price'];
            }
            
            $sql = "SELECT * FROM `".DB_PREFIX."product_discount` WHERE customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND date_start <= NOW() AND ( date_end = '0000-00-00' OR date_end >= NOW() ) AND product_id=".$product_id;
            
            $discount_prices = $this->db->query($sql." AND quantity=1 ORDER BY priority ASC ");
            
            if($discount_prices->row){
                $result['discount_special_price'] = $discount_prices->row['price'];
            }
            
            return $result;
            
        }
        
        
    	
    }
    ?>

     

     

    Пример выгрузки https://test.mebelmassive.ru/index.php?route=extension/feed/ocext_feed_generator_yamarket&token=64367

×
×
  • Создать...