Post by jerome » Sat Jul 24, 2010 9:41 pm


Newbie

Posts

Joined
Fri Jul 23, 2010 6:27 am

Post by ncc50446@hotmail.com » Wed Jul 28, 2010 12:34 am

Go to catalog/controller/product/category.php

Find

Code: Select all

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

Code: Select all

if (isset($this->request->get['sort'])) {
                $sort = $this->request->get['sort'];
            } else {
                $sort = 'p.date_added'; //Can also do by p.date_modified
            } 
Find

Code: Select all

if (isset($this->request->get['order'])) {
                $order = $this->request->get['order'];
            } else {
                $order = 'ASC';
            } 
Change to

Code: Select all

if (isset($this->request->get['order'])) {
                $order = $this->request->get['order'];
            } else {
                $order = 'DESC';
            } 
Find

Code: Select all

$this->data['sorts'][] = array(
                    'text'  => $this->language->get('text_name_asc'),
                    'value' => 'pd.name-ASC',
                    'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC')
                ); 
Add before

Code: Select all

$this->data['sorts'][] = array(
                    'text'  => $this->language->get('text_date_desc'),
                    'value' => 'p.date_added-DESC',
                    'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.date_added&order=DESC')
                );
 
                $this->data['sorts'][] = array(
                    'text'  => $this->language->get('text_date_asc'),
                    'value' => 'p.date_added-ASC',
                    'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.date_added&order=ASC')
                ); 
Go to catalog/language/english/product/category.php
Add

Code: Select all

$_['text_date_desc']= 'Newest > Oldest';
$_['text_date_asc']    = 'Oldest > Newest'; 
Go to catalog/model/catalog/product.php
Find

Code: Select all

$sort_data = array( 
Add into the array, at the end

Code: Select all

'p.date_added' 
I think that's all of it :)

Edit: Forgot about model


Posts

Joined
Sat Mar 13, 2010 10:23 am

Post by jerome » Wed Jul 28, 2010 4:44 am

this is not working in 1.4.8b. i cant find "$sort = 'pd.name';".
catalog/controller/product/category.php (original 1.4.8b codes).

Code: Select all

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

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

Newbie

Posts

Joined
Fri Jul 23, 2010 6:27 am

Post by Maio » Wed Aug 04, 2010 8:38 am

yes that working.. $sort = "pd.name; " around line 190 fine it with notepad++

this is the example http://www.sanfashions.com

New member

Posts

Joined
Wed Aug 04, 2010 8:35 am
Location - Indonesia

Post by manson » Sun Dec 12, 2010 11:24 pm

i can't find the codes in OC 1.4.9.2. can some1 show me the coding for 1.4.9.2? here's my catalog/controller/product/category.php

Code: Select all

<?php 
class ControllerProductCategory extends Controller {  
	public function index() { 
		$this->language->load('product/category');
	
		$this->document->breadcrumbs = array();

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

		$this->load->model('catalog/category');
		$this->load->model('tool/seo_url');  
		
		if (isset($this->request->get['path'])) {
			$path = '';
		
			$parts = explode('_', $this->request->get['path']);
		
			foreach ($parts as $path_id) {
				$category_info = $this->model_catalog_category->getCategory($path_id);
				
				if ($category_info) {
					if (!$path) {
						$path = $path_id;
					} else {
						$path .= '_' . $path_id;
					}

	       			$this->document->breadcrumbs[] = array(
   	    				'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $path),
    	   				'text'      => $category_info['name'],
        				'separator' => $this->language->get('text_separator')
        			);
				}
			}		
		
			$category_id = array_pop($parts);
		} else {
			$category_id = 0;
		}
		
		$category_info = $this->model_catalog_category->getCategory($category_id);
	
		if ($category_info) {
	  		$this->document->title = $category_info['name'];
			
			$this->document->keywords = $category_info['meta_keywords'];
			
			$this->document->description = $category_info['meta_description'];
			
			$this->data['heading_title'] = $category_info['name'];
			
			$this->data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
			
			$this->data['text_sort'] = $this->language->get('text_sort');
			
			$this->load->model('tool/image'); 
			
			if ($category_info['image']) {
				$image = $category_info['image'];
			} else {
				$image = '';
			}

			$this->data['thumb'] = $this->model_tool_image->resize($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
			
			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 = 'p.sort_order';
			}

			if (isset($this->request->get['order'])) {
				$order = $this->request->get['order'];
			} else {
				$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'];
			}
			
			$this->load->model('catalog/product');  
						 
			$category_total = $this->model_catalog_category->getTotalCategoriesByCategoryId($category_id);
			$product_total = $this->model_catalog_product->getTotalProductsByCategoryId($category_id);
			
			if ($category_total || $product_total) {
        		$this->data['categories'] = array();
        		
				$results = $this->model_catalog_category->getCategories($category_id);
				
        		foreach ($results as $result) {
					if ($result['image']) {
						$image = $result['image'];
					} else {
						$image = 'no_image.jpg';
					}
					
					$this->data['categories'][] = array(
            			'name'  => $result['name'],
            			'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
            			'thumb' => $this->model_tool_image->resize($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'))
          			);
        		}
		
				$this->load->model('catalog/review');
				
				$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
				
				$this->data['products'] = array();
        		
				$results = $this->model_catalog_product->getProductsByCategoryId($category_id, $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';
					}
					
					if ($this->config->get('config_review')) {
						$rating = $this->model_catalog_review->getAverageRating($result['product_id']);	
					} else {
						$rating = false;
					}
 					
					$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')));
						}					
					}
			
					$options = $this->model_catalog_product->getProductOptions($result['product_id']);
					
					if ($options) {
						$add = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']);
					} else {
						$add = HTTPS_SERVER . 'index.php?route=checkout/cart&product_id=' . $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'   => $price,
            			'options' => $options,
						'special' => $special,
						'href'    => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']),
						'add'	  => $add
          			);
        		}

				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_default'),
					'value' => 'p.sort_order-ASC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC')
				);
				
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_name_asc'),
					'value' => 'pd.name-ASC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC')
				);
 
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_name_desc'),
					'value' => 'pd.name-DESC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC')
				);

				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_price_asc'),
					'value' => 'p.price-ASC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.price&order=ASC')
				); 

				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_price_desc'),
					'value' => 'p.price-DESC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.price&order=DESC')
				); 
				
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_rating_desc'),
					'value' => 'rating-DESC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=rating&order=DESC')
				); 
				
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_rating_asc'),
					'value' => 'rating-ASC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=rating&order=ASC')
				);
				
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_model_asc'),
					'value' => 'p.model-ASC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.model&order=ASC')
				);
 
				$this->data['sorts'][] = array(
					'text'  => $this->language->get('text_model_desc'),
					'value' => 'p.model-DESC',
					'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.model&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 = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . $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/category.tpl')) {
					$this->template = $this->config->get('config_template') . '/template/product/category.tpl';
				} else {
					$this->template = 'default/template/product/category.tpl';
				}	
				
				$this->children = array(
					'common/column_right',
					'common/column_left',
					'common/footer',
					'common/header'
				);
		
				$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));										
      		} else {
        		$this->document->title = $category_info['name'];
				
				$this->document->description = $category_info['meta_description'];
				
        		$this->data['heading_title'] = $category_info['name'];

        		$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';
		
				$this->data['categories'] = array();
				
				$this->data['products'] = array();
						
				if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
					$this->template = $this->config->get('config_template') . '/template/product/category.tpl';
				} else {
					$this->template = 'default/template/product/category.tpl';
				}	
				
				$this->children = array(
					'common/column_right',
					'common/column_left',
					'common/footer',
					'common/header'
				);
		
				$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
      		}
    	} else {
			$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'];
			}	
			
			if (isset($this->request->get['path'])) {	
	       		$this->document->breadcrumbs[] = array(
   	    			'href'      => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . $url),
    	   			'text'      => $this->language->get('text_error'),
        			'separator' => $this->language->get('text_separator')
        		);
			}
				
			$this->document->title = $this->language->get('text_error');

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

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

      		$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/column_right',
				'common/column_left',
				'common/footer',
				'common/header'
			);
		
			$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
		}
  	}
}
?>

I don't know much about PHP...~~
Don't know much about JQuery...~~
But I do know that I love OC!~~
and I know that if you'd guide me, what a wonderful world this would be...!~~

_________________________________________________________________
Using OC 1.4.9.2
http://www.ten2hundred.com


User avatar
New member

Posts

Joined
Mon Dec 06, 2010 6:58 pm

Post by manson » Tue Dec 14, 2010 7:32 am

anyone can help plz?

I don't know much about PHP...~~
Don't know much about JQuery...~~
But I do know that I love OC!~~
and I know that if you'd guide me, what a wonderful world this would be...!~~

_________________________________________________________________
Using OC 1.4.9.2
http://www.ten2hundred.com


User avatar
New member

Posts

Joined
Mon Dec 06, 2010 6:58 pm

Post by Maio » Wed Feb 16, 2011 5:57 pm

You can download the attachment then extract it to the catalog it will rewrite your 3 categories.php then you're done. i made it from OC 1.4.9.3, it should be work on any 1.4.9.x because nothing have been change.

!if you dont know what re you doing please find anyone have programing background or you'll messing up your site. O0

Attachments

Try with you own risk


New member

Posts

Joined
Wed Aug 04, 2010 8:35 am
Location - Indonesia

Post by sans » Sun Mar 06, 2011 5:26 pm

Maio wrote:
You can download the attachment then extract it to the catalog it will rewrite your 3 categories.php then you're done. i made it from OC 1.4.9.3, it should be work on any 1.4.9.x because nothing have been change.
Your code is wrong.

kaos jersey, jersey bola, baju bola, baju bola terbaru, baju bola murah


Active Member

Posts

Joined
Tue Dec 07, 2010 9:18 am

Post by Maio » Wed May 25, 2011 7:25 pm

Try this if this doesn't work i dont know what can make it work ???

New member

Posts

Joined
Wed Aug 04, 2010 8:35 am
Location - Indonesia

Post by icedge » Mon Jun 25, 2012 1:17 am

ICan somebody tell me how to do that in opencart 1.5.2.1 please?

New member

Posts

Joined
Sun Oct 24, 2010 2:32 am

Post by barrycorrigan » Wed Jun 19, 2013 6:19 pm

For people looking at this and finding it is not working it is most likely because of this:

Code: Select all

'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.date_added&order=DESC')
and

Code: Select all

'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.date_added&order=ASC')
These should be altered to be like this:

Code: Select all

'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.date_added&order=DESC' . $url)
and

Code: Select all

'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.date_added&order=ASC' . $url)
This worked for me anyway :-)

Newbie

Posts

Joined
Mon Jun 10, 2013 10:30 pm

Post by faisalsani » Wed Sep 11, 2013 12:21 am

These should be altered to be like this:

CODE: SELECT ALL
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.date_added&order=DESC' . $url)


and

CODE: SELECT ALL
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.date_added&order=ASC' . $url)


This worked for me anyway :-)
Yes, this is worked on .1.5.4

Web Hosting Murah Indonesia,
Domain Murah,
VPS Murah


Newbie

Posts

Joined
Mon Jul 30, 2012 9:33 pm
Location - solo

Post by faisalsani » Wed Sep 11, 2013 12:25 am

ncc50446@hotmail.com wrote:Go to catalog/controller/product/category.php

Find

Code: Select all

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

Code: Select all

if (isset($this->request->get['sort'])) {
                $sort = $this->request->get['sort'];
            } else {
                $sort = 'p.date_added'; //Can also do by p.date_modified
            }
Find

Code: Select all

if (isset($this->request->get['order'])) {
                $order = $this->request->get['order'];
            } else {
                $order = 'ASC';
            }
Change to

Code: Select all

if (isset($this->request->get['order'])) {
                $order = $this->request->get['order'];
            } else {
                $order = 'DESC';
            }
Find

Code: Select all

$this->data['sorts'][] = array(
                    'text'  => $this->language->get('text_name_asc'),
                    'value' => 'pd.name-ASC',
                    'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC')
                );
Add before

Code: Select all

$this->data['sorts'][] = array(
                    'text'  => $this->language->get('text_date_desc'),
                    'value' => 'p.date_added-DESC',
                    'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.date_added&order=DESC')
                );
 
                $this->data['sorts'][] = array(
                    'text'  => $this->language->get('text_date_asc'),
                    'value' => 'p.date_added-ASC',
                    'href'  => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.date_added&order=ASC')
                );
Go to catalog/language/english/product/category.php
Add

Code: Select all

$_['text_date_desc']= 'Newest > Oldest';
$_['text_date_asc']    = 'Oldest > Newest';
Go to catalog/model/catalog/product.php
Find

Code: Select all

$sort_data = array(
Add into the array, at the end

Code: Select all

'p.date_added'
I think that's all of it :)

Edit: Forgot about model
this is what I need! Thankyou Very much! This is worked on OC 1.5.4

Web Hosting Murah Indonesia,
Domain Murah,
VPS Murah


Newbie

Posts

Joined
Mon Jul 30, 2012 9:33 pm
Location - solo

Post by feriyanto » Sun Sep 29, 2013 6:57 am

yes that working.. $sort = "pd.name; " around line 190 fine it with editplus

this is the example http://www.chantiqbutik.com

http://www.chantiqbutik.com
http://www.jasikom.com


Newbie

Posts

Joined
Tue May 22, 2012 3:10 am

Post by clara1212 » Sun Jan 12, 2014 12:59 pm

I have solve my problem using this post,
thank you
http://www.blogbajumurah.wordpress.com

Newbie

Posts

Joined
Sun Jan 12, 2014 12:15 pm

Post by Jakub.B » Mon Jul 07, 2014 12:05 pm

Hello. How can I do this (sort products in category by latest) in OpenCart version 1.5.6 please. Thank you....

Newbie

Posts

Joined
Thu Feb 27, 2014 2:46 pm

Post by akif » Thu Dec 25, 2014 1:27 am

Followed your instructions and it did work for me too. Thanks for that.

BUT there's a problem, whenever I am on the category page, I have a message at the top most part of the page which says below:

application/x-httpd-php category.php ( PHP script text )

And I get 2 scroll bars at the right side of the window, as if there are two windows one over another.

Now, I do not know what went wrong, if it did.
Sorting thing is working perfectly fine though!

Any help will be highly appreciated.

Eagerly awaiting your response.

Thanks!

Newbie

Posts

Joined
Thu Dec 25, 2014 1:23 am

Post by iplocker » Fri Sep 09, 2016 6:02 am

Hello.
Is it possible please to have this guide for Opencart 2.2 too please?
Thanks

Active Member

Posts

Joined
Sun May 26, 2013 6:39 pm

Who is online

Users browsing this forum: No registered users and 239 guests