Post by sparky007 » Sun Mar 01, 2015 7:28 pm

My business (and site) offers both non-sales support and information and also a sales option for customers to buy products (in that sense it is not a predominatly 'sales/shopping cart site'). For those customers looking to purchase a product, I have created a custom page called 'sales' which provides some toplevel info/details about or sales. To follow from here, I would like the path/url and breadcumbs to categories and products for my site to be taken and shown as: home/sales/category/product and not: home/category/product (as it is by default).

I'm guessing I need to look to make the changes somewhere in the controller, seourl and url aliases, but having looked and tried a few things, I'm not getting that far (not getting anywhere actually).

So, in summary: when customers are browsing my site, i want them to just see the seo/url/path & breadcrumbs as the standard home/contact or home/information etc... but for all shopping category/product related, I would like 'sales' added to the path to indicate home/sales/category/product seo/url/path & breadcrumbs.

I hope this can be done... could someone kindly help or nudge me in the right direction please - thanks!

Clive.

New member

Posts

Joined
Sun Mar 01, 2015 7:04 pm

Post by sparky007 » Mon Mar 02, 2015 3:30 pm

So, the best I can come up with is a very simple change (addition) in seo_url.php.... (around line 200, just after DB call for categories).

if ($query->num_rows) {
$url .= '/sales/' . $query->row['keyword'];

I simply added sales/

That works to some extent, it corrects the top level category URL/path, eg. home/sales/toplevcategory/product
But also adds the same to the second level category (if one exists), eg. home/sales/toplevcategory/sales/nextlevcategory/product

I'm almost there, just need a helping had please - thanks Clive.

New member

Posts

Joined
Sun Mar 01, 2015 7:04 pm

Post by sparky007 » Tue Mar 03, 2015 7:34 pm

Hello again.

I'm still stuck with this, just wanted to try once more to see if anyone has any thoughts?

To summarise, I require the 'non shopping' side of my site (information pages, contact etc..) to run from:
home/information or home/contact etc...
but want to run the shopping side via:
home/sales/category/product

Adding sales/ within the seo_url (as I mention above) works to show home/sales/category/product but creates a problem for any 2nd level category URL/paths eg. home/sales/toplevcategory/sales/nextlevcategory/product

My pea brain and depth of opencart knowledge just isnt cutting it.... it feels tanalisingly do'able, hopefully someone will push me forward and help.

Thanks, Clive.

New member

Posts

Joined
Sun Mar 01, 2015 7:04 pm

Post by Dhaupin » Tue Mar 03, 2015 11:09 pm

Here is a vQmod that should do that for you (tested in 1.5.6.4). The steps it does are these:

1) Define an empty variable "$url_prefix" in the rewrite() function
2) Remove product triggers from the rewrite IF near line 70
3) Add another ELSEIF for those product triggers, so they are their own switch then define $url_prefix as "/sales"
4) Define $url_prefix as "/sales" in the ELSEIF for the path (categories) below it
5) Put the output of $url_prefix before $url in the return at the bottom so it loads before the other seo_urls do in the address for the page

Code: Select all

<modification>

	<id><![CDATA[Tweaks the routes system to include a custom URL on products and categories.]]></id>
	<version><![CDATA[1.0.0]]></version>
	<vqmver><![CDATA[2.4.1]]></vqmver>
	<author><![CDATA[Dhaupin - CreadevDotOrg]]></author>



	<!-- @SEO_URL CONTROLLER -->
	<file name="catalog/controller/common/seo_url.php">

		<operation info="remove generic product from IF and define empty url_prefix" error="log">
			<search position="replace"><![CDATA[
				if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
			]]></search>
			<add><![CDATA[
				$url_prefix = '';
				
				if ((($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
			]]></add>
		</operation>
		<operation info="add new IF for products and set url_prefix" error="log">
			<search position="before"><![CDATA[
				} elseif ($key == 'path') {
			]]></search>
			<add><![CDATA[
				} elseif ($data['route'] == 'product/product' && $key == 'product_id') {
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'");

					$url_prefix = '/sales';
					
					if ($query->num_rows) {
						
						$url .= '/' . $query->row['keyword'];
						
						unset($data[$key]);
					}
			]]></add>
		</operation>
		<operation info="set url_prefix in categories" error="log">
			<search position="after"><![CDATA[
				} elseif ($key == 'path') {
			]]></search>
			<add><![CDATA[
					$url_prefix = '/sales';
			]]></add>
		</operation>
		<operation info="add url_prefix to constructed url" error="log">
			<search position="replace"><![CDATA[
				return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
			]]></search>
			<add><![CDATA[
		return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url_prefix . $url . $query;
			]]></add>
		</operation>

	</file>



	<!-- @PRODUCT CONTROLLER -->
	<file path="catalog/controller/" name="product/category.php,product/product.php">

		<operation info="add sales after home in breadcrumbs" error="log">
			<search position="replace"><![CDATA[
				'separator' => false
			]]></search>
			<add><![CDATA[
			'separator' => false
		);
		$this->data['breadcrumbs'][] = array(
			'text'      => 'Sales',
			'href'      => $this->url->link('common/home'),
			'separator' => $this->language->get('text_separator')
			]]></add>
		</operation>

	</file>

</modification>
Last edited by Dhaupin on Wed Mar 04, 2015 5:06 am, edited 1 time in total.

https://creadev.org | support@creadev.org - Opencart Extensions, Integrations, & Development. Made in the USA.


User avatar
Active Member

Posts

Joined
Tue May 13, 2014 3:45 am
Location - PA

Post by sparky007 » Wed Mar 04, 2015 2:27 am

Awesome.... Thanks Dhaupin!!

I just changed (I tend to mod the core and not use vqmod/xml), and it works great. I just have the breadcrumbs to sort out now.....

Thanks again!!

Clive.

New member

Posts

Joined
Sun Mar 01, 2015 7:04 pm

Post by sparky007 » Wed Mar 04, 2015 4:06 am

Arhh, I cant sort out the breadcumbs to include home > sales > category > product.

I'm guessing I need to change/add to the breadcurmbs in the respecive controller files (eg. controller/product/category.php) and then also the associated template file (eg. template/product/category.tpl)?

Can I trouble you again, and ask how and if I'm on the right track or there is another way?

Thanks again, Clive.

New member

Posts

Joined
Sun Mar 01, 2015 7:04 pm

Post by Dhaupin » Wed Mar 04, 2015 5:05 am

Yeah you need to add a breadcrumb array for the item in the controller(s). The easiest way would be to do it after the one for "home". I have added that to the vQmod above.

Code: Select all

$this->data['breadcrumbs'][] = array(
	'text'      => $this->language->get('text_home'),
	'href'      => $this->url->link('common/home'),			
	'separator' => false
);
$this->data['breadcrumbs'][] = array(
	'text'      => 'Sales',
	'href'      => $this->url->link('common/home'),
	'separator' => $this->language->get('text_separator')
);

https://creadev.org | support@creadev.org - Opencart Extensions, Integrations, & Development. Made in the USA.


User avatar
Active Member

Posts

Joined
Tue May 13, 2014 3:45 am
Location - PA

Post by sparky007 » Wed Mar 04, 2015 5:54 am

That's it - thanks again!!

Only one point:

$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => 'Sales',
'href' => $this->url->link('common/home'),
'separator' => $this->language->get('text_separator')
);

That href/url path obviously takes you back to the home page. I have my 'sales' page defined as: information/sales which I substituted and works like a dream.

Thanks again!! Clive.

New member

Posts

Joined
Sun Mar 01, 2015 7:04 pm

Post by Dhaupin » Wed Mar 04, 2015 8:25 am

Good catch man, wasnt sure what you wanted for that link hah. Glad it works for you. Thanks for the inspiration to dig into this concept, hopefully others can understand it better as well. It wouldnt be too tedious to inject an admin page, some tokens, and some settings into this to make it like the Wordpress permalinks templates screen. Hate to re-invent the wheel but if others need this as a customizable/extended mod, we may be interested to finish it up when time permits.

Just an FYI for folks in the future: The above vQmod was made for Clive, there are no guarantees it will work in your store or with your SEO url system. DiY tweaking is recommended :)

https://creadev.org | support@creadev.org - Opencart Extensions, Integrations, & Development. Made in the USA.


User avatar
Active Member

Posts

Joined
Tue May 13, 2014 3:45 am
Location - PA

Post by casperkip » Tue May 26, 2015 1:50 pm

Thanks for instance.

this just category.
How to both product and category?
thnx.

Newbie

Posts

Joined
Tue May 26, 2015 1:47 pm

Post by tucetrn » Wed May 20, 2020 8:36 pm

Hello,

Can you help this way for Opencart 3.0.2.0 version

Newbie

Posts

Joined
Fri Mar 27, 2020 6:48 pm

Post by straightlight » Wed May 20, 2020 11:07 pm

tucetrn wrote:
Wed May 20, 2020 8:36 pm
Hello,

Can you help this way for Opencart 3.0.2.0 version
Please create a new topic. You are posting in the v1.5x about a different OC version series.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 18 guests