Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

Свой вид урлов


Recommended Posts

Всем привет. Есть такая задача, нужно сделать урлы следующего вида:

1) для категорий: domen.ru/category/halaty.html

2) для товаров: domen.ru/product/473-halat-tilli-malina.html

Такое как-нибудь можно исполнить? Заранее спасибо.

Edited by abonnent
Link to post
Share on other sites
10 минут назад, buslikdrev сказал:

Если Seo_pro установлен, то возможно, возможно и без него, только нагрузка будет на БД (в сео-про кэшируется это дело).

сео про есть, но как это сделать?

можешь объяснить?

Link to post
Share on other sites
41 минуту назад, abonnent сказал:

Такое как-нибудь можно исполнить? Заранее спасибо.

легко

 

http://shalash.slasoft.kharkov.ua/product/258

http://shalash.slasoft.kharkov.ua/catalog/viski/

Только не надо спрашивать - как, проще и быстрее - сразу в личку.

Link to post
Share on other sites
12 минут назад, buslikdrev сказал:


В сео_про вместо этого

  Скрыть контент


        $seo_url = $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '/' ) . '' . $seo_url;


Вставить это:

  Скрыть контент

        $category_path = ($route == 'product/category' ? (!empty($this->cache_data['queries']['product/category']) ? '/' . $this->cache_data['queries']['product/category'] : '/category') : false);
        
        $seo_url = $url_info['scheme'] . '://' . $url_info['host'] . $category_path . (isset($url_info['port']) ? ':' . $url_info['port'] : '/' ) . '' . $seo_url;


Если в сео менеджере не указать короткое урл, то будет стандарт /category

а в плагине для опенкарта это как сделать не знаете?

Link to post
Share on other sites
<?php
class ControllerStartupSeoPro extends Controller {
	private $cache_data = null;

	public function __construct($registry) {
		parent::__construct($registry);
		$this->cache_data = $this->cache->get('seo_pro');
		if (!$this->cache_data) {
			$query = $this->db->query("SELECT LOWER(`keyword`) as 'keyword', `query` FROM " . DB_PREFIX . "url_alias ORDER BY url_alias_id");
			$this->cache_data = array();
			foreach ($query->rows as $row) {
				if (isset($this->cache_data['keywords'][$row['keyword']])){
					$this->cache_data['keywords'][$row['query']] = $this->cache_data['keywords'][$row['keyword']];
					continue;
				}
				$this->cache_data['keywords'][$row['keyword']] = $row['query'];
				$this->cache_data['queries'][$row['query']] = $row['keyword'];
			}
			$this->cache->set('seo_pro', $this->cache_data);
		}
	}

	public function index() {

		// Add rewrite to url class
		if ($this->config->get('config_seo_url')) {
			$this->url->addRewrite($this);
		} else {
			return;
		}

		// Decode URL
		if (!isset($this->request->get['_route_'])) {
			$this->validate();
		} else {
			$route_ = $route = $this->request->get['_route_'];
			unset($this->request->get['_route_']);
			$parts = explode('/', trim(utf8_strtolower($route), '/'));
			list($last_part) = explode('.', array_pop($parts));
			array_push($parts, $last_part);

			$rows = array();
			foreach ($parts as $keyword) {
				if (isset($this->cache_data['keywords'][$keyword])) {
					$rows[] = array('keyword' => $keyword, 'query' => $this->cache_data['keywords'][$keyword]);
				}
			}

			if (isset($this->cache_data['keywords'][$route])){
				$keyword = $route;
				$parts = array($keyword);
				$rows = array(array('keyword' => $keyword, 'query' => $this->cache_data['keywords'][$keyword]));
			}

			if (count($rows) == sizeof($parts)) {
				$queries = array();
				foreach ($rows as $row) {
					$queries[utf8_strtolower($row['keyword'])] = $row['query'];
				}

				reset($parts);
				foreach ($parts as $part) {
					if(!isset($queries[$part])) return false;
					$url = explode('=', $queries[$part], 2);

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

			if (isset($this->request->get['product_id'])) {
				$this->request->get['route'] = 'product/product';
				if (!isset($this->request->get['path'])) {
					$path = $this->getPathByProduct($this->request->get['product_id']);
					if ($path) $this->request->get['path'] = $path;
				}
			} 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/info';
			} elseif (isset($this->request->get['information_id'])) {
				$this->request->get['route'] = 'information/information';
			} elseif(isset($this->cache_data['queries'][$route_])) {
					header($this->request->server['SERVER_PROTOCOL'] . ' 301 Moved Permanently');
					$this->response->redirect($this->cache_data['queries'][$route_]);
			} else {
				if (isset($queries[$parts[0]])) {
					$this->request->get['route'] = $queries[$parts[0]];
				}
			}

			$this->validate();

			if (isset($this->request->get['route'])) {
				return new Action($this->request->get['route']);
			}
		}
	}

	public function rewrite($link) {
		if (!$this->config->get('config_seo_url')) return $link;

		$seo_url = '';

		$component = parse_url(str_replace('&amp;', '&', $link));

		$data = array();
		parse_str($component['query'], $data);

		$route = $data['route'];
		unset($data['route']);

		switch ($route) {
			case 'product/product':
				if (isset($data['product_id'])) {
					$tmp = $data;
					$data = array();
					if ($this->config->get('config_seo_url_include_path')) {
						$data['path'] = $this->getPathByProduct($tmp['product_id']);
						if (!$data['path']) return $link;
					}
					$data['product_id'] = $tmp['product_id'];
					if (isset($tmp['tracking'])) {
						$data['tracking'] = $tmp['tracking'];
					}
				}
				break;

			case 'product/category':
				if (isset($data['path'])) {
					$category = explode('_', $data['path']);
					$category = end($category);
					$data['path'] = $this->getPathByCategory($category);
					if (!$data['path']) return $link;
				}
				break;

			case 'product/product/review':
			case 'information/information/info':
				return $link;
				break;

			default:
				break;
		}

		if ($component['scheme'] == 'https') {
			$link = $this->config->get('config_ssl');
		} else {
			$link = $this->config->get('config_url');
		}

		$link .= 'index.php?route=' . $route;

		if (count($data)) {
			$link .= '&amp;' . urldecode(http_build_query($data, '', '&amp;'));
		}

		$queries = array();
		if(!in_array($route, array('product/search'))) {
			foreach($data as $key => $value) {
				switch($key) {
					case 'product_id':
					case 'manufacturer_id':
					case 'category_id':
					case 'information_id':
					case 'order_id':
						$queries[] = $key . '=' . $value;
						unset($data[$key]);
						$postfix = 1;
						break;

					case 'path':
						$categories = explode('_', $value);
						foreach($categories as $category) {
							$queries[] = 'category_id=' . $category;
						}
						unset($data[$key]);
						break;

					default:
						break;
				}
			}
		}

		if(empty($queries)) {
			$queries[] = $route;
		}

		$rows = array();
		foreach($queries as $query) {
			if(isset($this->cache_data['queries'][$query])) {
				$rows[] = array('query' => $query, 'keyword' => $this->cache_data['queries'][$query]);
			}
		}

		if(count($rows) == count($queries)) {
			$aliases = array();
			foreach($rows as $row) {
				$aliases[$row['query']] = $row['keyword'];
			}
			foreach($queries as $query) {
				$seo_url .= '/' . rawurlencode($aliases[$query]);
			}
		}

		if ($seo_url == '') return $link;

		$seo_url = trim($seo_url, '/');

		if ($component['scheme'] == 'https') {
			$seo_url = $this->config->get('config_ssl') . $seo_url;
		} else {
			$seo_url = $this->config->get('config_url') . $seo_url;
		}

		if (isset($postfix)) {
			$seo_url .= trim($this->config->get('config_seo_url_postfix'));
		} else {
			$seo_url .= '/';
		}

		if(substr($seo_url, -2) == '//') {
			$seo_url = substr($seo_url, 0, -1);
		}

		if (count($data)) {
			$seo_url .= '?' . urldecode(http_build_query($data, '', '&amp;'));
		}

		return $seo_url;
	}

	private function getPathByProduct($product_id) {
		$product_id = (int)$product_id;
		if ($product_id < 1) return false;

		static $path = null;
		if (!isset($path)) {
			$path = $this->cache->get('product.seopath');
			if (!isset($path)) $path = array();
		}

		if (!isset($path[$product_id])) {
			$query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . $product_id . "' ORDER BY main_category DESC LIMIT 1");

			$path[$product_id] = $this->getPathByCategory($query->num_rows ? (int)$query->row['category_id'] : 0);

			$this->cache->set('product.seopath', $path);
		}

		return $path[$product_id];
	}

	private function getPathByCategory($category_id) {
		$category_id = (int)$category_id;
		if ($category_id < 1) return false;

		static $path = null;
		if (!isset($path)) {
			$path = $this->cache->get('category.seopath');
			if (!isset($path)) $path = array();
		}

		if (!isset($path[$category_id])) {
			$max_level = 10;

			$sql = "SELECT CONCAT_WS('_'";
			for ($i = $max_level-1; $i >= 0; --$i) {
				$sql .= ",t$i.category_id";
			}
			$sql .= ") AS path FROM " . DB_PREFIX . "category t0";
			for ($i = 1; $i < $max_level; ++$i) {
				$sql .= " LEFT JOIN " . DB_PREFIX . "category t$i ON (t$i.category_id = t" . ($i-1) . ".parent_id)";
			}
			$sql .= " WHERE t0.category_id = '" . $category_id . "'";

			$query = $this->db->query($sql);

			$path[$category_id] = $query->num_rows ? $query->row['path'] : false;

			$this->cache->set('category.seopath', $path);
		}

		return $path[$category_id];
	}

	private function validate() {
		if (isset($this->request->get['route']) && $this->request->get['route'] == 'error/not_found') {
			return;
		}
		if (ltrim($this->request->server['REQUEST_URI'], '/') =='sitemap.xml') {
			$this->request->get['route'] = 'feed/google_sitemap';
			return;
		}

		if(empty($this->request->get['route'])) {
			$this->request->get['route'] = 'common/home';
		}

		if (isset($this->request->server['HTTP_X_REQUESTED_WITH']) && strtolower($this->request->server['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
			return;
		}

		if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
			$config_ssl = substr($this->config->get('config_ssl'), 0, $this->strpos_offset('/', $this->config->get('config_ssl'), 3) + 1);
			$url = str_replace('&amp;', '&', $config_ssl . ltrim($this->request->server['REQUEST_URI'], '/'));
			$seo = str_replace('&amp;', '&', $this->url->link($this->request->get['route'], $this->getQueryString(array('route')), true));
		} else {
			$config_url = substr($this->config->get('config_url'), 0, $this->strpos_offset('/', $this->config->get('config_url'), 3) + 1);
			$url = str_replace('&amp;', '&', $config_url . ltrim($this->request->server['REQUEST_URI'], '/'));
			$seo = str_replace('&amp;', '&', $this->url->link($this->request->get['route'], $this->getQueryString(array('route')), false));
		}

		if (rawurldecode($url) != rawurldecode($seo)) {
			header($this->request->server['SERVER_PROTOCOL'] . ' 301 Moved Permanently');

			$this->response->redirect($seo);
		}
	}

	private function strpos_offset($needle, $haystack, $occurrence) {
		// explode the haystack
		$arr = explode($needle, $haystack);
		// check the needle is not out of bounds
		switch($occurrence) {
			case $occurrence == 0:
				return false;
			case $occurrence > max(array_keys($arr)):
				return false;
			default:
				return strlen(implode($needle, array_slice($arr, 0, $occurrence)));
		}
	}

	private function getQueryString($exclude = array()) {
		if (!is_array($exclude)) {
			$exclude = array();
			}

		return urldecode(http_build_query(array_diff_key($this->request->get, array_flip($exclude))));
		}
	}
?>

вот здесь это возможно сделать?

Link to post
Share on other sites
1 час назад, buslikdrev сказал:


Попробуйте так:

  Скрыть контент


        $category_path = ($route == 'product/category' ? (!empty($this->cache_data['queries']['product/category']) ? '/' . $this->cache_data['queries']['product/category'] . '/' . : '/category/') : false);

               if ($component['scheme'] == 'https') {
			$seo_url = $this->config->get('config_ssl') . $category_path . $seo_url;
		} else {
			$seo_url = $this->config->get('config_url') . $category_path . $seo_url;
		}


Либо обращайтесь к @chukcha

что-то не так

Edited by abonnent
Link to post
Share on other sites

А как надо?

Вам здесь показали места где, берите и делайте

Я же вам предложил готовое решение, или даже так гарантированно рабочее решение.

Link to post
Share on other sites
2 минуты назад, chukcha сказал:

А как надо?

Вам здесь показали места где, берите и делайте

Я же вам предложил готовое решение, или даже так гарантированно рабочее решение.

изменений не наблюдаю просто

Link to post
Share on other sites
3 часа назад, abonnent сказал:

Такое как-нибудь можно исполнить? Заранее спасибо.

Как-нибудь - нельзя
А правильно, что работало - можно

Пример приведен (пусть и для 1.5) но там были другие требования

Вот еще пример на демо

http://demo2302.slasoft.kharkov.ua/shop/ipod-touch

На ошибки не смотрим

http://demo2302.slasoft.kharkov.ua/catalog/test-25

а вот категория с коротким урл и префиксом

Link to post
Share on other sites
3 минуты назад, chukcha сказал:

Хм, у меня как-то :) работает

if ($route == 'product/product'){
            if (!empty($this->cache_data['queries']['product/product'])){
                $category_path = '/' . $this->cache_data['queries']['product/product'] . '/';
            } else {
                $category_path = 'product/';
            }
        } else {
            $category_path = false;
        }

при переходе на страницу с товаром пишет, что нет такой страницы =(

Link to post
Share on other sites
16 минут назад, chukcha сказал:

Ну, у меня не пишет, а переходит

а в этом массиве $this->cache_data['queries'] у вас есть product/category ?

Link to post
Share on other sites
1 минуту назад, chukcha сказал:

Зачем?

if ($route == 'product/category'){
            if (!empty($this->cache_data['queries']['product/category'])){
                $category_path = $this->cache_data['queries']['product/category'] . '/';
            } else {
                $category_path = 'category/';
                echo '<pre>';
                print_r($this->cache_data);
                echo '</pre>';
            }
        } else {
            $category_path = false;
        }

вот это условие if (!empty($this->cache_data['queries']['product/category'])){ заведомо невыполнимо ведь, т.к. такого ключа нет. зачем же оно?

Link to post
Share on other sites
3 минуты назад, chukcha сказал:

Зачем?

Array
(
    [keywords] => Array
        (
            [vouchers] => account/voucher
            [wishlist] => account/wishlist
            [my-account] => account/account
            [cart] => checkout/cart
            [checkout] => checkout/checkout
            [login] => account/login
            [logout] => account/logout
            [order-history] => account/order
            [newsletter] => account/newsletter
            [specials] => product/special
            [affiliates] => affiliate/account
            [gift-vouchers] => checkout/voucher
            [brands] => product/manufacturer
            [contact-us] => information/contact
            [request-return] => account/return/insert
            [sitemap] => information/sitemap
            [forgot-password] => account/forgotten
            [downloads] => account/download
            [returns] => account/return
            [transactions] => account/transaction
            [create-account] => account/register
            [compare-products] => product/compare
            [search] => product/search
            [edit-account] => account/edit
            [change-password] => account/password
            [address-book] => account/address
            [reward-points] => account/reward
            [edit-affiliate-account] => affiliate/edit
            [change-affiliate-password] => affiliate/password
            [affiliate-payment-options] => affiliate/payment
            [affiliate-tracking-code] => affiliate/tracking
            [affiliate-transactions] => affiliate/transaction
            [affiliate-logout] => affiliate/logout
            [affiliate-forgot-password] => affiliate/forgotten
            [create-affiliate-account] => affiliate/register
            [affiliate-login] => affiliate/login
            [add-return] => account/return/add
            [] => common/home
            [apple] => manufacturer_id=8
            [test] => product_id=42
            [about_us] => information_id=4
            [laptop-notebook] => category_id=18
            [macs] => category_id=46
            [windows] => category_id=45
            [component] => category_id=25
            [mouse] => category_id=29
            [monitor] => category_id=28
            [test1] => category_id=35
            [test2] => category_id=36
            [printer] => category_id=30
            [scanner] => category_id=31
            [web-camera] => category_id=32
            [tablet] => category_id=57
            [software] => category_id=17
            [smartphone] => category_id=24
            [camera] => category_id=33
            [mp3-players] => category_id=34
            [test11] => category_id=43
            [test12] => category_id=44
            [test15] => category_id=47
            [test16] => category_id=48
            [test17] => category_id=49
            [test18] => category_id=50
            [test19] => category_id=51
            [test20] => category_id=52
            [test25] => category_id=58
            [test21] => category_id=53
            [test22] => category_id=54
            [test23] => category_id=55
            [test24] => category_id=56
            [test4] => category_id=38
            [test5] => category_id=37
            [test6] => category_id=39
            [test7] => category_id=40
            [test8] => category_id=41
            [test9] => category_id=42
            [canon-eos-5d] => product_id=30
            [htc-touch-hd] => product_id=28
            [macbook] => product_id=43
            [macbook-air] => product_id=44
            [macbook-pro] => product_id=45
            [nikon-d300] => product_id=31
            [palm-treo-pro] => product_id=29
            [product-8] => product_id=35
            [samsung-galaxy-tab-10-1] => product_id=49
            [samsung-syncmaster-941bw] => product_id=33
            [sony-vaio] => product_id=46
            [iphone] => product_id=40
            [ipod-classic] => product_id=48
            [ipod-nano] => product_id=36
            [ipod-shuffle] => product_id=34
            [ipod-touch] => product_id=32
            [canon] => manufacturer_id=9
            [htc] => manufacturer_id=5
            [hewlett-packard] => manufacturer_id=7
            [palm] => manufacturer_id=6
            [sony] => manufacturer_id=10
            [pc] => category_id=26
            [mac] => category_id=27
            [desktops] => category_id=20
            [imac] => product_id=41
            [hp-lp3065] => product_id=47
            [delivery] => information_id=6
            [privacy] => information_id=3
            [terms] => information_id=5
        )

    [queries] => Array
        (
            [account/voucher] => vouchers
            [account/wishlist] => wishlist
            [account/account] => my-account
            [checkout/cart] => cart
            [checkout/checkout] => checkout
            [account/login] => login
            [account/logout] => logout
            [account/order] => order-history
            [account/newsletter] => newsletter
            [product/special] => specials
            [affiliate/account] => affiliates
            [checkout/voucher] => gift-vouchers
            [product/manufacturer] => brands
            [information/contact] => contact-us
            [account/return/insert] => request-return
            [information/sitemap] => sitemap
            [account/forgotten] => forgot-password
            [account/download] => downloads
            [account/return] => returns
            [account/transaction] => transactions
            [account/register] => create-account
            [product/compare] => compare-products
            [product/search] => search
            [account/edit] => edit-account
            [account/password] => change-password
            [account/address] => address-book
            [account/reward] => reward-points
            [affiliate/edit] => edit-affiliate-account
            [affiliate/password] => change-affiliate-password
            [affiliate/payment] => affiliate-payment-options
            [affiliate/tracking] => affiliate-tracking-code
            [affiliate/transaction] => affiliate-transactions
            [affiliate/logout] => affiliate-logout
            [affiliate/forgotten] => affiliate-forgot-password
            [affiliate/register] => create-affiliate-account
            [affiliate/login] => affiliate-login
            [account/return/add] => add-return
            [common/home] => 
            [manufacturer_id=8] => apple
            [product_id=42] => test
            [information_id=4] => about_us
            [category_id=18] => laptop-notebook
            [category_id=46] => macs
            [category_id=45] => windows
            [category_id=25] => component
            [category_id=29] => mouse
            [category_id=28] => monitor
            [category_id=35] => test1
            [category_id=36] => test2
            [category_id=30] => printer
            [category_id=31] => scanner
            [category_id=32] => web-camera
            [category_id=57] => tablet
            [category_id=17] => software
            [category_id=24] => smartphone
            [category_id=33] => camera
            [category_id=34] => mp3-players
            [category_id=43] => test11
            [category_id=44] => test12
            [category_id=47] => test15
            [category_id=48] => test16
            [category_id=49] => test17
            [category_id=50] => test18
            [category_id=51] => test19
            [category_id=52] => test20
            [category_id=58] => test25
            [category_id=53] => test21
            [category_id=54] => test22
            [category_id=55] => test23
            [category_id=56] => test24
            [category_id=38] => test4
            [category_id=37] => test5
            [category_id=39] => test6
            [category_id=40] => test7
            [category_id=41] => test8
            [category_id=42] => test9
            [product_id=30] => canon-eos-5d
            [product_id=28] => htc-touch-hd
            [product_id=43] => macbook
            [product_id=44] => macbook-air
            [product_id=45] => macbook-pro
            [product_id=31] => nikon-d300
            [product_id=29] => palm-treo-pro
            [product_id=35] => product-8
            [product_id=49] => samsung-galaxy-tab-10-1
            [product_id=33] => samsung-syncmaster-941bw
            [product_id=46] => sony-vaio
            [product_id=40] => iphone
            [product_id=48] => ipod-classic
            [product_id=36] => ipod-nano
            [product_id=34] => ipod-shuffle
            [product_id=32] => ipod-touch
            [manufacturer_id=9] => canon
            [manufacturer_id=5] => htc
            [manufacturer_id=7] => hewlett-packard
            [manufacturer_id=6] => palm
            [manufacturer_id=10] => sony
            [category_id=26] => pc
            [category_id=27] => mac
            [category_id=20] => desktops
            [product_id=41] => imac
            [product_id=47] => hp-lp3065
            [information_id=6] => delivery
            [information_id=3] => privacy
            [information_id=5] => terms
        )

)

это все что есть

Link to post
Share on other sites

Я прекрасно знаю, структру  этого массива, зачем вы мне ее показываете?

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.