Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Description : With this modifications, the friendly url link will contains
- // the color name if available
- // using Prestashop > 1.4.4
- class Link extends LinkCore{
- /**
- * Return the correct link for product, with the color name if there
- * is a color attribute available
- *
- * @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)
- {
- $id_lang = (int)$id_lang;
- if (!is_object($id_product))
- $id_product = new Product($id_product);
- $attributs = $id_product->getAttributeCombinaisons($id_lang);
- // adding color attribute, first part
- foreach($attributs AS $k => $attribut)
- if($attributs[$k]['is_color_group'])
- {
- $color = $attribut['attribute_name'];
- break;
- }
- // if link_rewrite
- if ($this->allow == 1)
- {
- $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang) ;
- if (isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home')
- $url .= $id_product->category.'/';
- $url .= $id_product->id.'-'.$id_product->link_rewrite;
- // adding color attribute, part II
- if (isset($color))
- $url .= '-'.$color;
- $url .= $id_product->ean13 ? '-'.$id_product->ean13 : '';
- $url .= '.html';
- }
- else
- $url = _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product->id;
- return $url;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment