Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Категории с выводом товара


Recommended Posts

Здравствуйте, подскажите пж нужно в категории вывести один товар http://joxi.ru/J2bJwjNh4Qw0N2. Пробовал вывести через рекомендуемые добавив один товар http://joxi.ru/L213kVpu6YnO1r но как его вывести что бы для разных категорий разный товар по id рекомендуемого товара. Как вывести товар?

 

1. Cоздал файл catalog/controller/common/feat.php

<?php
class ControllerCommonFeat extends Controller {
    public function index() {
        $this->load->model('design/layout');
 
        if (isset($this->request->get['route'])) {
            $route = (string)$this->request->get['route'];
        } else {
            $route = 'common/home';
        }
 
        $layout_id = 0;
 
        if ($route == 'product/category' && isset($this->request->get['path'])) {
            $this->load->model('catalog/category');
 
            $path = explode('_', (string)$this->request->get['path']);
 
            $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
        }
 
        if ($route == 'product/product' && isset($this->request->get['product_id'])) {
            $this->load->model('catalog/product');
 
            $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
        }
 
        if ($route == 'information/information' && isset($this->request->get['information_id'])) {
            $this->load->model('catalog/information');
 
            $layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
        }
 
        if (!$layout_id) {
            $layout_id = $this->model_design_layout->getLayout($route);
        }
 
        if (!$layout_id) {
            $layout_id = $this->config->get('config_layout_id');
        }
 
        $data['modules'] = array();
 
        $modules = $this->model_design_layout->getLayoutModules($layout_id, 'feat');
 
        foreach ($modules as $module) {
            $part = explode('.', $module['code']);
 
            if (isset($part[0]) && $this->config->get($part[0] . '_status')) {
                $data['modules'][] = $this->load->controller('module/' . $part[0]);
            }
 
            if (isset($part[1])) {
                $setting_info = $this->model_extension_module->getModule($part[1]);
 
                if ($setting_info && $setting_info['status']) {
                    $data['modules'][] = $this->load->controller('module/' . $part[0], $setting_info);
                }
            }
        }
 
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/feat.tpl')) {
            return $this->load->view($this->config->get('config_template') . '/template/common/feat.tpl', $data);
        } else {
            return $this->load->view('default/template/common/feat.tpl', $data);
        }
    }
}

 

2. Создал шаблон для вывода модуля в новой позиции catalog/view/theme/тема/template/module/feat.tpl


<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>

 

3. В файле catalog/controller/module/category_menu.php (куда в этом файле вставить $data['content_newpos'] =  $this->load->controller('common/content_newpos');)

 

<?php
class ControllerModuleCategoryMenu extends Controller {
private $cache_data = null;
 
public function index($settings) {
$this->cache_data = $this->cache->get('category_menu');
if (!$this->cache_data) {
$this->cache_data = array();
}
 
if($settings['style'] == 1){
$tpl_name = "category_menu";
$this->document->addScript('catalog/view/javascript/category_menu.js');
}else{
$tpl_name = "category_menu_vertical";
}
 
if (file_exists('catalog/view/theme/' . $this->config->get('config_template') . '/css/'.$tpl_name.'.css')) {
$this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/css/'.$tpl_name.'.css');
} else {
$this->document->addStyle('catalog/view/theme/default/css/'.$tpl_name.'.css');
}
 
 
$this->language->load('module/category_menu');
$this->load->model('tool/image');
 
    $data['heading_title'] = $this->language->get('heading_title');
        
        
        if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
 
if (isset($parts[0])) {
$data['category_id'] = 60;
} else {
$data['category_id'] = 60;
}
 
if (isset($parts[1])) {
$data['child_id'] = $parts[1];
} else {
$data['child_id'] = 0;
}
        
 
$this->load->model('catalog/category');
$this->load->model('catalog/product');
 
$data['categories'] = array();
 
$categories = $this->model_catalog_category->getCategories(0);
 
foreach ($categories as $category) {
if($settings['category_count'] == 1){
if (!isset($this->cache_data['count'][$category['category_id']])) {
$total = $this->model_catalog_product->getTotalProducts(array('filter_category_id'  => $category['category_id'], 'filter_sub_category' => true));
$this->cache_data['count'][$category['category_id']] = $total;
}else{
$total = $this->cache_data['count'][$category['category_id']];
}
}
 
$children_data = array();
            if( $settings['level'] > 1){
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
 
if($settings['child_count'] == 1){
if (!isset($this->cache_data['count'][$child['category_id']])) {
$data = array(
'filter_category_id'  => $child['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$this->cache_data['count'][$child['category_id']] = $product_total;
}else{
$product_total = $this->cache_data['count'][$child['category_id']];
}
}
 
 
$subchildren_data = array();
if($settings['level'] > 2){
$subchildren = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($subchildren as $subchild) {
 
if($settings['subchild_count'] == 1){
if (!isset($this->cache_data['count'][$subchild['category_id']])) {
$subdata = array(
'filter_category_id'  => $subchild['category_id'],
'filter_sub_category' => true
);
$subproduct_total = $this->model_catalog_product->getTotalProducts($subdata);
$this->cache_data['count'][$subchild['category_id']] = $subproduct_total;
}else{
$subproduct_total = $this->cache_data['count'][$subchild['category_id']];
}
}
 
$subchildren_data[] = array(
'category_id' => $subchild['category_id'],
'name'  => $subchild['name'] . ($settings['subchild_count'] ? ' (' . $subproduct_total . ')' : ''),
'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'] . '_' . $subchild['category_id']),
'image' => ($settings['subchild_images']['status'] ? $this->model_tool_image->resize($subchild['image'], $settings['subchild_images']['width'], $settings['subchild_images']['height']) : false)
);
}
}
 
$children_data[] = array(
'category_id' => $child['category_id'],
'name'        => $child['name'] . ($settings['child_count'] ? ' (' . $product_total . ')' : ''),
'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']),
'image'     => ($settings['child_images']['status'] ? $this->model_tool_image->resize($child['image'], $settings['child_images']['width'], $settings['child_images']['height']) : false),
'subchildren' => $subchildren_data,
'column'   => $child['column'] ? $child['column'] : 1,
);
}
}
 
$data['categories'][] = array(
'category_id' => $category['category_id'],
'name'        => $category['name'] . ($settings['category_count'] ? ' (' . $total . ')' : ''),
'href'        => $this->url->link('product/category', 'path=' . $category['category_id']),
'image'  => ($settings['category_images']['status'] ? $this->model_tool_image->resize($category['image'], $settings['category_images']['width'], $settings['category_images']['height']) : false),
'children'    => $children_data,
'column'   => $category['column'] ? $category['column'] : 1,
);
}
 
if($this->cache_data){
$this->cache->set('category_menu', $this->cache_data);
}
 
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/'.$tpl_name.'.tpl')) {
return $this->load->view($this->config->get('config_template').'/template/module/'.$tpl_name.'.tpl', $data);
} else {
return $this->load->view('default/template/module/'.$tpl_name.'.tpl', $data);
}
  }
 
}
?>

 

4. catalog/view/theme/тема/template/module/category_menu_vertical.tpl и в нужном месте добавляю

<?php echo $feat; ?>

 

Надіслати
Поділитися на інших сайтах


Здравствуйте, подскажите пж нужно в категории вывести один товар http://joxi.ru/J2bJwjNh4Qw0N2. Пробовал вывести через рекомендуемые добавив один товар http://joxi.ru/L213kVpu6YnO1r но как его вывести что бы для разных категорий разный товар по id рекомендуемого товара. Как вывести товар?

 

1. Cоздал файл catalog/controller/common/feat.php

<?php
class ControllerCommonFeat extends Controller {
    public function index() {
        $this->load->model('design/layout');
 
        if (isset($this->request->get['route'])) {
            $route = (string)$this->request->get['route'];
        } else {
            $route = 'common/home';
        }
 
        $layout_id = 0;
 
        if ($route == 'product/category' && isset($this->request->get['path'])) {
            $this->load->model('catalog/category');
 
            $path = explode('_', (string)$this->request->get['path']);
 
            $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
        }
 
        if ($route == 'product/product' && isset($this->request->get['product_id'])) {
            $this->load->model('catalog/product');
 
            $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
        }
 
        if ($route == 'information/information' && isset($this->request->get['information_id'])) {
            $this->load->model('catalog/information');
 
            $layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
        }
 
        if (!$layout_id) {
            $layout_id = $this->model_design_layout->getLayout($route);
        }
 
        if (!$layout_id) {
            $layout_id = $this->config->get('config_layout_id');
        }
 
        $data['modules'] = array();
 
        $modules = $this->model_design_layout->getLayoutModules($layout_id, 'feat');
 
        foreach ($modules as $module) {
            $part = explode('.', $module['code']);
 
            if (isset($part[0]) && $this->config->get($part[0] . '_status')) {
                $data['modules'][] = $this->load->controller('module/' . $part[0]);
            }
 
            if (isset($part[1])) {
                $setting_info = $this->model_extension_module->getModule($part[1]);
 
                if ($setting_info && $setting_info['status']) {
                    $data['modules'][] = $this->load->controller('module/' . $part[0], $setting_info);
                }
            }
        }
 
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/feat.tpl')) {
            return $this->load->view($this->config->get('config_template') . '/template/common/feat.tpl', $data);
        } else {
            return $this->load->view('default/template/common/feat.tpl', $data);
        }
    }
}

 

2. Создал шаблон для вывода модуля в новой позиции catalog/view/theme/тема/template/module/feat.tpl

<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>

 

3. В файле catalog/controller/module/category_menu.php (куда в этом файле вставить $data['content_newpos'] =  $this->load->controller('common/content_newpos');)

 

<?php
class ControllerModuleCategoryMenu extends Controller {
private $cache_data = null;
 
public function index($settings) {
$this->cache_data = $this->cache->get('category_menu');
if (!$this->cache_data) {
$this->cache_data = array();
}
 
if($settings['style'] == 1){
$tpl_name = "category_menu";
$this->document->addScript('catalog/view/javascript/category_menu.js');
}else{
$tpl_name = "category_menu_vertical";
}
 
if (file_exists('catalog/view/theme/' . $this->config->get('config_template') . '/css/'.$tpl_name.'.css')) {
$this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/css/'.$tpl_name.'.css');
} else {
$this->document->addStyle('catalog/view/theme/default/css/'.$tpl_name.'.css');
}
 
 
$this->language->load('module/category_menu');
$this->load->model('tool/image');
 
    $data['heading_title'] = $this->language->get('heading_title');
        
        
        if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
} else {
$parts = array();
}
 
if (isset($parts[0])) {
$data['category_id'] = 60;
} else {
$data['category_id'] = 60;
}
 
if (isset($parts[1])) {
$data['child_id'] = $parts[1];
} else {
$data['child_id'] = 0;
}
        
 
$this->load->model('catalog/category');
$this->load->model('catalog/product');
 
$data['categories'] = array();
 
$categories = $this->model_catalog_category->getCategories(0);
 
foreach ($categories as $category) {
if($settings['category_count'] == 1){
if (!isset($this->cache_data['count'][$category['category_id']])) {
$total = $this->model_catalog_product->getTotalProducts(array('filter_category_id'  => $category['category_id'], 'filter_sub_category' => true));
$this->cache_data['count'][$category['category_id']] = $total;
}else{
$total = $this->cache_data['count'][$category['category_id']];
}
}
 
$children_data = array();
            if( $settings['level'] > 1){
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
 
if($settings['child_count'] == 1){
if (!isset($this->cache_data['count'][$child['category_id']])) {
$data = array(
'filter_category_id'  => $child['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$this->cache_data['count'][$child['category_id']] = $product_total;
}else{
$product_total = $this->cache_data['count'][$child['category_id']];
}
}
 
 
$subchildren_data = array();
if($settings['level'] > 2){
$subchildren = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($subchildren as $subchild) {
 
if($settings['subchild_count'] == 1){
if (!isset($this->cache_data['count'][$subchild['category_id']])) {
$subdata = array(
'filter_category_id'  => $subchild['category_id'],
'filter_sub_category' => true
);
$subproduct_total = $this->model_catalog_product->getTotalProducts($subdata);
$this->cache_data['count'][$subchild['category_id']] = $subproduct_total;
}else{
$subproduct_total = $this->cache_data['count'][$subchild['category_id']];
}
}
 
$subchildren_data[] = array(
'category_id' => $subchild['category_id'],
'name'  => $subchild['name'] . ($settings['subchild_count'] ? ' (' . $subproduct_total . ')' : ''),
'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'] . '_' . $subchild['category_id']),
'image' => ($settings['subchild_images']['status'] ? $this->model_tool_image->resize($subchild['image'], $settings['subchild_images']['width'], $settings['subchild_images']['height']) : false)
);
}
}
 
$children_data[] = array(
'category_id' => $child['category_id'],
'name'        => $child['name'] . ($settings['child_count'] ? ' (' . $product_total . ')' : ''),
'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']),
'image'     => ($settings['child_images']['status'] ? $this->model_tool_image->resize($child['image'], $settings['child_images']['width'], $settings['child_images']['height']) : false),
'subchildren' => $subchildren_data,
'column'   => $child['column'] ? $child['column'] : 1,
);
}
}
 
$data['categories'][] = array(
'category_id' => $category['category_id'],
'name'        => $category['name'] . ($settings['category_count'] ? ' (' . $total . ')' : ''),
'href'        => $this->url->link('product/category', 'path=' . $category['category_id']),
'image'  => ($settings['category_images']['status'] ? $this->model_tool_image->resize($category['image'], $settings['category_images']['width'], $settings['category_images']['height']) : false),
'children'    => $children_data,
'column'   => $category['column'] ? $category['column'] : 1,
);
}
 
if($this->cache_data){
$this->cache->set('category_menu', $this->cache_data);
}
 
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/'.$tpl_name.'.tpl')) {
return $this->load->view($this->config->get('config_template').'/template/module/'.$tpl_name.'.tpl', $data);
} else {
return $this->load->view('default/template/module/'.$tpl_name.'.tpl', $data);
}
  }
 
}
?>

 

4. catalog/view/theme/тема/template/module/category_menu_vertical.tpl и в нужном месте добавляю

<?php echo $feat; ?>

 

 

Попробуйте реализовать так:

https://opencartforum.com/topic/5312-kak-vyvesti-modul-samoe-populiarnoe-na-404/?do=findComment&comment=35298#entry35298

Змінено користувачем designa
Надіслати
Поділитися на інших сайтах


Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку
×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.