Post by alfaaluska » Sun Oct 19, 2014 6:00 pm

I have modify the code with error message Fatal error: Call to undefined method ControllerCommonSeoUrl::forward() in################## line 64 (on Opencart 2.0.0.0)

I have check and fix the problem, now the code tested on OPENCART 2.0.0.0 (1st Oct 2014)
The real code is not created by me, i'm just fix this.
BACKUP YOUR FILE BEFORE DO THIS.
1. Go to /public_html/catalog/controller/common/ and find seo_url.php then change the code with this one:

Code: Select all

    <?php
    class ControllerCommonSeoUrl extends Controller {
       public function index() {
          // Add rewrite to url class
          if ($this->config->get('config_seo_url')) {
             $this->url->addRewrite($this);
          }
          
          // Decode URL
          if (isset($this->request->get['_route_'])) {
             $parts = explode('/', $this->request->get['_route_']);

             $route = "";
             
             foreach ($parts as $part) {
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
                
                if ($query->num_rows) {
                   $url = explode('=', $query->row['query']);

                   if(count($url) > 1){
                   
                   if ($url[0] == 'product_id') {
                      $this->request->get['product_id'] = $url[1];
                   }
                   
                   if ($url[0] == 'category_id') {
                      if (!isset($this->request->get['path'])) {
                         $this->request->get['path'] = $url[1];
                      } else {
                         $this->request->get['path'] .= '_' . $url[1];
                      }
                   }   
                   
                   if ($url[0] == 'manufacturer_id') {
                      $this->request->get['manufacturer_id'] = $url[1];
                   }
                   
                   if ($url[0] == 'information_id') {
                      $this->request->get['information_id'] = $url[1];
                   }
                   }else{
                      $route = $url[0];
                   }
                } else {
                   $this->request->get['route'] = 'error/not_found';   
                }
             }
             
             if (isset($this->request->get['product_id'])) {
                $this->request->get['route'] = 'product/product';
             } elseif (isset($this->request->get['path'])) {
                $this->request->get['route'] = 'product/category';
             } elseif (isset($this->request->get['manufacturer_id'])) {
                $this->request->get['route'] = 'product/manufacturer/product';
             } elseif (isset($this->request->get['information_id'])) {
                $this->request->get['route'] = 'information/information';
             }else {
                $this->request->get['route'] = $route;
             }

             
			if (isset($this->request->get['route'])) {
				return new Action($this->request->get['route']);
			}
          }
       }
       
       public function rewrite($link) {
          if ($this->config->get('config_seo_url')) {
             $url_data = parse_url(str_replace('&', '&', $link));
          
             $url = '';
             
             $data = array();
          
             parse_str($url_data['query'], $data);
             
             foreach ($data as $key => $value) {
                if (($key == 'product_id') || ($key == 'manufacturer_id') || ($key == 'information_id')) {
                   $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
                
                   if ($query->num_rows) {
                      $url .= '/' . $query->row['keyword'];
                      
                      unset($data[$key]);
                   }               
                } elseif ($key == 'path') {
                   $categories = explode('_', $value);
                   
                   foreach ($categories as $category) {
                      $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
                
                      if ($query->num_rows) {
                         $url .= '/' . $query->row['keyword'];
                      }                     
                   }
                   
                   unset($data[$key]);
                }elseif ($key == 'route') {
                   $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($value) . "'");
                
                   if ($query->num_rows) {
                      $url .= '/' . $query->row['keyword'];
                      
                      unset($data[$key]);
                   }               
                }
             }
          
             if ($url) {
                unset($data['route']);
             
                $query = '';
             
                if ($data) {
                   foreach ($data as $key => $value) {
                      $query .= '&' . $key . '=' . $value;
                   }
                   
                   if ($query) {
                      $query = '?' . trim($query, '&');
                   }
                }

                return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
             } else {
                return $link;
             }
          } else {
             return $link;
          }      
       }   
    }
    ?>

2. Open your PHP My Admin, and add this one to your SQL:

Code: Select all

    INSERT INTO url_alias (query, keyword) VALUES ('common/home', '');
    INSERT INTO url_alias (query, keyword) VALUES ('account/wishlist', 'wishlist');
    INSERT INTO url_alias (query, keyword) VALUES ('account/account', 'my-account');
    INSERT INTO url_alias (query, keyword) VALUES ('checkout/cart', 'shopping-cart');
    INSERT INTO url_alias (query, keyword) VALUES ('checkout/checkout', 'checkout');
    INSERT INTO url_alias (query, keyword) VALUES ('account/login', 'login');
    INSERT INTO url_alias (query, keyword) VALUES ('account/logout', 'logout');
    INSERT INTO url_alias (query, keyword) VALUES ('account/order', 'order-history');
    INSERT INTO url_alias (query, keyword) VALUES ('account/newsletter', 'newsletter');
    INSERT INTO url_alias (query, keyword) VALUES ('product/special', 'specials');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/account', 'affiliates');
    INSERT INTO url_alias (query, keyword) VALUES ('checkout/voucher', 'gift-vouchers');
    INSERT INTO url_alias (query, keyword) VALUES ('product/manufacturer', 'brands');
    INSERT INTO url_alias (query, keyword) VALUES ('information/contact', 'contact-us');
    INSERT INTO url_alias (query, keyword) VALUES ('account/return/insert', 'request-return');
    INSERT INTO url_alias (query, keyword) VALUES ('information/sitemap', 'sitemap');
    INSERT INTO url_alias (query, keyword) VALUES ('account/forgotten', 'forgot-password');
    INSERT INTO url_alias (query, keyword) VALUES ('account/download', 'downloads');
    INSERT INTO url_alias (query, keyword) VALUES ('account/return', 'returns');
    INSERT INTO url_alias (query, keyword) VALUES ('account/transaction', 'transactions');
    INSERT INTO url_alias (query, keyword) VALUES ('account/register', ''register');
    INSERT INTO url_alias (query, keyword) VALUES ('account/recurring', ''recurring');
    INSERT INTO url_alias (query, keyword) VALUES ('product/compare', 'compare-products');
    INSERT INTO url_alias (query, keyword) VALUES ('product/search', 'search');
    INSERT INTO url_alias (query, keyword) VALUES ('account/edit', 'edit-account');
    INSERT INTO url_alias (query, keyword) VALUES ('account/password', 'change-password');
    INSERT INTO url_alias (query, keyword) VALUES ('account/address', 'address-book');
    INSERT INTO url_alias (query, keyword) VALUES ('account/reward', 'reward-points');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/edit', 'edit-affiliate-account');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/password', 'change-affiliate-password');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/payment', 'affiliate-payment-options');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/tracking', 'affiliate-tracking-code');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/transaction', 'affiliate-transactions');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/logout', 'affiliate-logout');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/forgotten', 'affiliate-forgot-password');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/register', 'create-affiliate-account');
    INSERT INTO url_alias (query, keyword) VALUES ('affiliate/login', 'affiliate-login');
What's changed?
- added new link (for Recurring Payments link)
- edit 'line 64' with default code in Opencart 2.0.0.0
If there any problems/bug i can't fix that or maybe i can :) just try it! i hope this code is work.
i'm newbie in coding, but if this code work for Opencart 2.0.0.0 i will proud for myself.

-Sorry for my bad english, because i'm Indonesian.

Newbie

Posts

Joined
Sun Oct 19, 2014 5:47 pm

Post by cara_ionutz » Wed Nov 05, 2014 12:47 am

Notice: Undefined index: query in /home/mfashion/public_html/catalog/controller/common/seo_url.php on line 77Notice: Undefined index: query in /home/mfashion/public_html/catalog/controller/common/seo_url.php on line 77Notice: Undefined index: query in /home/mfashion/public_html/catalog/controller/common/seo_url.php on line 77

Hello, Ive got this error. Can you tell me why?
thank you

Newbie

Posts

Joined
Wed Nov 05, 2014 12:45 am

Post by bhar » Fri Jan 22, 2016 1:19 am

amdev wrote:Hi, u need to modify seo_url.php controller.
I'm tried and work fine for my site.
http://www.laptop-ratings.com/

and see another link like account , checkout , login ...

oc 15x easier than 14x because it just edit 1 file.
In 14x need to edit 2 file and need to load tool/seo_url before to rewite.
But in 15x no need.

there r 2 things to do.
1. edit catalog/controller/common/seo_url.php this is my code(Backup your file before edit)

Code: Select all

<?php
class ControllerCommonSeoUrl extends Controller {
	public function index() {
		// Add rewrite to url class
		if ($this->config->get('config_seo_url')) {
			$this->url->addRewrite($this);
		}
		
		// Decode URL
		if (isset($this->request->get['_route_'])) {
			$parts = explode('/', $this->request->get['_route_']);

			$route = "";
			
			foreach ($parts as $part) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
				
				if ($query->num_rows) {
					$url = explode('=', $query->row['query']);

					if(count($url) > 1){
					
					if ($url[0] == 'product_id') {
						$this->request->get['product_id'] = $url[1];
					}
					
					if ($url[0] == 'category_id') {
						if (!isset($this->request->get['path'])) {
							$this->request->get['path'] = $url[1];
						} else {
							$this->request->get['path'] .= '_' . $url[1];
						}
					}	
					
					if ($url[0] == 'manufacturer_id') {
						$this->request->get['manufacturer_id'] = $url[1];
					}
					
					if ($url[0] == 'information_id') {
						$this->request->get['information_id'] = $url[1];
					}
					}else{
						$route = $url[0];
					}
				} else {
					$this->request->get['route'] = 'error/not_found';	
				}
			}
			
			if (isset($this->request->get['product_id'])) {
				$this->request->get['route'] = 'product/product';
			} elseif (isset($this->request->get['path'])) {
				$this->request->get['route'] = 'product/category';
			} elseif (isset($this->request->get['manufacturer_id'])) {
				$this->request->get['route'] = 'product/manufacturer/product';
			} elseif (isset($this->request->get['information_id'])) {
				$this->request->get['route'] = 'information/information';
			}else {
				$this->request->get['route'] = $route;
			}

			
			if (isset($this->request->get['route'])) {
				return $this->forward($this->request->get['route']);
			}
		}
	}
	
	public function rewrite($link) {
		if ($this->config->get('config_seo_url')) {
			$url_data = parse_url(str_replace('&', '&', $link));
		
			$url = ''; 
			
			$data = array();
		
			parse_str($url_data['query'], $data);
			
			foreach ($data as $key => $value) {
				if (($key == 'product_id') || ($key == 'manufacturer_id') || ($key == 'information_id')) {
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");
				
					if ($query->num_rows) {
						$url .= '/' . $query->row['keyword'];
						
						unset($data[$key]);
					}					
				} elseif ($key == 'path') {
					$categories = explode('_', $value);
					
					foreach ($categories as $category) {
						$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
				
						if ($query->num_rows) {
							$url .= '/' . $query->row['keyword'];
						}							
					}
					
					unset($data[$key]);
				}elseif ($key == 'route') {
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($value) . "'");
				
					if ($query->num_rows) {
						$url .= '/' . $query->row['keyword'];
						
						unset($data[$key]);
					}					
				}
			}
		
			if ($url) {
				unset($data['route']);
			
				$query = '';
			
				if ($data) {
					foreach ($data as $key => $value) {
						$query .= '&' . $key . '=' . $value;
					}
					
					if ($query) {
						$query = '?' . trim($query, '&');
					}
				}

				return $url_data['scheme'] . '://' . $url_data['host'] . (isset($url_data['port']) ? ':' . $url_data['port'] : '') . str_replace('/index.php', '', $url_data['path']) . $url . $query;
			} else {
				return $link;
			}
		} else {
			return $link;
		}		
	}	
}
?>

2.goto url_alias table (PHPmyadmin) and inset

query field = common/home(add another route ie. checkout/cart,checkout/checkout,information/sitemap,...)
keyword = home(or u need).

See my attach file.


I don't see common/home in phpmyadmin tab ? I'm using Version 1.5.6.4

Sorry for my bad english.

Good luck sir. :) :) :)

Active Member

Posts

Joined
Mon Jul 07, 2014 7:22 pm


Post by AbeMark » Tue Mar 21, 2017 3:59 pm

this code not fully working on OC 2.3.0.2.

anyone can help?

Newbie

Posts

Joined
Wed Mar 15, 2017 11:57 am

Post by nootkan » Tue Jul 30, 2024 4:26 am

Just made this work on v1.5.6.5rc but had to add oc_url_alias to allow for table names in my database in case the sql didn't work for anyone. Make sure to clear cookies, history etc after to see results. What a great mod!

New member

Posts

Joined
Mon May 26, 2014 5:21 am
Who is online

Users browsing this forum: mihai.stnc and 10 guests