Hi,
I have a url question I hope you can help me with.
In my left menu I have made my own menu containing some direct links
to some of my products, but I get an url that isn’t rewrited when I add them myself.
Fx if I add a link to my product 2 I add the link below
```php
{$index_script}?{$target_name}=products&product_id=2
```
But in order to get the url rewrited I need to add this
```php
{$index_script}?{$target_name}=products&product_id={$product.product_id}
```
But the $product variable isn’t defined, so I can’t do that.
Is it possible to get my url rewrited to what I already have it set for in the database somehow ?
Perhaps something like this right before each link:
```php
$product.product==2
```
and so on for all my own links ?
Thanks,
bpn
did you put {debug} in your template to see if the $product variable or some other usable variable is defined?
Hi dragon,
no I did not. I need to set the variable myself somehow.
Fx if make a link to product no 17, I need $product.product to be 17
$product.product will never be a number… $product.product is the product name
$product.product_id is the product number
but, in your template, put {debug} then view the page… a popup window will come up showing you all of the variables that are currently defined on the page
Sorry, I did mean $product.product_id, also in the first post.
I tried to add the debug thing, but all I can see in the window is a lot of variables and arrays, but I don’t see how that should help me to force $product.product_id to be a certain number.
That said, I am absolutely not a programmer, but it’s just annoying that my homemade menu can’t have seo friendly urls somehow, because it seems so straightforward:
This link has not seo friendly urls
[QUOTE]{$index_script}?{$target_name}=products&product_id=2[/QUOTE]
This link has
[QUOTE]{$index_script}?{$target_name}=products&product_id={$product.product_id}[/QUOTE]
So somehow {$product.product_id} is replacing the whole link with a seo frindly url
as that is the only difference between those 2 lines
OH… ok, I misunderstood what you were saying…
it’s because the seo mod looks specifically for {$product.product_id}
Yes, and that’s why I want to define {$product.product_id} before each homemade link I have.
Do you know if that is possible somehow?
it is with a simple mod
in addons/seo/func.php
around line 143, you’ll see:
//Convert product links
right underneath that (between it and the if statement below it) put:
if (preg_match_all('/(\{\$index_script\}\?\{\$target_name\}=products(&|&)product_id=(\d+))([&|&]?)/i', $tpl_source, $matches1)) {
$mytemp = fn_get_product_data($matches1[3][0], $auth, $cart_language);
preg_match_all('/(\{\$index_script\}\?\{\$target_name\}=products(&|&)product_id=\d+)([&|&]?)/i', $tpl_source, $matches);
foreach ($matches[0] as $key => $match) {
$tpl_source = str_replace($match, fn_seo_link("p",$mytemp['product_id'],$mytemp['product']) . (empty($matches[3][$key]) ? '' : '?'), $tpl_source);
}
}
save
that will now search the templates for {$index_script}?{$target_name}=products&product_id=#
where # is the id# of the product and it will replace it with the appropriate seo link
Ahh, getting there almost
Only one thing, it doesn’t change my language folder name ‘en’, ‘es’
Do you happen to have a solution to that ?
it should because it’s passing $cart_language to the function
Strange then. The rest of my links are changing the language foldername, so it does seem to work like it should, but your link is staying at the default language I have set in admin.
The is the exact link I am using
```php
{$index_script}?{$target_name}=products&product_id=2
```
Does that look fine to you ?
try this:
in the same function where you put that if statement, a few lines above it, you’ll see:
global $cscart_http_dir, $current_location, $index_script, $settings;
change it to say:
global $cscart_http_dir, $current_location, $index_script, $settings, $auth, $cart_language;
No much luck I’m afraid.
This is what I did at line 136
```php
// global $cscart_http_dir, $current_location, $index_script, $settings;
global $cscart_http_dir, $current_location, $index_script, $settings, $auth, $cart_language;
```
However, it’s still stucked at ‘en’
ok, gotta run for now, but I’ll dig into it a little more to see what I can come up with…
Ok, thank you so much for now, I really appreciate it
in the code I gave you, change:
$mytemp = fn_get_product_data($matches1[3][0], $auth, $cart_language);
to
$mytemp = fn_get_product_data($matches1[3][0], $auth, strtolower($cart_language));
Sorry, but that didn’t help either
that’s weird, because when you dump the variables that are defined in that area, it says that cart_language is defined… unfortunately, I only have 1 language defined, so I’m not sure how to tell if it’s using the selected one or not…
It seems like I found the cause of the problem.
If I clear the templates cache with my 2nd languge selected, it will change the url in the link when I refresh the site.
Also, if I edit something in my main.tpl and upload it again, the language in the url is updated.
But it’s only the url that is cached somehow, because the anchor text itself is changing without clearing the cache when I change language.
Does that bring you a bit closer to what the problem could be ?
yes, because that url is “generated” by the php code, not by the tpl (because of the id# lookup)
if it’s always the same id#, then I can give you code to correct it… if you want the id# to change “regularly” then I don’t know what I can tell you to do about it… though I’ll see what I can come up with.