Jump to content
rsqrsk

Вывод товаров по принадлежности к категории

Recommended Posts

Добрый вечер. 

Вывожу список всех товаров по id в определенном диапазоне, но не устраивает, что это сплошной список.

Подскажите пожалуйста, каким способом лучше отсортировать их хотя бы по главному родителю категорий (товары с главной категорией в админке связаны)?

Например:

Название категории

... продукт

... продукт

... продукт 

Название категории

... продукт

... продукт

... продукт 

 

Список вывожу таким образом:

controller

<?php
class ControllerInformationPricelist extends Controller {
	public function index() {
		$this->document->setTitle($this->config->get('config_meta_title'));
		$this->document->setDescription($this->config->get('config_meta_description'));
		$this->document->setKeywords($this->config->get('config_meta_keyword'));
		
		$this->load->model('catalog/category');
		$this->load->model('catalog/product');
		
		$data['products'] = array();
		$data['discounts'] = array();
		
		$products = array_merge(range(50,100));
		foreach ($products as $product_id) {
			$product_info = $this->model_catalog_product->getProduct($product_id);
			
			//$product_img = $this->model_catalog_product->getProductImages($product_id);	
			
			$discount_info = $this->model_catalog_product->getProductDiscountPrice($product_id);
			foreach ($discount_info as $discount) {
					$data['discounts'][] = array(
						'quantity' => $discount['quantity'],
						'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
					);
			}	
					
			if ($product_info) {
					if ($this->customer->isLogged() || !$this->config->get(				'config_customer_price')) {
						$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
					} else {
						$price = false;
					}

					if ((float)$product_info['special']) {
						$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['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)$product_info['special'] ? $product_info['special'] : $product_info['price'], $this->session->data['currency']);
					} else {
						$tax = false;
					}

					if ($this->config->get('config_review_status')) {
						$rating = $product_info['rating'];
					} else {
						$rating = false;
					}
					
					$data['products'][] = array(
						'product_id'  => $product_info['product_id'],
						'name'        => $product_info['name'],
						'pricedis'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
						'sku'         => $product_info['sku'],
						'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
						'price'       => $price,
						'special'     => $special,
						'tax'         => $tax,
						'rating'      => $rating,
						'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
					);
			}
		}
		
		if (isset($this->request->get['route'])) {
			$this->document->addLink($this->config->get('config_url'), 'canonical');
		}

		$data['column_left'] = $this->load->controller('common/column_left');
		$data['column_right'] = $this->load->controller('common/column_right');
		$data['content_top'] = $this->load->controller('common/content_top');
		$data['content_bottom'] = $this->load->controller('common/content_bottom');
		$data['footer'] = $this->load->controller('common/footer');
		$data['header'] = $this->load->controller('common/header');

		$this->response->setOutput($this->load->view('information/pricelist', $data));
	}
}

view

{{ header }}
<div id="information-sitemap" class="container">
<table class="price-list-wrapper">
	<tr>
		<th>Название</th>
		<th>Артикул</th>
		<th>Цена розн.</th>
		<th>Цена опт. от 10 шт.</th>
	</tr>
{% if products %}
	{% for product in products %}
	<tr>
		<th>{{ product.name }}</th>
		<th>{{ product.sku }}</th>
		<th>{{ product.price }}</th>
		<th>{{ product.pricedis }}</th>
	</tr>
	{% endfor %}
{% else %}
	<p>Нет товаров!</p>
{% endif %}
</table>
</div>
{{ footer }}

 

Share this post


Link to post
Share on other sites

Группировать в контроллере массив товаров с ключами по ID главной категории

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.