Jump to content

Recommended Posts

Всем привет. Есть модуль, который получает некую переменную $setting , в этой переменной должны идти настройки модуля, которые находятся в сетке oc_setting. Настройки там есть, но в переменную они почему-то не поступают. Где можно посмотреть откуда она идет? Смотрю в других модулях, там точно также в ф-цию index() передается переменная $settings, но там все работает.

Share this post


Link to post
Share on other sites

Есть два типа модулей: модули "одиночки" и модули, которые создаются добавлением в списке модулей.

Настройки первого типа сохраняются в таблице setting, второго - в module.

 

$setting идет в модулях второго типа (карусель, баннеры, последние...).

Модули без "подмодулей" такой переменной не получают (категории, фильтр, аккаунт...).

 

Чтобы получить настройки модуля из таблицы setting, используйте API конфига:

$this->config->get('mymodule_status');

 

Share this post


Link to post
Share on other sites
8 минут назад, SooR сказал:

Есть два типа модулей: модули "одиночки" и модули, которые создаются добавлением в списке модулей.

Настройки первого типа сохраняются в таблице setting, второго - в module.

 

$setting идет в модулях второго типа (карусель, баннеры, последние...).

Модули без "подмодулей" такой переменной не получают (категории, фильтр, аккаунт...).

 

Чтобы получить настройки модуля из таблицы setting, используйте API конфига:


$this->config->get('mymodule_status');

 

Не совсем понял что сделать. Это $this->config->get('mymodule_status'); добавить в контроллере модуля?

Edited by abonnent

Share this post


Link to post
Share on other sites

Все что хранится в setting попадает в $this->config и доступно по ключу, которым является колонка 'key' в этой таблице.

Используйте $this->config->get('mymodule_status'); вместо $setting['status'].

Share this post


Link to post
Share on other sites

Извините за глупость, но где это вставить?

<?php  
class ControllerExtensionModulePavautosearch extends Controller {
	
	private $mdata = array();

	public function index($setting){


		echo '<div style="display:none">';
		echo '<pre>';
		print_r($setting);
		echo '</pre>';
		echo '</div>';



		// pavo 2.2 fix
		$this->load->language('extension/module/themecontrol');

		$config_theme = $this->config->get('theme_default_directory');
		
		$this->mdata['objlang']   = $this->language;
		$this->mdata['ourl']      = $this->url;
		$this->mdata['sconfig']   = $this->config;
		$this->mdata['themename'] = $config_theme;
		// pavo 2.2 fix
	
		static $module = 0;
		$this->load->language('extension/module/pavautosearch');
		$this->load->model('tool/image');
		$this->load->model('catalog/category');
		$this->load->model('catalog/manufacturer');

		$this->mdata['objlang'] = $this->language;

		if (file_exists('catalog/view/theme/' . $config_theme . '/stylesheet/pavautosearch.css')) {
			$this->document->addStyle('catalog/view/theme/' . $config_theme . '/stylesheet/pavautosearch.css');
		} else {
			$this->document->addStyle('catalog/view/theme/default/stylesheet/pavautosearch.css');
		}

		$this->mdata['additional_class'] = isset($setting['class'])?$setting['class']:'';
		$this->mdata['limit'] = isset($setting['limit'])?$setting['limit']:5;
		$this->mdata['show_category'] = isset($setting['show_category'])?$setting['show_category']:'1';
		$this->mdata['show_image'] = isset($setting['show_image'])?$setting['show_image']:'1';
		$this->mdata['show_price'] = isset($setting['show_price'])?$setting['show_price']:'1';
		$this->mdata['categories'] = $this->mdata["manufacturers"] = array();

		if($this->mdata['show_category']){
			
			// 3 Level Category Search
			$this->mdata['categories'] = array();

			$this->mdata['category_id'] = 0;

			$categories_1 = $this->model_catalog_category->getCategories(0);

			foreach ($categories_1 as $category_1) {
				$level_2_data = array();

				$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);

				foreach ($categories_2 as $category_2) {
					$level_3_data = array();

					$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);

					foreach ($categories_3 as $category_3) {
						$level_3_data[] = array(
							'category_id' => $category_3['category_id'],
							'name'        => $category_3['name'],
						);
					}

					$level_2_data[] = array(
						'category_id' => $category_2['category_id'],	
						'name'        => $category_2['name'],
						'children'    => $level_3_data
					);					
				}

				$this->mdata['categories'][] = array(
					'category_id' => $category_1['category_id'],
					'name'        => $category_1['name'],
					'children'    => $level_2_data
				);
			}

		}
		
		$this->mdata['module'] = $module++;
		
		return $this->load->view('extension/module/pavautosearch', $this->mdata);
	}
	public function autocomplete() {
		$json = array();

		$this->load->language('product/category');
		if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_manufacturer_id']) || isset($this->request->get['filter_category_id'])) {
			$this->load->model('tool/image');
			$this->load->model('catalog/product');
			
			if (isset($this->request->get['filter_name'])) {
				$filter_name = $this->request->get['filter_name'];
			} else {
				$filter_name = '';
			}

			if (isset($this->request->get['filter_category_id'])) {
				$filter_category_id = $this->request->get['filter_category_id'];
			} else {
				$filter_category_id = '';
			}
			if (isset($this->request->get['description'])) {
				$description = $this->request->get['description'];
			} else {
				$description = '';
			}
			if (isset($this->request->get['sub_category'])) {
				$sub_category = $this->request->get['sub_category'];
			} else {
				$sub_category = '';
			}

			if (isset($this->request->get['limit'])) {
				$limit = $this->request->get['limit'];	
			} else {
				$limit = 20;	
			}

			if (isset($this->request->get['width'])) {
				$width = $this->request->get['width'];	
			} else {
				$width = 100;	
			}

			if (isset($this->request->get['height'])) {
				$height = $this->request->get['height'];	
			} else {
				$height = 100;	
			}

			$data = array(
				'filter_name'  => $filter_name,
				'filter_tag'   => $filter_name,
				'filter_description' => $description,
				'filter_sub_category' => $sub_category,
				'filter_category_id' => $filter_category_id,
				'start'        => 0,
				'limit'        => $limit
			);
			
			$results = $this->model_catalog_product->getProducts($data);
			$total = $this->model_catalog_product->getTotalProducts($data);
			foreach ($results as $result) {
				if ($result['image']) {
					$image = $this->model_tool_image->resize($result['image'], $width, $height);
				} else {
					$image = false;
				}
				if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
					$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				} else {
					$price = false;
				}
						
				if ((float)$result['special']) {
					$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				} else {
					$special = false;
				}
				if ($this->config->get('config_tax')) {
					$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
				} else {
					$tax = false;
				}
				
				$json[] = array(
					'total' => $total,
					'product_id' => $result['product_id'],
					'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),	
					'model'      => $result['model'],
					'image'		 => $image,
					'link'		 => $this->url->link('product/product','product_id='.$result['product_id']),
					'special'	 => $special,
					'tax'		 => $tax,
					'price'      => $price
				);	
			}
			
		}

		$this->response->setOutput(json_encode($json));
	}
}
?>

это контроллер модуля. 

Share this post


Link to post
Share on other sites

@abonnent , нужно изначально знать как подключается этот модуль, какого он типа? Если он добавляется в списке модулей, то должен получать $setting аргументом.

 

Вы должны сперва правильно сохранить настройки этого модуля (не в setting?), затем использовать его.

Share this post


Link to post
Share on other sites
2 минуты назад, SooR сказал:

@abonnent , нужно изначально знать как подключается этот модуль, какого он типа? Если он добавляется в списке модулей, то должен получать $setting аргументом.

 

Вы должны сперва правильно сохранить настройки этого модуля (не в setting?), затем использовать его.

не я делал этот модуль, но настройки его сохраняются именно там. Если этот модуль сделан как-то не так, то что нужно сделать, чтобы вытащить его настройки из этой сетки (oc_settings)?

Edited by abonnent

Share this post


Link to post
Share on other sites

Какой code имеет настройка этого модуля в таблице?

Share this post


Link to post
Share on other sites
4 минуты назад, SooR сказал:

Какой code имеет настройка этого модуля в таблице?

{"1":{"class":"autosearch","limit":"6","show_category":"0","show_image":"1","show_price":"1"}}

 

Share this post


Link to post
Share on other sites

Это value, а нужен code

Здесь, к примеру, в поле code указано theme_default

 

Спойлер

2017-12-23_182238.png.b3c9f756ec465fb13e1592a7ec3bc881.png

 

Share this post


Link to post
Share on other sites
3 минуты назад, SooR сказал:

Это value, а нужен code

Здесь, к примеру, в поле code указано theme_default

 

  Скрыть контент

2017-12-23_182238.png.b3c9f756ec465fb13e1592a7ec3bc881.png

 

ой, простите) pavautosearch

Share this post


Link to post
Share on other sites

Тогда попробуйте так, хотя и поле key желательно бы знать.

 

Share this post


Link to post
Share on other sites
1 минуту назад, SooR сказал:

Тогда попробуйте так, хотя и поле key желательно бы знать.

 

  Показать контент


<?php
class ControllerExtensionModulePavautosearch extends Controller {

	private $mdata = array();

	public function index($setting = array()) {
    if (!$setting) {
    	$setting = $this->config->get('pavautosearch');
    }

    echo '<div style="display:none">';
		echo '<pre>';
		print_r($setting);
		echo '</pre>';
		echo '</div>';

		// pavo 2.2 fix
		$this->load->language('extension/module/themecontrol');

		$config_theme = $this->config->get('theme_default_directory');

		$this->mdata['objlang']   = $this->language;
		$this->mdata['ourl']      = $this->url;
		$this->mdata['sconfig']   = $this->config;
		$this->mdata['themename'] = $config_theme;
		// pavo 2.2 fix

		static $module = 0;
		$this->load->language('extension/module/pavautosearch');
		$this->load->model('tool/image');
		$this->load->model('catalog/category');
		$this->load->model('catalog/manufacturer');

		$this->mdata['objlang'] = $this->language;

		if (file_exists('catalog/view/theme/' . $config_theme . '/stylesheet/pavautosearch.css')) {
			$this->document->addStyle('catalog/view/theme/' . $config_theme . '/stylesheet/pavautosearch.css');
		} else {
			$this->document->addStyle('catalog/view/theme/default/stylesheet/pavautosearch.css');
		}

		$this->mdata['additional_class'] = isset($setting['class'])?$setting['class']:'';
		$this->mdata['limit'] = isset($setting['limit'])?$setting['limit']:5;
		$this->mdata['show_category'] = isset($setting['show_category'])?$setting['show_category']:'1';
		$this->mdata['show_image'] = isset($setting['show_image'])?$setting['show_image']:'1';
		$this->mdata['show_price'] = isset($setting['show_price'])?$setting['show_price']:'1';
		$this->mdata['categories'] = $this->mdata["manufacturers"] = array();

		if($this->mdata['show_category']){

			// 3 Level Category Search
			$this->mdata['categories'] = array();

			$this->mdata['category_id'] = 0;

			$categories_1 = $this->model_catalog_category->getCategories(0);

			foreach ($categories_1 as $category_1) {
				$level_2_data = array();

				$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);

				foreach ($categories_2 as $category_2) {
					$level_3_data = array();

					$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);

					foreach ($categories_3 as $category_3) {
						$level_3_data[] = array(
							'category_id' => $category_3['category_id'],
							'name'        => $category_3['name'],
						);
					}

					$level_2_data[] = array(
						'category_id' => $category_2['category_id'],
						'name'        => $category_2['name'],
						'children'    => $level_3_data
					);
				}

				$this->mdata['categories'][] = array(
					'category_id' => $category_1['category_id'],
					'name'        => $category_1['name'],
					'children'    => $level_2_data
				);
			}

		}

		$this->mdata['module'] = $module++;

		return $this->load->view('extension/module/pavautosearch', $this->mdata);
	}
	public function autocomplete() {
		$json = array();

		$this->load->language('product/category');
		if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_manufacturer_id']) || isset($this->request->get['filter_category_id'])) {
			$this->load->model('tool/image');
			$this->load->model('catalog/product');

			if (isset($this->request->get['filter_name'])) {
				$filter_name = $this->request->get['filter_name'];
			} else {
				$filter_name = '';
			}

			if (isset($this->request->get['filter_category_id'])) {
				$filter_category_id = $this->request->get['filter_category_id'];
			} else {
				$filter_category_id = '';
			}
			if (isset($this->request->get['description'])) {
				$description = $this->request->get['description'];
			} else {
				$description = '';
			}
			if (isset($this->request->get['sub_category'])) {
				$sub_category = $this->request->get['sub_category'];
			} else {
				$sub_category = '';
			}

			if (isset($this->request->get['limit'])) {
				$limit = $this->request->get['limit'];
			} else {
				$limit = 20;
			}

			if (isset($this->request->get['width'])) {
				$width = $this->request->get['width'];
			} else {
				$width = 100;
			}

			if (isset($this->request->get['height'])) {
				$height = $this->request->get['height'];
			} else {
				$height = 100;
			}

			$data = array(
				'filter_name'  => $filter_name,
				'filter_tag'   => $filter_name,
				'filter_description' => $description,
				'filter_sub_category' => $sub_category,
				'filter_category_id' => $filter_category_id,
				'start'        => 0,
				'limit'        => $limit
			);

			$results = $this->model_catalog_product->getProducts($data);
			$total = $this->model_catalog_product->getTotalProducts($data);
			foreach ($results as $result) {
				if ($result['image']) {
					$image = $this->model_tool_image->resize($result['image'], $width, $height);
				} else {
					$image = false;
				}
				if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
					$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				} else {
					$price = false;
				}

				if ((float)$result['special']) {
					$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				} else {
					$special = false;
				}
				if ($this->config->get('config_tax')) {
					$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
				} else {
					$tax = false;
				}

				$json[] = array(
					'total' => $total,
					'product_id' => $result['product_id'],
					'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
					'model'      => $result['model'],
					'image'		 => $image,
					'link'		 => $this->url->link('product/product','product_id='.$result['product_id']),
					'special'	 => $special,
					'tax'		 => $tax,
					'price'      => $price
				);
			}

		}

		$this->response->setOutput(json_encode($json));
	}
}
?>

 

 

key - pavautosearch_module

Share this post


Link to post
Share on other sites

Тогда так должно сработать

 

Спойлер

<?php
class ControllerExtensionModulePavautosearch extends Controller {

	private $mdata = array();

	public function index($setting = array()) {
    if (!$setting) {
    	$setting = $this->config->get('pavautosearch_module');
    }

    echo '<div style="display:none">';
		echo '<pre>';
		print_r($setting);
		echo '</pre>';
		echo '</div>';

		// pavo 2.2 fix
		$this->load->language('extension/module/themecontrol');

		$config_theme = $this->config->get('theme_default_directory');

		$this->mdata['objlang']   = $this->language;
		$this->mdata['ourl']      = $this->url;
		$this->mdata['sconfig']   = $this->config;
		$this->mdata['themename'] = $config_theme;
		// pavo 2.2 fix

		static $module = 0;
		$this->load->language('extension/module/pavautosearch');
		$this->load->model('tool/image');
		$this->load->model('catalog/category');
		$this->load->model('catalog/manufacturer');

		$this->mdata['objlang'] = $this->language;

		if (file_exists('catalog/view/theme/' . $config_theme . '/stylesheet/pavautosearch.css')) {
			$this->document->addStyle('catalog/view/theme/' . $config_theme . '/stylesheet/pavautosearch.css');
		} else {
			$this->document->addStyle('catalog/view/theme/default/stylesheet/pavautosearch.css');
		}

		$this->mdata['additional_class'] = isset($setting['class'])?$setting['class']:'';
		$this->mdata['limit'] = isset($setting['limit'])?$setting['limit']:5;
		$this->mdata['show_category'] = isset($setting['show_category'])?$setting['show_category']:'1';
		$this->mdata['show_image'] = isset($setting['show_image'])?$setting['show_image']:'1';
		$this->mdata['show_price'] = isset($setting['show_price'])?$setting['show_price']:'1';
		$this->mdata['categories'] = $this->mdata["manufacturers"] = array();

		if($this->mdata['show_category']){

			// 3 Level Category Search
			$this->mdata['categories'] = array();

			$this->mdata['category_id'] = 0;

			$categories_1 = $this->model_catalog_category->getCategories(0);

			foreach ($categories_1 as $category_1) {
				$level_2_data = array();

				$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);

				foreach ($categories_2 as $category_2) {
					$level_3_data = array();

					$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);

					foreach ($categories_3 as $category_3) {
						$level_3_data[] = array(
							'category_id' => $category_3['category_id'],
							'name'        => $category_3['name'],
						);
					}

					$level_2_data[] = array(
						'category_id' => $category_2['category_id'],
						'name'        => $category_2['name'],
						'children'    => $level_3_data
					);
				}

				$this->mdata['categories'][] = array(
					'category_id' => $category_1['category_id'],
					'name'        => $category_1['name'],
					'children'    => $level_2_data
				);
			}

		}

		$this->mdata['module'] = $module++;

		return $this->load->view('extension/module/pavautosearch', $this->mdata);
	}
	public function autocomplete() {
		$json = array();

		$this->load->language('product/category');
		if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_manufacturer_id']) || isset($this->request->get['filter_category_id'])) {
			$this->load->model('tool/image');
			$this->load->model('catalog/product');

			if (isset($this->request->get['filter_name'])) {
				$filter_name = $this->request->get['filter_name'];
			} else {
				$filter_name = '';
			}

			if (isset($this->request->get['filter_category_id'])) {
				$filter_category_id = $this->request->get['filter_category_id'];
			} else {
				$filter_category_id = '';
			}
			if (isset($this->request->get['description'])) {
				$description = $this->request->get['description'];
			} else {
				$description = '';
			}
			if (isset($this->request->get['sub_category'])) {
				$sub_category = $this->request->get['sub_category'];
			} else {
				$sub_category = '';
			}

			if (isset($this->request->get['limit'])) {
				$limit = $this->request->get['limit'];
			} else {
				$limit = 20;
			}

			if (isset($this->request->get['width'])) {
				$width = $this->request->get['width'];
			} else {
				$width = 100;
			}

			if (isset($this->request->get['height'])) {
				$height = $this->request->get['height'];
			} else {
				$height = 100;
			}

			$data = array(
				'filter_name'  => $filter_name,
				'filter_tag'   => $filter_name,
				'filter_description' => $description,
				'filter_sub_category' => $sub_category,
				'filter_category_id' => $filter_category_id,
				'start'        => 0,
				'limit'        => $limit
			);

			$results = $this->model_catalog_product->getProducts($data);
			$total = $this->model_catalog_product->getTotalProducts($data);
			foreach ($results as $result) {
				if ($result['image']) {
					$image = $this->model_tool_image->resize($result['image'], $width, $height);
				} else {
					$image = false;
				}
				if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
					$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				} else {
					$price = false;
				}

				if ((float)$result['special']) {
					$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
				} else {
					$special = false;
				}
				if ($this->config->get('config_tax')) {
					$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
				} else {
					$tax = false;
				}

				$json[] = array(
					'total' => $total,
					'product_id' => $result['product_id'],
					'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
					'model'      => $result['model'],
					'image'		 => $image,
					'link'		 => $this->url->link('product/product','product_id='.$result['product_id']),
					'special'	 => $special,
					'tax'		 => $tax,
					'price'      => $price
				);
			}

		}

		$this->response->setOutput(json_encode($json));
	}
}
?>

 

 

  • +1 1

Share this post


Link to post
Share on other sites

Спасибо. Заработало =)
 

Edited by abonnent

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.