Post by R_D » Tue Jun 14, 2016 10:03 pm

Hi,

I've got a strange problem. I've got OC 2.2 installed and forced it into https
Everything works fine except the sitemap

When I test it at Google Webmaster Tools I receive an error displaying that the url for images is invalid. This because the base url of my store is missing.

The url in sitemap is: image/cache/catalog/category/product.jpg
instead of : https://www.store.com/image/cache/catal ... roduct.jpg

Does anyone have an idea?

Thanks!

R_D
Active Member

Posts

Joined
Sun Jan 09, 2011 3:13 am

Post by oc-extensions » Wed Jun 15, 2016 12:02 am

Hi,

When sitemap.xml is accessed from .htaccess file will "redirect" google to feed/google_sitemap

Code: Select all

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap
feed/google_sitemap will generate full URL for images

Code: Select all

$output .= '<image:loc>' . $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_popup_width'), $this->config->get($this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>';
If image URL is generated without BASE URL then:
- config.php is wrong
- or you modified image class directly or from some vqmod/ocmod extension
- many other reasons -

You should ask an developer to take a look

Good Luck!

Image | Extensions and Custom Development


User avatar
Active Member

Posts

Joined
Fri Jan 06, 2012 11:31 pm

Post by R_D » Wed Jun 15, 2016 1:05 am

oc-extensions wrote:Hi,

When sitemap.xml is accessed from .htaccess file will "redirect" google to feed/google_sitemap

Code: Select all

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap
feed/google_sitemap will generate full URL for images

Code: Select all

$output .= '<image:loc>' . $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_popup_width'), $this->config->get($this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>';
If image URL is generated without BASE URL then:
- config.php is wrong
- or you modified image class directly or from some vqmod/ocmod extension
- many other reasons -

You should ask an developer to take a look

Good Luck!

Thanks for answering, config.php is correct and I didn't modify image class directly or from some vqmod/ocmod extension.

I think it must be the "many other reasons" :-[
Strangely though, the images are displayed ok in the store. ???

R_D
Active Member

Posts

Joined
Sun Jan 09, 2011 3:13 am

Post by oc-extensions » Wed Jun 15, 2016 1:13 am

Hi,

When browser is used on yourstore.com and in page images are loaded like "image/something.png" are displayed correctly (with relative path) because browser convert path to yourstore.com/image/something.php

In your store take a look with view source and check images path (is absolute path or relative path)?

To clarify:
absolute path = "http://www.yourstore.com/image/something.jpg"
relative path = "image/something.jpg"

Image | Extensions and Custom Development


User avatar
Active Member

Posts

Joined
Fri Jan 06, 2012 11:31 pm

Post by R_D » Wed Jun 15, 2016 4:00 am

oc-extensions wrote:Hi,

When browser is used on yourstore.com and in page images are loaded like "image/something.png" are displayed correctly (with relative path) because browser convert path to yourstore.com/image/something.php

In your store take a look with view source and check images path (is absolute path or relative path)?

To clarify:
absolute path = "http://www.yourstore.com/image/something.jpg"
relative path = "image/something.jpg"

You're right: it's showing the relative path... :'(
Back to the drawing board I guess ;)

R_D
Active Member

Posts

Joined
Sun Jan 09, 2011 3:13 am

Post by R_D » Wed Jun 15, 2016 5:02 pm

oc-extensions wrote:Hi,

When browser is used on yourstore.com and in page images are loaded like "image/something.png" are displayed correctly (with relative path) because browser convert path to yourstore.com/image/something.php

In your store take a look with view source and check images path (is absolute path or relative path)?

To clarify:
absolute path = "http://www.yourstore.com/image/something.jpg"
relative path = "image/something.jpg"

Just a question: do you know of a way to insert the base url temporarely so I can use the sitemap while searching for the error?

Thanks in advance!

R_D
Active Member

Posts

Joined
Sun Jan 09, 2011 3:13 am

Post by uksitebuilder » Thu Jun 16, 2016 5:23 am

Add a function in the controller:

catalog/controller/feed/google_sitemap.php

Code: Select all

	public function serverURL(){
		$isSecure = false;
		if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
			$isSecure = true;
		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
			$isSecure = true;
		}
		return ($isSecure ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'].'/';
	}
Then prefix the image url with: $this->serverURL() . 'image/….…...

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by R_D » Thu Jun 16, 2016 2:14 pm

uksitebuilder wrote:Add a function in the controller

Code: Select all

	public function serverURL(){
		$isSecure = false;
		if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
			$isSecure = true;
		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
			$isSecure = true;
		}
		return ($isSecure ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'].'/';
	}
Then prefix the image url with: $this->serverURL() . 'image/….…...

I will try that, thanks!

R_D
Active Member

Posts

Joined
Sun Jan 09, 2011 3:13 am

Post by ahill16 » Thu Aug 11, 2016 12:51 pm

uksitebuilder wrote:Add a function in the controller

Code: Select all

	public function serverURL(){
		$isSecure = false;
		if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
			$isSecure = true;
		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
			$isSecure = true;
		}
		return ($isSecure ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'].'/';
	}
Then prefix the image url with: $this->serverURL() . 'image/….…...
what controller file does this go into? I am having the same issue

Newbie

Posts

Joined
Wed Aug 10, 2016 8:42 am

Post by uksitebuilder » Thu Aug 11, 2016 1:48 pm

catalog/controller/feed/google_sitemap.php

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by ahill16 » Thu Aug 11, 2016 2:25 pm

uksitebuilder wrote:catalog/controller/feed/google_sitemap.php
I attempted to put this there but it didnt work. Do i Just copy and paste the code in the very bottom of the file?

When i posted the code at the very end me sitemap showed a url but still did not have the full url for the image path. Is there any way to edit how opencart creates the sitemap image urls?

Newbie

Posts

Joined
Wed Aug 10, 2016 8:42 am

Post by uksitebuilder » Thu Aug 11, 2016 5:38 pm

Did you amend the image code in the file

from

'image/….….….….…...

To

$this->serverURL() . 'image/….…...

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by ahill16 » Thu Aug 11, 2016 9:36 pm

can you give me a hand with the code? I havent touched code much outside classic ASP.

Code: Select all

<?php
class ControllerFeedGoogleSitemap extends Controller {
	public function index() {
		if ($this->config->get('google_sitemap_status')) {
			$output  = '<?xml version="1.0" encoding="UTF-8"?>';
			$output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';

			$this->load->model('catalog/product');
			$this->load->model('tool/image');

			$products = $this->model_catalog_product->getProducts();

			foreach ($products as $product) {
				if ($product['image']) {
					$output .= '<url>';
					$output .= '<loc>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</loc>';
					$output .= '<changefreq>weekly</changefreq>';
					$output .= '<lastmod>' . date('Y-m-d\TH:i:sP', strtotime($product['date_modified'])) . '</lastmod>';
					$output .= '<priority>1.0</priority>';
					$output .= '<image:image>';
					$output .= '<image:loc>' . $this->serverURL() . $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_popup_width'), $this->config->get($this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>';
					$output .= '<image:caption>' . $product['name'] . '</image:caption>';
					$output .= '<image:title>' . $product['name'] . '</image:title>';
					$output .= '</image:image>';
					$output .= '</url>';
				}
			}

			$this->load->model('catalog/category');

			$output .= $this->getCategories(0);

			$this->load->model('catalog/manufacturer');

			$manufacturers = $this->model_catalog_manufacturer->getManufacturers();

			foreach ($manufacturers as $manufacturer) {
				$output .= '<url>';
				$output .= '<loc>' . $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $manufacturer['manufacturer_id']) . '</loc>';
				$output .= '<changefreq>weekly</changefreq>';
				$output .= '<priority>0.7</priority>';
				$output .= '</url>';

				$products = $this->model_catalog_product->getProducts(array('filter_manufacturer_id' => $manufacturer['manufacturer_id']));

				foreach ($products as $product) {
					$output .= '<url>';
					$output .= '<loc>' . $this->url->link('product/product', 'manufacturer_id=' . $manufacturer['manufacturer_id'] . '&product_id=' . $product['product_id']) . '</loc>';
					$output .= '<changefreq>weekly</changefreq>';
					$output .= '<priority>1.0</priority>';
					$output .= '</url>';
				}
			}

			$this->load->model('catalog/information');

			$informations = $this->model_catalog_information->getInformations();

			foreach ($informations as $information) {
				$output .= '<url>';
				$output .= '<loc>' . $this->url->link('information/information', 'information_id=' . $information['information_id']) . '</loc>';
				$output .= '<changefreq>weekly</changefreq>';
				$output .= '<priority>0.5</priority>';
				$output .= '</url>';
			}

			$output .= '</urlset>';

			$this->response->addHeader('Content-Type: application/xml');
			$this->response->setOutput($output);
		}
	}

	protected function getCategories($parent_id, $current_path = '') {
		$output = '';

		$results = $this->model_catalog_category->getCategories($parent_id);

		foreach ($results as $result) {
			if (!$current_path) {
				$new_path = $result['category_id'];
			} else {
				$new_path = $current_path . '_' . $result['category_id'];
			}

			$output .= '<url>';
			$output .= '<loc>' . $this->url->link('product/category', 'path=' . $new_path) . '</loc>';
			$output .= '<changefreq>weekly</changefreq>';
			$output .= '<priority>0.7</priority>';
			$output .= '</url>';

			$products = $this->model_catalog_product->getProducts(array('filter_category_id' => $result['category_id']));

			foreach ($products as $product) {
				$output .= '<url>';
				$output .= '<loc>' . $this->url->link('product/product', 'path=' . $new_path . '&product_id=' . $product['product_id']) . '</loc>';
				$output .= '<changefreq>weekly</changefreq>';
				$output .= '<priority>1.0</priority>';
				$output .= '</url>';
			}

			$output .= $this->getCategories($result['category_id'], $new_path);
		}

		return $output;
	}
   public function serverURL(){
      $isSecure = false;
      if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
         $isSecure = true;
      } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
         $isSecure = true;
      }
      return ($isSecure ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'].'/';
   }
}

Newbie

Posts

Joined
Wed Aug 10, 2016 8:42 am

Post by uksitebuilder » Thu Aug 11, 2016 10:24 pm

Hi

I have modified your code above.

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by ahill16 » Fri Aug 12, 2016 10:34 am

this is still a nogo. sitemap is still generating the short url and not the long one

here is the sitemap that it gives me. I copied and pasted the new code that was in the box

https://www.uslawnparts.com/test/index. ... le_sitemap
Last edited by ahill16 on Fri Aug 12, 2016 11:56 am, edited 1 time in total.

Newbie

Posts

Joined
Wed Aug 10, 2016 8:42 am

Post by ahill16 » Fri Aug 12, 2016 11:49 am

uksitebuilder wrote:Did you amend the image code in the file

from

'image/….….….….…...

To

$this->serverURL() . 'image/….…...

Can you show me an example of where this goes? does this go in my image name when i upload images?

Newbie

Posts

Joined
Wed Aug 10, 2016 8:42 am

Post by uksitebuilder » Fri Aug 12, 2016 1:26 pm

I put it in the code above that I amended in your post

Code: Select all

$output .= '<image:loc>' . $this->serverURL() . $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_popup_width'), $this->config->get($this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>';
Of course you can amend it further by hardcoding your url instead of using the function if you wish

change the above to

Code: Select all

$output .= '<image:loc>http://ENTERYOURDOMAINHERE.COM/' . $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_popup_width'), $this->config->get($this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>';

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by ahill16 » Fri Aug 12, 2016 9:06 pm

uksitebuilder wrote:I put it in the code above that I amended in your post

Code: Select all

$output .= '<image:loc>' . $this->serverURL() . $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_popup_width'), $this->config->get($this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>';
Of course you can amend it further by hardcoding your url instead of using the function if you wish

change the above to

Code: Select all

$output .= '<image:loc>http://ENTERYOURDOMAINHERE.COM/' . $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_popup_width'), $this->config->get($this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>';
So if i Put this into the code into the file and it still isnt doing anything. Could it be google preventing this. The sitemap generates from opencart right?

Newbie

Posts

Joined
Wed Aug 10, 2016 8:42 am

Post by uksitebuilder » Fri Aug 12, 2016 9:38 pm

Most likely you are serving a cached page. Check your caching extensions if you have any that may be caching the file.

Some extensions offer an exclusions list where you can set the feed url to be excluded from caching.

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by ahill16 » Sat Aug 13, 2016 1:12 am

uksitebuilder wrote:Most likely you are serving a cached page. Check your caching extensions if you have any that may be caching the file.

Some extensions offer an exclusions list where you can set the feed url to be excluded from caching.
Are you talking about a cached page in my browser or in my site files?

Newbie

Posts

Joined
Wed Aug 10, 2016 8:42 am
Who is online

Users browsing this forum: No registered users and 2 guests