cancel
Showing results for 
Search instead for 
Did you mean: 

Link to another product in current product

SOLVED

Link to another product in current product

Is there a shortcut where I can supply a product ID inside a tag and use that to have Magento render the correct URL?

I want to link to other products from a current product's description.

 

I know I can use widgets for this but that seems like a lot of steps to do.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Link to another product in current product

@mikecorrac Yes that's actually same, same kind of logic you can use apply with little modification. tag changes on backend and parse same on frontend... of course dynamically.

-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

View solution in original post

8 REPLIES 8

Re: Link to another product in current product

If it is the product details page then you can use the Magento Upsell functionality.

Re: Link to another product in current product

@mikecorrac

 

Seems like you want to add another products link into current product description.... hummm.. Possible but you need to write little piece of code. let me help you by writing sample php code.

 

As you've said apply product id so I assume and go with product id wise. Add product id tag wise into description, just like.

Lorem Ipsum is simply dummy text <product_id>121</product_id> of the printing and typesetting industry

php code to achieve it.

 

<?php 
function getTagsIds($string, $tagname)
{
    $pattern = "/<$tagname>([\w\W]*?)<\/$tagname>/";
    if(preg_match($pattern, $string, $matches))
		return $matches;
}

$description = 'Lorem Ipsum is simply dummy text <product_id>121</product_id> of the printing and typesetting industry';
$ids = getTagsIds($description, "product_id");

if(!empty($ids)){
 foreach($ids as $id){
	$description = str_replace("<product_id>$id</product_id>", "<a href='http://www.google.com'>Test</a>", $description);
 }
}

echo $description;

Just implement same into Magento files and you're done. Good luck Smiley Happy

 

-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Link to another product in current product

That isn't exactly what I meant. I was seeing firstly if Magento had a stock function for doing this. Similar to this:

 

<a href="{{store url="page_identifier_here"}}#something">Anchor text here</a>

 

 

But if I was going to write code it would have to be dynamic since it would need to parse the tag wherever it lives on the site 

Re: Link to another product in current product

You probably want to check out product widgets: http://magento.stackexchange.com/questions/11674/cms-block-widgets-for-individual-products

 

Tanel Raja

Re: Link to another product in current product

I saw that too, I would have to create a widget for each and every product, that seems silly to me.

Re: Link to another product in current product

@mikecorrac Yes that's actually same, same kind of logic you can use apply with little modification. tag changes on backend and parse same on frontend... of course dynamically.

-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Link to another product in current product

We ended up writing our own solution based loosely on your suggestion, thanks

Re: Link to another product in current product


@mikecorrac wrote:

I saw that too, I would have to create a widget for each and every product, that seems silly to me.


The whole point of widget is that you do not create them for each and every product. Widgets are smart blocks: all you need to do is  to give it a product code (which you need to have there anyways) and it does everything else.

Tanel Raja