// getProductLink fix and optimization
This commit is contained in:
+3
-4
@@ -94,15 +94,14 @@ class LinkCore
|
|||||||
throw new PrestashopException('Invalid product vars');
|
throw new PrestashopException('Invalid product vars');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set available keywords
|
// Set available keywords
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['id'] = $product->id;
|
$params['id'] = $product->id;
|
||||||
$params['rewrite'] = (!$alias) ? $product->link_rewrite : $alias;
|
$params['rewrite'] = (!$alias) ? $product->getFieldByLang('link_rewrite') : $alias;
|
||||||
$params['ean13'] = (!$ean13) ? $product->ean13 : $ean13;
|
$params['ean13'] = (!$ean13) ? $product->ean13 : $ean13;
|
||||||
$params['category'] = (!$category) ? $product->category : $category;
|
$params['category'] = (!$category) ? $product->category : $category;
|
||||||
$params['meta_keywords'] = Tools::str2url($product->meta_keywords);
|
$params['meta_keywords'] = Tools::str2url($product->getFieldByLang('meta_keywords'));
|
||||||
$params['meta_title'] = Tools::str2url($product->meta_title);
|
$params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title'));
|
||||||
|
|
||||||
if ($dispatcher->hasKeyword('product_rule', 'manufacturer'))
|
if ($dispatcher->hasKeyword('product_rule', 'manufacturer'))
|
||||||
$params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
|
$params['manufacturer'] = Tools::str2url($product->isFullyLoaded ? $product->manufacturer_name : Manufacturer::getNameById($product->id_manufacturer));
|
||||||
|
|||||||
@@ -1267,4 +1267,32 @@ abstract class ObjectModelCore
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the field value for the specified language if the field is multilang, else the field value.
|
||||||
|
*
|
||||||
|
* @param $field_name
|
||||||
|
* @param null $id_lang
|
||||||
|
* @return mixed
|
||||||
|
* @throws PrestashopException
|
||||||
|
* @since 1.5
|
||||||
|
*/
|
||||||
|
public function getFieldByLang($field_name, $id_lang = null)
|
||||||
|
{
|
||||||
|
$definition = ObjectModel::getDefinition($this);
|
||||||
|
// Is field in definition?
|
||||||
|
if ($definition && isset($definition['fields'][$field_name]))
|
||||||
|
{
|
||||||
|
$field = $definition['fields'][$field_name];
|
||||||
|
// Is field multilang?
|
||||||
|
if (isset($field['lang']) && $field['lang'])
|
||||||
|
{
|
||||||
|
if (is_array($this->{$field_name}))
|
||||||
|
return $this->{$field_name}[$id_lang ? $id_lang : Context::getContext()->language->id];
|
||||||
|
}
|
||||||
|
return $this->{$field_name};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new PrestashopException('Could not load field from definition.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2165,7 +2165,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
$preview_url = $this->context->link->getProductLink(
|
$preview_url = $this->context->link->getProductLink(
|
||||||
$this->getFieldValue($product, 'id'),
|
$product,
|
||||||
$this->getFieldValue($product, 'link_rewrite', $this->context->language->id),
|
$this->getFieldValue($product, 'link_rewrite', $this->context->language->id),
|
||||||
Category::getLinkRewrite($product->id_category_default, $this->context->language->id), null, null, Context::getContext()->shop->getID());
|
Category::getLinkRewrite($product->id_category_default, $this->context->language->id), null, null, Context::getContext()->shop->getID());
|
||||||
if (!$product->active)
|
if (!$product->active)
|
||||||
@@ -2175,7 +2175,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$token = Tools::encrypt('PreviewProduct'.$product->id);
|
$token = Tools::encrypt('PreviewProduct'.$product->id);
|
||||||
if (strpos($preview_url, '?') === false)
|
if (strpos($preview_url, '?') === false)
|
||||||
$preview_url .= '?';
|
$preview_url .= '?';
|
||||||
$preview_url = ($this->context->link->getProductLink($this->getFieldValue($product, 'id'), $this->getFieldValue($product, 'link_rewrite', $this->default_form_language), Category::getLinkRewrite($this->getFieldValue($product, 'id_category_default'), $this->context->language->id)));
|
$preview_url = ($this->context->link->getProductLink($product, $this->getFieldValue($product, 'link_rewrite', $this->default_form_language), Category::getLinkRewrite($this->getFieldValue($product, 'id_category_default'), $this->context->language->id)));
|
||||||
if (!$product->active)
|
if (!$product->active)
|
||||||
{
|
{
|
||||||
$admin_dir = dirname($_SERVER['PHP_SELF']);
|
$admin_dir = dirname($_SERVER['PHP_SELF']);
|
||||||
|
|||||||
Reference in New Issue
Block a user