Post by matthewbaynham » Mon Apr 26, 2021 7:32 pm

I need to fix a twig file but I don't know which one.

When looking at the products in a category if you click on a product then the URL is wrong, it's put the product name into the URL.
https://www.gwenllian-retail.com/shop/i ... path=32_37

I can't remember which twig file I was editing.

-------------
Update:
I found the twig file.
/catalog/view/theme/default/template/product/category.twig:134

The problem is {{ product.href }} is returning the product name and not the href.

So where is {{ product.href }} being set?



---------------------

I'm guessing the values are being set in /catalog/controller/product/category.php but it looks fine.

Am I right?
This is lines 196-206

Code: Select all

				$data['products'][] = array(
					'product_id'  => $result['product_id'],
					'thumb'       => $image,
					'name'        => $result['name'],
					'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
					'price'       => $price,
					'special'     => $special,
					'tax'         => $tax,
					'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
					'rating'      => $result['rating'],
					'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
				);
Last edited by matthewbaynham on Mon Apr 26, 2021 8:08 pm, edited 1 time in total.

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by OSWorX » Mon Apr 26, 2021 8:05 pm

matthewbaynham wrote:
Mon Apr 26, 2021 7:32 pm
So where is {{ product.href }} being set?
In the controller.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by matthewbaynham » Mon Apr 26, 2021 8:32 pm

Yes...

I've found out it's being set in line 206 of /catalog/controller/product/category.php

Code: Select all

'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
But this is the wrong value so where does the $this->url->link function get it's values from?

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by JNeuhoff » Mon Apr 26, 2021 9:15 pm

When looking at the products in a category if you click on a product then the URL is wrong, it's put the product name into the URL.
No, it doesn't. At the moment your product link uses a URL like this one:

https://www.gwenllian-retail.com/shop/i ... ct_id=3043

if you want SEO-friendly links, then you have to add the SEO keywords in the admin backend's product edit page. Also in the admin backend, you have to enable the SEO URLs at System > Settings > store > Server > Use SEO URLs: Yes

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by matthewbaynham » Mon Apr 26, 2021 10:32 pm

I know normally it's https://www.gwenllian-retail.com/shop/i ... ct_id=3043

But I just did anything to get my shop working again. And I could easily generate this text "?route=product/product&product_id=3043"

I didn't see where the php the categories will be for the product. I know it looks thought the categories towards the top of the php file but I went for the easy solution as a temporary fix.

I know the path would normally be "?route=product/product&path=32_37&product_id=3043" but unless I can see what the parent category 32 and the child category 37 are in the php, then I'm stuck.

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by JNeuhoff » Mon Apr 26, 2021 11:06 pm

I am not what you are on about. Just put in the SEO keywords in the admin backend for your categories and products, and enable SEO Urls. That's it. No need to change the twig file, nor the controller.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by matthewbaynham » Mon Apr 26, 2021 11:15 pm

Now things make sense. I was wondering what made everything go wrong.

I switched "Use SEO URLs" to "yes" and I didn't think anything of this. However this was just before I noticed the problem.

So I need to check the apache module mod-rewrite.

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by OSWorX » Mon Apr 26, 2021 11:46 pm

matthewbaynham wrote:
Mon Apr 26, 2021 11:15 pm
So I need to check the apache module mod-rewrite.
Should be normally enabled by default.
More important (beside the fact that you have to enable the SEO-URLs [as explained above] and add SEO-definitions to all your categories, information texts and products), to enable the .htaccess
Which is per default not, because it's named: .htaccess.txt
So simple rename this file to .htaccess - usually nothing to do anymore .. IF your Webshop is not running inside a subfolder for example.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by matthewbaynham » Tue Apr 27, 2021 1:15 am

Now things are making more sense.

I've automated loading up all the data from my supplier but I didn't populate the table oc_seo_url correctly.

I put the manufacturer and the products in there but I didn't do the categories.

I've spent my time looking at fixing the configuration of the .htaccess file and the modules. I didn't know about the oc_seo_url table.

Thank you for that.

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by OSWorX » Tue Apr 27, 2021 2:07 am

Now after a "few" posts and answers, I am sure you can imagine how important it is this to read BEFORE you post the 1. message:
viewtopic.php?f=176&t=200480

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by matthewbaynham » Tue Apr 27, 2021 3:45 pm

Version 3.0.3.2
Default template

When I switch to "Use SEO URLs" my site stops working. (I leave it switched off unless I'm testing.)

.htaccess
I've edited the .htaccess so that the / is now /shop/

SEO-definitions
All of my categories, products and manufacturers have unique keywords without spaces in the oc_seo_url table (double checked in phpmysql)
(I don't know what prefix the information pages need in the oc_seo_url table but I'm opening them up yet in my tests).

Apache module mod-rewrite
When I use phpinfo() in a php file the it lists the apache module mod-rewrite. So I'm guessing that's OK.

What else?
I can't think what else I'm missing?

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by matthewbaynham » Tue Apr 27, 2021 3:49 pm

Is the Apache module mod_rewrite the same as mod-rewrite?

Could that be my problem?

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by OSWorX » Tue Apr 27, 2021 5:09 pm

All Apache modules are named like mod_
see: https://httpd.apache.org/docs/current/m ... write.html
mod-rewrite don't know what that should be .. ?

So now, what problem do you still have?

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by matthewbaynham » Tue Apr 27, 2021 5:18 pm

The problem I have now is when I switch on seo I get 404 page not found.

I just can't get this SEO to work. I've written above all the things I've check and I can't think what else it could be. And I can see anything on Google that it could be.

My .htacess file looks OK.
My the oc_seo_url table has been correctly updated for categories, products, information and manufacturers
And the mod-rewrite is installed

What else is there?

How can I narrow down the problem?

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|.twig|\.ini|\.log|(?<!robots)\.txt))">
 Require all denied
## For apache 2.2 and older, replace "Require all denied" with these two lines :
# Order deny,allow
# Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /shop/
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/storage/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by matthewbaynham » Tue Apr 27, 2021 5:20 pm

I created my own robots.txt file could that be a problem? Or doesn't it have anything to do with SEO?

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by OSWorX » Tue Apr 27, 2021 5:50 pm

matthewbaynham wrote:
Tue Apr 27, 2021 5:20 pm
I created my own robots.txt file could that be a problem? Or doesn't it have anything to do with SEO?
No, has not.
Deactivate this line in your .htaccess:
instead

Code: Select all

Options +FollowSymlinks
use

Code: Select all

#Options +FollowSymlinks
What kind of server management do you run, e.g. Plesk or CPanel or any other?

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by matthewbaynham » Tue Apr 27, 2021 5:56 pm

Didn't work.

Should .htaccess be located in /var/www/html/ or /var/www/html/shop/

Because my website is in a subdomain shop https://www.gwenllian-retail.com/shop

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by matthewbaynham » Tue Apr 27, 2021 5:58 pm

I'm using webmin to manage my server.

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm

Post by JNeuhoff » Tue Apr 27, 2021 6:16 pm

matthewbaynham wrote:
Tue Apr 27, 2021 5:56 pm
Didn't work.

Should .htaccess be located in /var/www/html/ or /var/www/html/shop/

Because my website is in a subdomain shop https://www.gwenllian-retail.com/shop
Your .htaccess file should be in /var/www/html/shop/, though I don't think that is the cause of the problem.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by matthewbaynham » Tue Apr 27, 2021 6:25 pm

So I'm going to guess that the .htaccess might not be where the problem is.

What else do I need to check in the oc_seo_url table?
  • The keywords need to be unique across all languages (I just have English and German).
  • All the spaces have been replaced with "-"
  • Non-ascii characters have been removed (Germans put double dots above the a, o, u and they have a character for double s, I've taken all that out of the keyword field).
Last edited by matthewbaynham on Tue Apr 27, 2021 8:58 pm, edited 1 time in total.

New member

Posts

Joined
Fri Nov 01, 2019 9:18 pm
Who is online

Users browsing this forum: No registered users and 121 guests