Jump to content

ean13 number in url


Recommended Posts

This is not the most elegant way to do it, though the shortest. Locate the file /classes/Link.php, find the method getProductLink and change

 

public function getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL, $id_lang = NULL)
{
 if (is_object($id_product))
  return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).((isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home') ? $id_product->category.'/' : '').(int)$id_product->id.'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.$id_product->ean13 : '').'.html') :
  (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product->id);
 elseif ($alias)
  return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).(($category AND $category != 'home') ? ($category.'/') : '').(int)$id_product.'-'.$alias.($ean13 ? '-'.$ean13 : '').'.html') :
  (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product);
 else
  return _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product;
}

 

to

 

 

public function getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL, $id_lang = NULL)
{
 if (is_object($id_product))
  return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).((isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home') ? $id_product->category.'/' : '').(int)$id_product->id.'-'.$id_product->link_rewrite.($id_product->ean13 ? '' : '').'.html') :
  (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product->id);
 elseif ($alias)
  return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).(($category AND $category != 'home') ? ($category.'/') : '').(int)$id_product.'-'.$alias.($ean13 ? '' : '').'.html') :
  (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product);
 else
  return _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product;
}

 

and here is a summary of changes, in case you're using a different version.

 

- return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).((isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home') ? $id_product->category.'/' : '').(int)$id_product->id.'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.$id_product->ean13 : '').'.html') :
+ return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).((isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home') ? $id_product->category.'/' : '').(int)$id_product->id.'-'.$id_product->link_rewrite.($id_product->ean13 ? '' : '').'.html') :

- return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).(($category AND $category != 'home') ? ($category.'/') : '').(int)$id_product.'-'.$alias.($ean13 ? '-'.$ean13 : '').'.html') :
+ return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).(($category AND $category != 'home') ? ($category.'/') : '').(int)$id_product.'-'.$alias.($ean13 ? '' : '').'.html') :

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
  • 1 month later...
  • 6 months later...

Hi, this is what i did:

You have to create an override class for friendly url build. This is done in classes/Link.php

For ugrade reasons you can not edit this file.

You have to create an override for this file, this is how:

0. If you dont understand this, ask somebody to do it for you

1. Always backup your files !!!!

2. Create a folder /override in root directory on shop, if not already exists

3. create a file called Link.php

this is the override file for classes/Link.php

4. copy the following code into it

<?php

class Link extends LinkCore{

/**
  * Return the correct link for product/category/supplier/manufacturer
  *
  * @param mixed $id_product Can be either the object or the ID only
  * @param string $alias Friendly URL (only if $id_OBJ is the object)
  * @return string link
  */
public function getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL, $id_lang = NULL)
{
 global $cookie;
 if (is_object($id_product))
 {
  $link = '';
  if ($this->allow == 1)
  {
$link .= (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang));

if (isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home')
 $link .= $id_product->category.'/';
else
 $link .= '';
$link .= (int)$id_product->id.'-';
if (is_array($id_product->link_rewrite))
 $link.= $id_product->link_rewrite[(int)$cookie->id_lang];
else
  $link.= $id_product->link_rewrite;
if ($id_product->ean13)
 $link .= ''; //$link .='-'.$id_product->ean13;
else
 $link .= '';
$link .= '.html';
  }
  else
  {
$link .= (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product->id);
  }
		//die($link);
  return $link;
 }

 else if ($alias)
 {
  $link = '';
  if ($this->allow == 1)
  {
$link .= (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang));

if ($category AND $category != 'home')
 $link .= $category.'/';
else
  $link .= '';

$link .= (int)$id_product.'-'.$alias;

if ($ean13)
 $link .= ''; //$link .='-'.$ean13;
else
 $link .= '';

$link .= '.html';
  }
  else
$link .=(_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product);
  return $link;
 }

 else
  return _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product;
}
  }

the lines changed are, 2 in total

$link .= ''; //$link .='-'.$ean13;

in this way it does not append the ean13 filed to the link

 

Hope i wrote it undersatndeble and that it hepls others.

Best regards, Zoli.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...