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

Главное меню, добавление пункта "Новинки" (Latest Products Page)


Recommended Posts

По мотивам Latest Products Page пытаюсь сделать для версии 1.3.2

Исходный код

<?php
    class ControllerProductLatest extends Controller {    
       public function index() {
           $this->language->load('product/latest');
             
           $this->document->title = $this->language->get('heading_title');

          $this->document->breadcrumbs = array();

             $this->document->breadcrumbs[] = array(
                 'href'      => HTTP_SERVER . 'index.php?route=common/home',
                 'text'      => $this->language->get('text_home'),
                'separator' => FALSE
             );

          $url = '';
          
          if (isset($this->request->get['sort'])) {
             $url .= '&sort=' . $this->request->get['sort'];
          }   

          if (isset($this->request->get['order'])) {
             $url .= '&order=' . $this->request->get['order'];
          }
                
          if (isset($this->request->get['page'])) {
             $url .= '&page=' . $this->request->get['page'];
          }   
             
             $this->document->breadcrumbs[] = array(
                 'href'      => HTTP_SERVER . 'index.php?route=product/latest' . $url,
                 'text'      => $this->language->get('heading_title'),
                'separator' => $this->language->get('text_separator')
             );
          
           $this->data['heading_title'] = $this->language->get('heading_title');
       
          $this->data['text_sort'] = $this->language->get('text_sort');
             
            if (isset($this->request->get['page'])) {
             $page = $this->request->get['page'];
          } else {
             $page = 1;
          }

          if (isset($this->request->get['sort'])) {
             $sort = $this->request->get['sort'];
          } else {
             $sort = 'pd.name';
          }

          if (isset($this->request->get['order'])) {
             $order = $this->request->get['order'];
          } else {
             $order = 'ASC';
          }
       
          $this->load->model('catalog/product');
             

             $url = '';
                
             $this->load->model('catalog/review');
             $this->load->model('tool/seo_url');
             $this->load->model('tool/image');
                
                 $this->data['products'] = array();
                
             $results = $this->model_catalog_product->getLatestProducts($this->config->get('config_catalog_limit'));

                  
             foreach ($results as $result) {
             if ($result['image']) {
                $image = $result['image'];
             } else {
                $image = 'no_image.jpg';
             }
             
             $rating = $this->model_catalog_review->getAverageRating($result['product_id']);   

             $special = FALSE;
             
             $discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
             
             if ($discount) {
                $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
             } else {
                $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
             
                $special = $this->model_catalog_product->getProductSpecial($result['product_id']);
             
                if ($special) {
                   $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
                }                  
             }
             
             $this->data['products'][] = array(                                  
                'name'    => $result['name'],
                'price'   => $price,
                'special' => $special,
                'thumb'   => $this->model_tool_image->resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
                'href'    => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id'])
             );
          }


             if (!$this->config->get('config_customer_price')) {
                $this->data['display_price'] = TRUE;
             } elseif ($this->customer->isLogged()) {
                $this->data['display_price'] = TRUE;
             } else {
                $this->data['display_price'] = FALSE;
             }

             $url = '';

             if (isset($this->request->get['page'])) {
                $url .= '&page=' . $this->request->get['page'];
             }   
                
             $this->data['sorts'] = array();
                
             $this->data['sorts'][] = array(
                'text'  => $this->language->get('text_name_asc'),
                'value' => 'pd.name',
                'href'  => HTTP_SERVER . 'index.php?route=product/latest' . $url . '&sort=pd.name'
             );

             $this->data['sorts'][] = array(
                'text'  => $this->language->get('text_name_desc'),
                'value' => 'pd.name-DESC',
                'href'  => HTTP_SERVER . 'index.php?route=product/latest' . $url . '&sort=pd.name&order=DESC'
             ); 

             $this->data['sorts'][] = array(
                'text'  => $this->language->get('text_price_asc'),
                'value' => 'latest-ASC',
                'href'  => HTTP_SERVER . 'index.php?route=product/latest' . $url . '&sort=latest&order=ASC'
             );

             $this->data['sorts'][] = array(
                'text'  => $this->language->get('text_price_desc'),
                'value' => 'latest-DESC',
                'href'  => HTTP_SERVER . 'index.php?route=product/latest' . $url . '&sort=latest&order=DESC'
             );
                
                
             $url = '';

             if (isset($this->request->get['sort'])) {
                $url .= '&sort=' . $this->request->get['sort'];
             }   

             if (isset($this->request->get['order'])) {
                $url .= '&order=' . $this->request->get['order'];
             }
                
             //$pagination = new Pagination();
             //$pagination->total = $product_total;
             //$pagination->page = $page;
             //$pagination->limit = $this->config->get('config_catalog_limit');
             //$pagination->text = $this->language->get('text_pagination');
             //$pagination->url = HTTP_SERVER . 'index.php?route=product/latest' . $url . '&page={page}';
                
             //$this->data['pagination'] = $pagination->render();
                
             $this->data['sort'] = $sort;
             $this->data['order'] = $order;

             if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/latest.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/product/latest.tpl';
             } else {
                $this->template = 'default/template/product/latest.tpl';
             }
             
             $this->children = array(
                'common/header',
                'common/footer',
                'common/column_left',
                'common/column_right'
             );
          
             $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));         
          
         }
    }
    ?>
Подправил где надо синтаксис для старой версии

'href'      => $this->url->http('
Массив товаров у меня не products a latest

$this->data['latest'][] = array(

Делал по аналогии с выводом списка новинок на главной через модуль controller/module/latest.php

<?php
// Latest Products Module by Fido-X (http://www.fido-x.net)
class ControllerModuleLatest extends Controller {
	protected function index() {
		$this->load->language('module/latest');

		if ($this->config->get('latest_position') == 'homepage') {
			$this->data['homepage'] = 'TRUE';
		}

     	$this->data['heading_title'] = $this->language->get('heading_title');

		$this->load->model('catalog/product');
		$this->load->model('catalog/review');
		$this->load->model('tool/seo_url');

		$this->load->helper('image');

		$this->data['latest'] = array();

		foreach ($this->model_catalog_product->getLatestProducts($this->config->get('latest_limit')) as $result) {
			if ($result['image']) {
				$image = $result['image'];
			} else {
				$image = 'no_image.jpg';
			}

			if ($this->config->get('latest_position') == 'homepage') {
				$thumb = image_resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
			} else {
				$thumb = image_resize($image, 38, 38);
			}

			$rating = $this->model_catalog_review->getAverageRating($result['product_id']);

			$special = FALSE;

			$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);

			if ($discount) {
				$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
			} else {
				$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));

				$special = $this->model_catalog_product->getProductSpecial($result['product_id']);

				if ($special) {
					$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
				}
			}

			$this->data['latest'][] = array(
				'name'    => $result['name'],
				'model'   => $result['model'],
				'rating'  => $rating,
				'stars'   => sprintf($this->language->get('text_stars'), $rating),
				'thumb'   => $thumb,
				'price'   => $price,
				'special' => $special,
				'href'    => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id']))
			);
		}

		if (!$this->config->get('config_customer_price')) {
			$this->data['display_price'] = TRUE;
		} elseif ($this->customer->isLogged()) {
			$this->data['display_price'] = TRUE;
		} else {
			$this->data['display_price'] = FALSE;
		}

		$this->id       = 'latest';
		$this->template = $this->config->get('config_template') . 'module/latest.tpl';
		$this->render();
	}
}
?>

Нужна сортировка и вывод постранично.

На сейчас надпись кнопки "Новинки" пропадает при нажатии на любую другую и остается дефолтная надпись "text_latest"

вывод товара происходит на отдельной пустой странице без разделителей стилей и сортировки, а надо как "Специальные предложения" и "Рекомендуем" в home_page

Подскажите правильный код latest.php для дирректории /controller/product/

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


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

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

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

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

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

Вхід

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

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

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

×
×
  • Створити...

Important Information

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