Post by L146705 » Fri Feb 15, 2013 12:15 am

I am having a bit of a problem with the Canonical URLs meta tag for the Category pages. Basically I had an error in some code that caused the sub categories to index as http://www.shopname.com/subcategory instead of http://www.shopname.com/parentcategory/subcategory

Here is the VQMOD code all that it needs is some code putting in
to get the full category path rather than just current url path.

Code: Select all

 $this->document->addLink($this->url->link('product/category', 'path=' . $category_id), 'canonical');

Code: Select all

    <modification>
       <id>Canonical Category Link</id>
       <version>1.0</version>
       <vqmver>1.2.3</vqmver>
       <author>uksb</author>
       <file name="catalog/controller/product/category.php">
          <operation>
             <search position="replace"><![CDATA[         $this->document->setKeywords($category_info['meta_keyword']);]]></search>
             <add><![CDATA[         $this->document->setKeywords($category_info['meta_keyword']);
             $this->document->addLink($this->url->link('product/category', 'path=' . $category_id), 'canonical');]]>
          
           </add>
          </operation>
       </file>
    </modification>
Please place your quotes for the work.

New member

Posts

Joined
Sun Feb 26, 2012 2:50 am

Post by paulfeakins » Fri Feb 15, 2013 6:49 pm

I'm not sure if we can quote to fix one line of code but take a look at this:
http://www.nanothree.net/2012/get-path- ... -opencart/

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by L146705 » Sun Feb 17, 2013 1:40 am

Thanks paulfeakins, it works. For anyone that comes across wondering how it is done I added the code to the model category.php page

Code: Select all

	/** custom code used in code to add correct canonical meta tag to page
* Returns the path to a category in the format 1_2_3 
* @param int $category_id 
* @return string the path to the category 
*/
public function getCategoryPath($category_id){
			$path = '';
			   $category = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c WHERE c.category_id = " .(int)($category_id));
	
   if($category->row['parent_id'] != 0){
			 $path .= $this->getCategoryPath($category->row['parent_id']) . '_';
	}
	
	$path .= $category->row['category_id'];
	
	 return $path;
}
And in the category.php controller file I added

Code: Select all

	/*added to add correct canonical meta tag to page*/
	$this->document->addLink($this->url->link('product/category', 'path=' . $this->model_catalog_category->getCategoryPath($category_id)), 'canonical');
	/*end of added to add correct canonical meta tag to page*/

New member

Posts

Joined
Sun Feb 26, 2012 2:50 am

Post by paulfeakins » Mon Feb 18, 2013 6:31 pm

Glad to hear it :)

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by xseon » Mon May 27, 2013 11:25 pm

I'm looking for a similar solution but regarding the product URL: when you open a product page like this one:

/index.php?route=product/product&product_id=40

then your breadcrumbs and category module doesn't "follow" you. So you need to somehow add the category path here and get the URL like this one:

/index.php?route=product/product&path=59_20&product_id=40

Can you suggest how to do it?

Deeper and Better Category Module
Mass Product Price Change
Unlimited hosting with free domain and all extras


User avatar
New member

Posts

Joined
Thu Dec 01, 2011 3:04 pm
Location - Bulgaria

Post by paulfeakins » Tue May 28, 2013 10:26 pm

But a product can be in more than one category so how will you know which path should be displayed?

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by straightlight » Thu Jun 06, 2013 6:15 am

By assigning the last session data variable to the category path, it is still possible to distinguish which product ID has been selected - referred from the URL. In this case, it is not required to set a GET request as the path in the URL.

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

Posts

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

Post by escurooo » Fri Jan 11, 2019 3:13 am

xseon wrote:
Mon May 27, 2013 11:25 pm
I'm looking for a similar solution but regarding the product URL: when you open a product page like this one:

/index.php?route=product/product&product_id=40

then your breadcrumbs and category module doesn't "follow" you. So you need to somehow add the category path here and get the URL like this one:

/index.php?route=product/product&path=59_20&product_id=40

Can you suggest how to do it?
Hello I have the same issue with.. I added subcategories to my cart but when I try to access to any product under that new subcategory the product is not displayed and I just got the error HTPP 500 internal Server and I just notice that for some reasons the code add "_" when product is under subcategory but "why" is not necessary haha... could some one can help me to correct the code? or something....

Newbie

Posts

Joined
Fri Jan 11, 2019 3:03 am

Post by paulfeakins » Fri Jan 11, 2019 5:32 pm

Hi there,

More than happy to take a look seeing as we fixed the last issue. Please email info@antropy.co.uk and we can pick it up from there.

Thanks,

Alex

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by deepvyas » Sat Jan 12, 2019 6:40 pm

Hello ,
Greetings!
I can help you further, need to check the script which return that error
Please add me on Skype - deepvyas71


Best Regards
Deep

Expert Opencart Developer & Designer | S: deepvyas71 | E: deepvyas71@gmail.com


Active Member

Posts

Joined
Thu Jan 12, 2017 7:04 pm
Who is online

Users browsing this forum: No registered users and 8 guests