Page 1 of 1

get full category path in vqmod

Posted: Fri Feb 15, 2013 12:15 am
by L146705
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.

Re: get full category path in vqmod

Posted: Fri Feb 15, 2013 6:49 pm
by paulfeakins
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/

Re: get full category path in vqmod

Posted: Sun Feb 17, 2013 1:40 am
by L146705
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*/

Re: get full category path in vqmod

Posted: Mon Feb 18, 2013 6:31 pm
by paulfeakins
Glad to hear it :)

Re: get full category path in vqmod

Posted: Mon May 27, 2013 11:25 pm
by xseon
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?

Re: get full category path in vqmod

Posted: Tue May 28, 2013 10:26 pm
by paulfeakins
But a product can be in more than one category so how will you know which path should be displayed?

Re: get full category path in vqmod

Posted: Thu Jun 06, 2013 6:15 am
by straightlight
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.

Re: get full category path in vqmod

Posted: Fri Jan 11, 2019 3:13 am
by escurooo
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....

Re: get full category path in vqmod

Posted: Fri Jan 11, 2019 5:32 pm
by paulfeakins
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

Re: get full category path in vqmod

Posted: Sat Jan 12, 2019 6:40 pm
by deepvyas
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