/** * Create a link to a product * * @param mixed $product Product object (can be an ID product, but deprecated) * @param string $alias * @param string $category * @param string $ean13 * @param null $lang_id * @param null $shop_id * @param int $product_attribute_id ID product attribute * @param bool $force_routes * @throws JException * @internal param int $id_lang * @internal param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart * @return string */ public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $lang_id = null, $shop_id = null, $product_attribute_id = 0, $force_routes = false) { if (!$lang_id) { $lang_id = JeproshopContext::getContext()->language->lang_id; } if (!is_object($product)) { if (is_array($product) && isset($product['product_id'])) { $product = new JeproshopProductModelProduct($product['product_id'], false, $lang_id, $shop_id); } elseif ((int) $product) { $product = new JeproshopProductModelProduct((int) $product, false, $lang_id, $shop_id); } else { throw new JException(JText::_('COM_JEPROSHOP_INVALID_PRODUCT_VARS_MESSAGE')); } } // Set available keywords $anchor = '&task=view&product_id=' . $product->product_id . (!$alias ? '&rewrite=' . $product->getFieldByLang('link_rewrite') : $alias) . (!$ean13 ? '&ean13=' . $product->ean13 : $ean13); $anchor .= '&meta_keywords=' . JeproshopTools::str2url($product->getFieldByLang('meta_keywords')) . '&meta_title=' . JeproshopTools::str2url($product->getFieldByLang('meta_title')); if ($this->hasKeyword('product', $lang_id, 'manufacturer', $shop_id)) { $params['manufacturer'] = JeproshopTools::str2url($product->isFullyLoaded ? $product->manufacturer_name : JeproshopManufacturerModelManufacturer::getNameById($product->manufacturer_id)); } if ($this->hasKeyword('product', $lang_id, 'supplier', $shop_id)) { $params['supplier'] = JeproshopTools::str2url($product->isFullyLoaded ? $product->supplier_name : JeproshopSupplierModelSupplier::getNameById($product->supplier_id)); } if ($this->hasKeyword('product', $lang_id, 'price', $shop_id)) { $params['price'] = $product->isFullyLoaded ? $product->price : JeproshopProductModelProduct::getStaticPrice($product->product_id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specific_price); } if ($this->hasKeyword('product', $lang_id, 'tags', $shop_id)) { $params['tags'] = JeproshopTools::str2url($product->getTags($lang_id)); } if ($this->hasKeyword('product', $lang_id, 'category', $shop_id)) { $params['category'] = !is_null($product->category) && !empty($product->category) ? JeproshopTools::str2url($product->category) : JeproshopTools::str2url($category); } if ($this->hasKeyword('product', $lang_id, 'reference', $shop_id)) { $params['reference'] = JeproshopTools::str2url($product->reference); } if ($this->hasKeyword('product', $lang_id, 'categories', $shop_id)) { $params['category'] = !$category ? $product->category : $category; $cats = array(); foreach ($product->getParentCategories() as $cat) { if (!in_array($cat->category_id, Link::$category_disable_rewrite)) { //remove root and home category from the URL $cats[] = $cat->link_rewrite; } } $params['categories'] = implode('/', $cats); } $anchor .= $product_attribute_id ? '&product_attribute_id=' . $product_attribute_id : ''; return JRoute::_('index.php?option=com_jeproshop&view=product' . $anchor); }