Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Вывод id категории товара в модуле "Рекомендуемые" OC 3


VKDanger
 Share

Recommended Posts

Приветствую!
Переписываю модуль "Рекомендуемые" ик, чтобы можно было использовать фильтрацию товаров по категориям.
Подклюлил в контроллер
 

$this->load->model('catalog/category');

 

Прописал запрос:

$query_categories = $this->model_catalog_product->getCategories($product_id);

        $categories = array();

        foreach ($query_categories as $cat) {
            $ocb_category = $this->model_catalog_category->getCategory($cat['category_id']);

            $category_info['category_id'] = $ocb_category['category_id'];
            $category_info['name'] = $ocb_category['name'];
            $category_info['thumb'] = $ocb_category['image'];
            $data['categories'][] = $category_info; 
        }
...
					$data['products'][] = array(
						'product_id'  => $product_info['product_id'],
						'category_id'  => $category_info['category_id'],
						'category_name'  => $category_info['name'],
						'category_thumb'  => $category_info['thumb'],
						'thumb'       => $image,
						'name'        => $product_info['name'],
						'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'])
					);

 

В twig шаблоне модуля вывод (название категории для наглядности):

{% if (categories) %} 
    {% for category in categories %} 
        {% if category.category_id %} 
         {{category.name}}
         {{category.category_id}}
        {% endif %}
		<br>
    {% endfor %} 
{% endif %}	

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

 

Подскажите, знатоки, как выводить в каждой карточке ТОЛЬКО соответствующую категорию (у одного товара только одна категория)?
Чувствую, что должно быть изящное решение, но кто-то на плече нашёптывает гделать костыли, спасайте! =)

 

Link to comment
Share on other sites


  • 1 year later...

 

В 14.05.2019 в 13:38, VKDanger сказал:

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

Как решили этот вопрос?

Edited by Blackseabreathe
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

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.