Jump to content

How to get full product link rewrite with category name in php?


Kerm

Recommended Posts

This:
 

$url = $this->context->link->getProductLink($product);

Or this: 

$product = new Product((int)$id_product);			
$link = new Link();
$url = $url = $link->getProductLink($product);

Show product link with out category name in url....

 

I need some link like that:

site.com/category-name/22[spam-filter]product-link.html

  • Like 1
Link to comment
Share on other sites

In product.php, I see that they first fill the 'category' array as well, and add it to the getProductLink function:

 

$row['category'] = Category::getLinkRewrite((int)$row['id_category_default'], (int)$id_lang);
$row['link'] = $context->link->getProductLink((int)$row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
 
 
Maybe this helps?
pascal.
  • Like 2
Link to comment
Share on other sites

  • 5 months later...
  • 3 years later...

Not sure if this answers your question:

How to get the Product link:

Context::getContext()->link->getProductLink( $id_product );

How to get the Category link:

Context::getContext()->link->getCategoryLink( $id_category );

 

 

Oh, actually I think now I understand what you're asking:

you want to change the URL structure, so you've gotta go to 

Admin Office -> Preferences -> Seo & URLs -> scroll down to SCHEMA OF URLS

I have mine set to {category:/}{id}/{rewrite} so I get exactly what you want I believe

 

 

 

prestashop urls.PNG

Edited by theillo (see edit history)
Link to comment
Share on other sites

  • 6 months later...

Hello, dont you know why is this code dont working? It wont generate product link 😮 

If product have combination, you can disable "Add to Cart" button on Category page. So i want to have this button linked to the product page.

Presta 1.7

<a href="{$product.url}">Choose combination</a>

Thank you for help.

Link to comment
Share on other sites

The full code of my productattributes.tpl

<div class="an_productattributes">
<form method="post" class="an_productattributesForm" action="{$cart|escape:'htmlall':'UTF-8'}">
<input name="token" value="{$token|escape:'htmlall':'UTF-8'}" type="hidden">
<input name="id_product" value="{$productId|escape:'htmlall':'UTF-8'}" type="hidden">
{*<input name="id_customization" value="0" placeholder="" type="hidden"> *}
{if $config.display_quantity!='1'}
<input name="qty" type="hidden" value="{$minimal_quantity|escape:'htmlall':'UTF-8'}" min="{$minimal_quantity|escape:'htmlall':'UTF-8'}">
{/if}
  
	{if $config.type_view=='standart'}
	<div class="js-an_productattributes-standart">
		{include file='./product-variants.tpl'}
	</div>
	{/if}
	{if $config.type_view=='select' AND isset($productData) AND count($productData)>0}
	<div class="an_productattributes-select js-an_productattributes-select">
		{include file='./product-select.tpl'}
	</div>
	{/if}
			
	{if $config.display_add_to_cart=='1'}
	<div class="an_productattributes-qty-add clearfix">
		
		{if $config.display_quantity=='1'}
		<div class="an_productattributes-qty-container">
		  <input type="number" name="qty" value="{$minimal_quantity|escape:'htmlall':'UTF-8'}" class="input-group form-control an_productattributes-qty" min="{$minimal_quantity|escape:'htmlall':'UTF-8'}" aria-label="Quantity" style="display: block;">
		</div>
		{/if}
		
		{if $availableForOrder !='0'}
		<div class="an_productattributes-add">
		  <button class="btn an_productattributes-add-to-cart-btn js-an_productattributes-add-to-cart" data-button-action="add-to-cart" type="submit" >
			<i class="material-icons shopping-cart"></i>
			{l s='Add to cart' mod='an_productattributes'}  
		  </button>
		</div>
		{/if}
		
		{if $availableForOrder !='1'}		
		<div class="an_productattributes-add">		
		  <a href="{$product.url}"> 
      <button class="btn an_productattributes-add-to-cart-btn">
			<i class="material-icons calendar_today"></i>
			Vyberte termín (Choose combination) 
		  </button>
		  </a>		  
		</div>		
		{/if}
		  
	</div>
	{/if}
</form>
</div>

 

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...