Jump to content
Sign in to follow this  
valonix

Как вывести список категорий с картинками на странице (information)

Recommended Posts

Добрый день. Видел модуль Category Groups, но он не подходит мне. Как можно заюзать getCategories и передать в information список категорий вместе с картинками. 

Share this post


Link to post
Share on other sites
$this->load->model('catalog/category');

		$this->load->model('catalog/product');
		$this->data['categories'] = array();

		$categories = $this->model_catalog_category->getCategories(0);
		//Показывать или нет количество товаров
		$show_product_count = $this->config->get('config_product_count');
		foreach ($categories as $category) {
			//Будем вычислять кол-во товаров в категориях только если это кол-во надо показывать
			$PIDs=array();
			if ($show_product_count) {
				$res = $this->model_catalog_product->getTotalProductsID(array('filter_category_id' => $category['category_id']));
				foreach ($res as $key=>$value) {
					$PIDs[$value['product_id']]=$value['product_id'];
				}
			}

			$children_data = array();

			$children = $this->model_catalog_category->getCategories($category['category_id']);

			foreach ($children as $child) {
				//Будем вычислять кол-во товаров в категориях только если это кол-во надо показывать
				if ($show_product_count) {
					$data = array(
						'filter_category_id'  => $child['category_id'],
						'filter_sub_category' => true
					);

					$res = $this->model_catalog_product->getTotalProductsID($data);
					$product_total=count($res);
					foreach ($res as $key=>$value) {
						$PIDs[$value['product_id']]=$value['product_id'];
					}

//					$total += count($PIDs);
				}

				$children_data[] = array(
					'category_id' => $child['category_id'],
					'name'        => $child['name'] . ($show_product_count ? ' (' . $product_total . ')' : ''),
					'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']),
					'image'       => $child['image'],
				);		
			}

			$total = count($PIDs);

			$this->data['categories'][] = array(
				'category_id' => $category['category_id'],
				'name'        => $category['name'] . ($show_product_count ? ' (' . $total . ')' : ''),
				'children'    => $children_data,
				'href'        => $this->url->link('product/category', 'path=' . $category['category_id']),
				'image'       => $category['image'],
			);	
		}

Пока написал, пришло озарение.  Вот получилось.

Share this post


Link to post
Share on other sites

А если этому модулю  тупо указать схему Information ?  :wink:

Share this post


Link to post
Share on other sites

Пришел Том и все испортил!!! :-D

Share this post


Link to post
Share on other sites

эээ, так а верстка то другая, это не тот что в категории в сайдбаре :)

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.

Sign in to follow this  

  • 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.