Jump to content

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

Recommended Posts

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



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

$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 %} 
        {% endif %}
    {% endfor %} 
{% endif %}	

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


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



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.

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.