Hi all,
Just starting to play arround with open cart and things are pretty much straight forward however, one thing is making me scratch my head.
Is it possible to have a latest products page (like the specials page) showing the last few products.
I have searched and someone has asked the question but with no replies.
Thanks
Just starting to play arround with open cart and things are pretty much straight forward however, one thing is making me scratch my head.
Is it possible to have a latest products page (like the specials page) showing the last few products.
I have searched and someone has asked the question but with no replies.
Thanks
Last edited by kroozing on Thu Apr 29, 2010 4:30 am, edited 1 time in total.
There is, by default, a Latest product module in a default 1.4.7 install.
Norman in 't Veldt
Moderator OpenCart Forums
_________________ READ and Search BEFORE POSTING _________________
Our FREE search: Find your answer FAST!.
[How to] BTW + Verzend + betaal setup.
The link now works with no errors however, there are no products shown even thought the latest products module shows results.
Would it be something to do with $this->model_catalog_product->getTotalProductSpecials();
here is my controller/product/latest.php
Would it be something to do with $this->model_catalog_product->getTotalProductSpecials();
here is my controller/product/latest.php
Code: Select all
<?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');
$product_total = $this->model_catalog_product->getTotalProductSpecials();
if ($product_total) {
$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($sort, $order, ($page - 1) * $this->config->get('config_catalog_limit'), $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']);
$this->data['products'][] = array(
'name' => $result['name'],
'model' => $result['model'],
'rating' => $rating,
'stars' => sprintf($this->language->get('text_stars'), $rating),
'thumb' => $this->model_tool_image->resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
'price' => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
'special' => $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))),
'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product' . $url . '&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'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_rating_desc'),
'value' => 'rating-DESC',
'href' => HTTP_SERVER . 'index.php?route=product/latest' . $url . '&sort=rating&order=DESC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_rating_asc'),
'value' => 'rating-ASC',
'href' => HTTP_SERVER . 'index.php?route=product/latest' . $url . '&sort=rating&order=ASC'
);
$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'));
} else {
$this->data['text_error'] = $this->language->get('text_empty');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
} else {
$this->template = 'default/template/error/not_found.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'));
}
}
}
?>
change
$results = $this->model_catalog_product->getLatestProducts($sort, $order, ($page - 1) * $this->config->get('config_catalog_limit'), $this->config->get('config_catalog_limit'));
to
$results = $this->model_catalog_product->getLatestProducts($this->config->get('config_catalog_limit'));
At this time, the LatestProducts function wasn't designed to have pagination.. just a single limit.
$results = $this->model_catalog_product->getLatestProducts($sort, $order, ($page - 1) * $this->config->get('config_catalog_limit'), $this->config->get('config_catalog_limit'));
to
$results = $this->model_catalog_product->getLatestProducts($this->config->get('config_catalog_limit'));
At this time, the LatestProducts function wasn't designed to have pagination.. just a single limit.
Thanks loads, that worked a treat.
I Seem to have a problem with line 90 saying that i have Undefined index: special
'special' => $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))),
If tried the code from the module but the error still shows with no special price
Many thanks
I Seem to have a problem with line 90 saying that i have Undefined index: special
'special' => $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))),
If tried the code from the module but the error still shows with no special price
Many thanks
I have managed to fix it, For anyone else wanting a latest products page i have attached the code needed.
First file catalog/controller/product/latest.php
The second file /catalog/language/english/product/latest.php
And the 3rd file /catalog/view/theme/default/template/product/latest.tpl
First file catalog/controller/product/latest.php
Code: Select all
<?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'));
}
}
?>
Code: Select all
<?php
// Heading
$_['heading_title'] = 'Latest products';
// Text
$_['text_empty'] = 'There are no new products to list.';
$_['text_sort'] = 'Sort By:';
$_['text_name_asc'] = 'Name A - Z';
$_['text_name_desc'] = 'Name Z - A';
$_['text_price_asc'] = 'Price Low > High';
$_['text_price_desc'] = 'Price High < Low';
?>
Code: Select all
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content">
<div class="top">
<div class="left"></div>
<div class="right"></div>
<div class="center">
<h1><?php echo $heading_title; ?></h1>
</div>
</div>
<div class="middle">
<div class="sort">
<div class="div1">
<select name="sort" onchange="location = this.value">
<?php foreach ($sorts as $sorts) { ?>
<?php if (($sort . '-' . $order) == $sorts['value']) { ?>
<option value="<?php echo str_replace('&', '&', $sorts['href']); ?>" selected="selected"><?php echo $sorts['text']; ?></option>
<?php } else { ?>
<option value="<?php echo str_replace('&', '&', $sorts['href']); ?>"><?php echo $sorts['text']; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="div2"><?php echo $text_sort; ?></div>
</div>
<table class="list">
<?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?>
<tr>
<?php for ($j = $i; $j < ($i + 4); $j++) { ?>
<td width="25%"><?php if (isset($products[$j])) { ?>
<a href="<?php echo str_replace('&', '&', $products[$j]['href']); ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" /></a><br />
<a href="<?php echo str_replace('&', '&', $products[$j]['href']); ?>"><?php echo $products[$j]['name']; ?></a><br />
<?php if ($display_price) { ?>
<?php if (!$products[$j]['special']) { ?>
<span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span><br />
<?php } else { ?>
<span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
<?php } ?>
<?php } ?>
<?php } ?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div>
<div class="bottom">
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</div>
</div>
<?php echo $footer; ?>
sample? or package!?!?
توسعه اپن کارت
طراحی نرم افزارهای مبتنی بر اپن کارت - امنیت/توسعه اختصاصی/خدمات سئو/ سیستم تیکت و فروش بلیط/مدیر سمینار و همایش
اتصال اپن کارت به نرم افزارهای انبار داری و انواع CRM و ERP و دستگاه پوز و پرینتر
https://www.imahmoudi.ir
https://www.opencart.com/index.php?rout ... @gmail.com
engchum I installed this.... http://www.opencart.com/index.php?route ... 050&page=4
Well worth the money
Well worth the money
Please help update code latest.php for old version 1.3.2
1. replace with
2. replace
how to update code latest.php from the module latest product FIDO-X.NET for the controller/product
1. replace
Code: Select all
'href' => HTTP_SERVER . 'index.php?route
Code: Select all
'href' => $this->url->http('
Code: Select all
$this->data['products'] = array();
Code: Select all
$this->data['latest'] = array();
Code: Select all
<?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();
}
}
?>
hi,
I do this all in upper posts and i have some errors in my shop:
http://www.sklep.e-budowanie.com/index. ... uct/latest
and i have a some questions:
- how to display all products or concrete number products ?
- how to display bestsellers in one page ?
- how to display featured in one page ?
I need some help
thanks for helps
----------edit------------
my opencart version 1.4.9.4
I do this all in upper posts and i have some errors in my shop:
http://www.sklep.e-budowanie.com/index. ... uct/latest
and i have a some questions:
- how to display all products or concrete number products ?
- how to display bestsellers in one page ?
- how to display featured in one page ?
I need some help
thanks for helps
----------edit------------
my opencart version 1.4.9.4
Who is online
Users browsing this forum: Ahrefs [Bot] and 133 guests